File size: 6,100 Bytes
1b5d209 | 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 | #!/usr/bin/env python
"""Update README/manifest/checksums after the licence join, then upload."""
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"
PARQUET = HERE / "code_search_net_java.parquet"
BUILD = HERE / "code_search_net_java.build.json"
README = HERE / "README.md"
MANIFEST = HERE / "manifest.json"
CHECKSUMS = HERE / "checksums.json"
def sha(b):
return hashlib.sha256(b).hexdigest()
def pct(n, total):
return f"{100*n/total:.1f}%"
def rights_block(build):
rows = build["license_class_rows"]
repos = build["license_class_repos"]
status = build["license_audit_status"]
nrows = build["rows"]
nrepos = build["license_audit_repos"]
order = ["permissive", "weak-copyleft", "strong-copyleft", "other", "unknown"]
row_line = " · ".join(f"{k} {rows.get(k,0):,} ({pct(rows.get(k,0), nrows)})" for k in order)
repo_line = " · ".join(f"{k} {repos.get(k,0):,}" for k in order)
status_line = " · ".join(f"{k} {v:,}" for k, v in status.items())
return f"""## Rights
- **Upstream**: CodeSearchNet, Apache-2.0 dataset; the card states that projects
without a license, or whose license does not permit redistribution, were
filtered out.
- **Per-repo audit (2026-12-05)**: {nrepos:,} repositories queried through the
GitHub licence API (`/repos/{{owner}}/{{repo}}/license`). Every row now
carries `license` (SPDX id, `NOASSERTION`, or `unknown`), `license_class`
(permissive / weak-copyleft / strong-copyleft / other / unknown) and
`license_source`. Full table: `repo_licenses.jsonl`.
- **Rows by class**: {row_line}.
- **Repos by class**: {repo_line}.
- **Audit status**: {status_line}.
- **Not release-ready**: the GitHub API detects only a LICENSE file;
`NOASSERTION`/`unknown` repos need manual review, and weak/strong copyleft
(EPL/LGPL/AGPL) carries notice/source obligations. A permissive-only slice is
`license_class == "permissive"`. Not legal advice. `release: None`.
"""
def not_checked_block():
return """## Not checked
- Manual review of repos the API reports as `NOASSERTION`/`unknown`.
- Whether GitHub's LICENSE-file detection matches the repo's actual terms.
- Notice/source obligations for EPL, LGPL and AGPL rows.
- Cross-corpus dedup against other code corpora.
- Whether the upstream "permissive" filter is exhaustive (the audit shows it is
not permissive-only: AGPL/EPL/LGPL are present).
"""
def main():
build = json.loads(BUILD.read_text(encoding="utf-8"))
text = README.read_text(encoding="utf-8")
start = text.index("## Rights")
end = text.index("## Files")
text = text[:start] + rights_block(build) + "\n" + text[end:]
text = text[:text.index("## Not checked")] + not_checked_block()
README.write_text(text, encoding="utf-8")
summary = {
"audited_repos": build["license_audit_repos"],
"audit_status": build["license_audit_status"],
"rows_by_class": build["license_class_rows"],
"repos_by_class": build["license_class_repos"],
"rows_by_license": build["license_distribution_rows"],
"repos_by_license": build["license_distribution_repos"],
"checked_at": "2026-12-05",
"source": "GitHub REST /repos/{owner}/{repo}/license",
}
(HERE / "license_summary.json").write_text(
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8")
cols = [f.name for f in pq.read_schema(PARQUET)]
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
manifest.update({
"generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"dataset_sha256": sha(PARQUET.read_bytes()),
"dataset_bytes": PARQUET.stat().st_size,
"rows": build["rows"],
"columns": cols,
"license_distribution_rows": build["license_distribution_rows"],
"license_class_rows": build["license_class_rows"],
"license_distribution_repos": build["license_distribution_repos"],
"license_class_repos": build["license_class_repos"],
"license_audit_status": build["license_audit_status"],
"license_audit_repos": build["license_audit_repos"],
})
MANIFEST.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
files = [
"code_search_net_java.parquet", "code_search_net_java.sample.jsonl",
"code_search_net_java.build.json", "README.md", "build_csn_java.py",
"make_sample.py", "sample_licenses.json", "audit_licenses.py",
"apply_licenses.py", "repos.txt", "repo_licenses.jsonl",
"license_summary.json",
]
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.upload_folder(folder_path=str(HERE), repo_id=RID, repo_type="dataset",
ignore_patterns=["raw/**", "*.fix.parquet", "*.licensed.parquet",
"__pycache__/**"],
commit_message="per-repo licence audit: license/license_class columns + summary")
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 by class:", build["license_class_rows"])
print("repos by class:", build["license_class_repos"])
print("audit status:", build["license_audit_status"])
if __name__ == "__main__":
main()
|