Download finalize_python.py from PiotrSty/code-search-net-python-permissive: direct link, hf CLI and curl.
- Browser
- Download file 6.09 kB
-
https://huggingface.co/datasets/PiotrSty/code-search-net-python-permissive/resolve/main/finalize_python.py
- Command line
-
hf download hf://datasets/PiotrSty/code-search-net-python-permissive/finalize_python.py
-
curl -L -o finalize_python.py https://huggingface.co/datasets/PiotrSty/code-search-net-python-permissive/resolve/main/finalize_python.py
6.09 kB
| #!/usr/bin/env python | |
| """README/manifest/checksums + upload for CodeSearchNet Python permissive-only.""" | |
| import hashlib | |
| import json | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| from huggingface_hub import HfApi | |
| HERE = Path(__file__).resolve().parent | |
| RID = "PiotrSty/code-search-net-python-permissive" | |
| PARQUET = HERE / "code_search_net_python.parquet" | |
| BUILD = HERE / "code_search_net_python_permissive.build.json" | |
| README = HERE / "README.md" | |
| FILES = [ | |
| "code_search_net_python.parquet", "code_search_net_python_permissive.sample.jsonl", | |
| "code_search_net_python_permissive.build.json", "README.md", "datasheet.md", | |
| "build_csn.py", "audit_python.py", "join_python.py", "finalize_python.py", | |
| "make_datasheet.py", "repos.txt", "repo_licenses.jsonl", | |
| "repo_cap.json", "license_summary.json", "sample_licenses.json", | |
| ] | |
| def sha(b): | |
| return hashlib.sha256(b).hexdigest() | |
| def readme(b): | |
| cap = json.loads((HERE / "repo_cap.json").read_text(encoding="utf-8")) | |
| rows = b["kept"] | |
| lic = sorted(b["licenses"].items(), key=lambda x: -x[1]) | |
| table = "\n".join(f"| `{k}` | {v:,} | {100*v/rows:.1f}% |" for k, v in lic) | |
| splits = " · ".join(f"{k} {v:,}" for k, v in b["splits"].items()) | |
| return f"""--- | |
| license: other | |
| language: | |
| - en | |
| tags: | |
| - code | |
| - python | |
| - code-search-net | |
| - permissive | |
| - function-documentation | |
| pretty_name: CodeSearchNet Python (permissive licences only) | |
| size_categories: | |
| - 100K<n<1M | |
| configs: | |
| - config_name: default | |
| data_files: | |
| - split: train | |
| path: code_search_net_python.parquet | |
| --- | |
| # CodeSearchNet Python — permissive licences only | |
| Working copy (2026-12-05). Derived from the official | |
| [`code-search-net/code_search_net`](https://huggingface.co/datasets/code-search-net/code_search_net) | |
| `python` configuration, keeping only repositories whose audited SPDX licence is | |
| permissive. | |
| - **{rows:,} rows**, **{b['repos']:,} repositories** | |
| - **{b['chars']:,} characters**, **{b['tokens']:,} tokens** | |
| (tiktoken `cl100k_base`) | |
| - parquet `{b['bytes']:,}` bytes (zstd), 20 columns | |
| - splits: {splits} | |
| - removed **{b['removed_not_permissive']:,}** non-permissive rows and | |
| **{b['removed_unknown']:,}** rows without a detected licence. | |
| - audit cap: {cap['audited_repos']:,} repos audited | |
| ({100*cap['audited_rows']/cap['total_rows']:.1f}% of rows); | |
| {cap['not_audited_repos']:,} selected repos | |
| ({cap['not_audited_rows']:,} rows) not audited and dropped. | |
| Full datasheet: [`datasheet.md`](./datasheet.md). | |
| ## Licences (rows) | |
| | SPDX | rows | % | | |
| |---|---:|---:| | |
| {table} | |
| ## Schema | |
| ``` | |
| id, repo, path, func_name, url, split, language, docstring, code, text, | |
| token_count, doc_chars, code_chars, license_basis, source, added, | |
| record_sha256, license, license_class, license_source | |
| ``` | |
| `text` = docstring + `\\n\\n` + code. `id` is unique. `record_sha256` is the | |
| canonical per-row SHA-256. | |
| ## Rights | |
| - Every retained row has an audited permissive SPDX licence in `license` | |
| (`license_class == "permissive"`, `license_source` = GitHub licence URL). | |
| - No copyleft and no `NOASSERTION`/`unknown`. | |
| - Permissive is not obligation-free: Apache-2.0 requires NOTICE/attribution; | |
| MIT/BSD require the copyright notice. This is not legal advice. | |
| ## Not checked | |
| - Whether GitHub's LICENSE-file detection matches the repo's actual terms. | |
| - Notice/attribution preservation for Apache-2.0/BSD rows. | |
| - Cross-corpus dedup against other code corpora. | |
| - PII in code/docstrings; no scrubber was run. | |
| """ | |
| def main(): | |
| b = json.loads(BUILD.read_text(encoding="utf-8")) | |
| README.write_text(readme(b), encoding="utf-8") | |
| cols = [f.name for f in pq.read_schema(PARQUET)] | |
| manifest = { | |
| "dataset": "code_search_net_python_permissive", | |
| "schema_version": "1.0", | |
| "generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"), | |
| "source": { | |
| "dataset": "code-search-net/code_search_net", "config": "python", | |
| "license": "other", "filter": "license_class == permissive", | |
| }, | |
| "dataset_file": PARQUET.name, | |
| "dataset_sha256": sha(PARQUET.read_bytes()), | |
| "dataset_bytes": PARQUET.stat().st_size, | |
| "rows": b["kept"], "columns": cols, "splits": b["splits"], | |
| "chars": b["chars"], "tokens": b["tokens"], "repos": b["repos"], | |
| "license_distribution_rows": b["licenses"], | |
| "license_class_rows": b["license_class_rows"], | |
| "removed_not_permissive": b["removed_not_permissive"], | |
| "removed_unknown": b["removed_unknown"], | |
| "tokenizer": b["tokenizer"], | |
| "per_row_hashes": "record_sha256 column", | |
| "checksums_file": "checksums.json", | |
| } | |
| (HERE / "manifest.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8") | |
| checks = {f: sha((HERE / f).read_bytes()) for f in FILES} | |
| (HERE / "checksums.json").write_text(json.dumps(checks, indent=2), encoding="utf-8") | |
| manifest["checksums_sha256"] = sha((HERE / "checksums.json").read_bytes()) | |
| (HERE / "manifest.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8") | |
| api = HfApi() | |
| api.create_repo(RID, repo_type="dataset", private=False, exist_ok=True) | |
| api.upload_folder(folder_path=str(HERE), repo_id=RID, repo_type="dataset", | |
| ignore_patterns=["raw/**", "*.final.parquet", "*_base.parquet", "__pycache__/**"], | |
| commit_message="CodeSearchNet Python permissive-only") | |
| info = api.repo_info(RID, repo_type="dataset") | |
| print("private:", info.private, "| sha:", info.sha) | |
| for it in api.list_repo_tree(RID, repo_type="dataset", recursive=True): | |
| if getattr(it, "path", "") == "code_search_net_python.parquet": | |
| lfs = getattr(it, "lfs", None) | |
| remote = getattr(lfs, "sha256", None) if lfs else None | |
| print("remote parquet sha:", remote) | |
| print("MATCH:", remote == checks["code_search_net_python.parquet"]) | |
| print("rows:", b["kept"], "repos:", b["repos"], "tokens:", b["tokens"]) | |
| if __name__ == "__main__": | |
| main() | |