File size: 5,466 Bytes
c032c6d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | #!/usr/bin/env python
"""Generate datasheet.md for the Python permissive dataset from build.json."""
import json
from pathlib import Path
HERE = Path(__file__).resolve().parent
BUILD = HERE / "code_search_net_python_permissive.build.json"
OUT = HERE / "datasheet.md"
def main():
b = json.loads(BUILD.read_text(encoding="utf-8"))
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])
lic_table = "\n".join(
f"| {k} | {v:,} | {100*v/rows:.1f}% |" for k, v in lic)
top = "\n".join(
f"{i}. `{r}` — {n:,} rows" for i, (r, n) in enumerate(b["top_repos"], 1))
splits = " · ".join(f"{k} {v:,}" for k, v in b["splits"].items())
text = f"""# code_search_net_python_permissive — CodeSearchNet Python (permissive only)
Added: 2026-12-05. Release: `None` (working copy, not a release).
## What the data is
Function-level Python source with its docstring, restricted to repositories whose
audited licence is permissive.
| | |
|---|---|
| Rows (functions) | **{rows:,}** |
| Repositories | **{b['repos']:,}** |
| Characters (`text`) | **{b['chars']:,}** |
| Tokens, tiktoken `cl100k_base` | **{b['tokens']:,}** |
| Parquet | **{b['bytes']:,} bytes** (zstd), 20 columns |
| Splits | {splits} |
| Language | Python (code) + English (docstrings) |
| Not OCR, not translated | yes |
`text` = docstring + `\\n\\n` + code. `id` is
`sha1(repo|path|func_name|sha256(code))[:24]` and is unique. `record_sha256` is
the canonical SHA-256 of the row and ships in the parquet.
## Where it comes from
- Upstream: [`code-search-net/code_search_net`](https://huggingface.co/datasets/code-search-net/code_search_net),
`python` configuration.
- No intermediary snapshot beyond the official HF dataset; no repository
contents were scraped (only the GitHub licence API was queried).
## Composition
Licences (rows), from a per-repo audit against the GitHub licence API
(`/repos/{{owner}}/{{repo}}/license`, 2026-12-05):
| SPDX | rows | % |
|---|---:|---:|
{lic_table}
Audit coverage: all {b['repos']:,} retained repositories carry a permissive
SPDX licence; rows from repositories with no
licence or a non-permissive licence were removed ({b['removed_unknown']:,}
unknown, {b['removed_not_permissive']:,} non-permissive).
Largest repositories by rows:
{top}
Row length (`token_count`): min {b['token_min']} · mean {b['token_avg']} ·
max {b['token_max']}. Docstrings are non-empty for {b['docstring_nonempty']:,} /
{rows:,} rows.
## 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
```
## Collection, normalization, filtering
Committed scripts: `build_csn_go.py` (shards → records), `audit_licenses.py`
(GitHub licence API), `join_go.py` (join + permissive filter),
`finalize_go.py`, `make_datasheet.py`.
- Code ≥ 20 chars; text ≥ 100 chars.
- Exact-code SHA-256 dedup (global).
- Keep only repositories with a detected permissive SPDX licence
(`license_class == "permissive"`).
- Audit cap: {cap['audited_repos']:,} repositories audited
({100*cap['audited_rows']/cap['total_rows']:.1f}% of rows);
{cap['not_audited_repos']:,} selected repositories
({cap['not_audited_rows']:,} rows) were not audited before the rate-limit
window closed and are dropped; the {cap['excluded_long_tail_repos']:,}-repo
long tail is excluded too.
- No text rewriting beyond stripping; no PII scrubbing (see Not checked).
## Rights
- Every retained row has an audited permissive SPDX licence in `license` and a
`license_source` URL; `license_class == "permissive"`.
- No copyleft (LGPL/EPL/GPL/AGPL) and no `NOASSERTION`/`unknown` rows.
- Permissive is not obligation-free: Apache-2.0 requires NOTICE/attribution and
preservation of notices; MIT/BSD require the copyright notice. The parquet
carries `repo` and `url` for attribution but **does not bundle licence texts
or NOTICE files**.
- Repo-level licence is not file-level: a repository may vendor or generate
files under other terms; GitHub reports the repository licence only.
## Why include it / uses
A licence-clean, function-level Python corpus with docstrings for code LLM
pretraining/SFT, code–documentation retrieval, and function-level generation or
summarisation. Python is under-represented relative to Java/Python code corpora.
## Limitations
- Function-level only: no package context, imports, or call graph.
- Licence state is a 2026-12-05 GitHub snapshot; repos can relicense later.
- Domain balance follows CodeSearchNet's collection (CLI/tooling-heavy,
web/scripting/data code prominent).
- Docstrings are upstream quality.
## Not checked
- PII in code or docstrings (author names, emails, keys): **no scrubber was run;
SlayerLab/NERGAL not applied**.
- Whether GitHub's LICENSE-file detection matches actual terms.
- Vendored/generated files inside repos that may carry other licences.
- Cross-corpus dedup against other code corpora.
- Preservation of Apache NOTICE / BSD-MIT copyright notices in downstream use.
## Reproduce
```bash
python build_csn_go.py
python audit_licenses.py
python join_go.py
python make_datasheet.py
python finalize_go.py
```
"""
OUT.write_text(text, encoding="utf-8")
print("wrote", OUT, len(text), "chars")
if __name__ == "__main__":
main()
|