Download research/release_candidate/check_loading.py from Helinity/python-security-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/datasets/Helinity/python-security-benchmark/resolve/main/research/release_candidate/check_loading.py
- Command line
-
hf download hf://datasets/Helinity/python-security-benchmark/research/release_candidate/check_loading.py
-
curl -L -o check_loading.py https://huggingface.co/datasets/Helinity/python-security-benchmark/resolve/main/research/release_candidate/check_loading.py
3.33 kB
| """Discover, load and inspect all six configurations entirely offline.""" | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| from tempfile import TemporaryDirectory | |
| from .audit import ROOT, RELEASE | |
| from research.build import json_bytes | |
| from research.check_hf import FILES | |
| def inspect_loading(root): | |
| os.environ['HF_HUB_OFFLINE'] = '1' | |
| os.environ['HF_DATASETS_OFFLINE'] = '1' | |
| os.environ['HF_HUB_DISABLE_TELEMETRY'] = '1' | |
| from datasets import get_dataset_config_names, get_dataset_split_names, load_dataset | |
| from huggingface_hub import DatasetCard | |
| card = DatasetCard.load(root / 'README.md') | |
| if card.data.license != 'apache-2.0': | |
| raise ValueError('License metadata differs') | |
| configured = {c['config_name']: {d['split']:d['path'] for d in c['data_files']} for c in card.data.configs} | |
| if configured != FILES: | |
| raise ValueError('Card config definitions differ from preserved configuration map') | |
| schemas = {} | |
| result = {} | |
| with TemporaryDirectory(prefix='codedna-rc-hf-') as cache: | |
| names = get_dataset_config_names(str(root), cache_dir=cache, token=False) | |
| if set(names) != set(FILES): | |
| raise ValueError('Configuration discovery mismatch') | |
| for config in sorted(names): | |
| split_names = get_dataset_split_names(str(root), config, cache_dir=cache, token=False) | |
| if set(split_names) != set(FILES[config]): | |
| raise ValueError('Split discovery mismatch') | |
| data = load_dataset(str(root), config, cache_dir=cache, token=False) | |
| result[config] = {} | |
| for split in split_names: | |
| expected = [json.loads(line) for line in (root / FILES[config][split]).read_text().splitlines()] | |
| actual = data[split] | |
| if actual.to_list() != expected: | |
| raise ValueError('Loaded data differs from source JSONL') | |
| # Exercise the local table/preview representation, including nested fields. | |
| preview = actual.select(range(min(3, len(actual)))).to_pandas() | |
| if len(preview) != min(3, len(actual)): | |
| raise ValueError('Local preview conversion failed') | |
| current = actual.features.to_dict() | |
| if config in schemas and schemas[config] != current: | |
| raise ValueError('Inconsistent split feature schema') | |
| schemas[config] = current | |
| result[config][split] = dict(rows=len(actual), fields=len(actual.column_names), local_table_preview='passed') | |
| return dict(configurations=result, hosted_preview='not_checked_requires_future_staging', | |
| access='offline_token_false', schemas=schemas) | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--root', type=Path, default=ROOT) | |
| parser.add_argument('--write', action='store_true') | |
| args = parser.parse_args() | |
| result = inspect_loading(args.root.resolve()) | |
| if args.write: | |
| (RELEASE / 'loading-check.json').write_bytes(json_bytes(result)) | |
| (RELEASE / 'schemas.json').write_bytes(json_bytes(result['schemas'])) | |
| print('Offline discovery, all 6 configs / 16 splits, exact record equality, schemas and local table preview: PASS') | |
| if __name__ == '__main__': | |
| main() | |