File size: 6,138 Bytes
9124411 b1dbcfb 9124411 b1dbcfb 9124411 | 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/usr/bin/env python
"""README/manifest/checksums + upload for the permissive-only dataset."""
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-java-permissive"
PARQUET = HERE / "code_search_net_java.parquet"
BUILD = HERE / "code_search_net_java_permissive.build.json"
README = HERE / "README.md"
MANIFEST = HERE / "manifest.json"
CHECKSUMS = HERE / "checksums.json"
FILES = [
"code_search_net_java.parquet", "code_search_net_java_permissive.sample.jsonl",
"code_search_net_java_permissive.build.json", "README.md", "datasheet.md",
"build_csn_java.py", "audit_licenses.py", "apply_licenses.py",
"filter_open.py", "filter_permissive.py", "finalize_permissive.py",
"repos.txt", "repo_licenses.jsonl", "license_summary.json",
"sample_licenses.json",
]
def sha(b):
return hashlib.sha256(b).hexdigest()
def readme(b):
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
- java
- code-search-net
- permissive
- function-documentation
pretty_name: CodeSearchNet Java (permissive licences only)
size_categories:
- 100K<n<1M
configs:
- config_name: default
data_files:
- split: train
path: code_search_net_java.parquet
---
# CodeSearchNet Java — permissive licences only
Working copy (2026-12-05). Subset of
[`PiotrSty/code-search-net-java`](https://huggingface.co/datasets/PiotrSty/code-search-net-java)
keeping only repositories whose audited SPDX licence is permissive
(MIT, Apache-2.0, BSD-2/3-Clause, ISC, Zlib, WTFPL, Artistic-2.0).
- **{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']:,}** weak/strong-copyleft rows and
**47,818** rows without a detected licence.
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.
## Provenance and audit
- Upstream: official CodeSearchNet Java shards.
- Filters: code ≥ 20 chars, text ≥ 100 chars, exact-code dedup, open-licence
filter, then `license_class == "permissive"`.
- Per-repo audit: GitHub REST `/repos/{{owner}}/{{repo}}/license` over 4,769
repositories (2026-12-05); full table in `repo_licenses.jsonl`.
## Rights
- Every retained row has an audited permissive SPDX licence in `license`
(`license_class == "permissive"`, `license_source` = GitHub licence URL).
- No copyleft rows (LGPL/EPL/GPL/AGPL) and no `NOASSERTION`/`unknown`.
- Permissive is not obligation-free: Apache-2.0 requires NOTICE/attribution and
BSD/MIT 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.
"""
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_java_permissive",
"schema_version": "1.0",
"generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"source": {
"dataset": "code-search-net/code_search_net", "config": "java",
"derived_from": "PiotrSty/code-search-net-java",
"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"],
"tokenizer": b["tokenizer"],
"per_row_hashes": "record_sha256 column",
"checksums_file": "checksums.json",
}
MANIFEST.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
checks = {f: sha((HERE / f).read_bytes()) for f in FILES}
CHECKSUMS.write_text(json.dumps(checks, indent=2), encoding="utf-8")
manifest["checksums_sha256"] = sha(CHECKSUMS.read_bytes())
MANIFEST.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=["__pycache__/**"],
commit_message="CodeSearchNet Java permissive-only: 334,367 rows")
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_java.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_java.parquet"])
print("rows:", b["kept"], "repos:", b["repos"], "tokens:", b["tokens"])
if __name__ == "__main__":
main()
|