Download wu_20261104_structure_function/manuscript_release/code/prepare_release.py from cyd0806/neuronmimic-data: direct link, hf CLI and curl.
- Browser
- Download file 7.19 kB
-
https://huggingface.co/datasets/cyd0806/neuronmimic-data/resolve/main/wu_20261104_structure_function/manuscript_release/code/prepare_release.py
- Command line
-
hf download hf://datasets/cyd0806/neuronmimic-data/wu_20261104_structure_function/manuscript_release/code/prepare_release.py
-
curl -L -o prepare_release.py https://huggingface.co/datasets/cyd0806/neuronmimic-data/resolve/main/wu_20261104_structure_function/manuscript_release/code/prepare_release.py
7.19 kB
| """Enumerate all task rounds and dependency closure; no auth or network.""" | |
| from pathlib import Path | |
| import csv,json,hashlib,re,concurrent.futures,collections,os,tarfile,urllib.parse | |
| P=Path(__file__).resolve().parents[1];R=P.parents[1] | |
| SEEDS=[R/'projects/wu_20261102_followup_20261103']+sorted(x for x in (R/'projects').glob('wu_20261104_*') if x!=P)+[R/'artifacts/wu_20261030_all5177_structural_atlas'] | |
| EXTERNAL=R/'simulation/data/external/kc_nachbac_model_2025' | |
| BAD_PARTS={'.git','__pycache__','.venv','.venv_fine_structure','.cache','.pytest_cache'} | |
| SECRET=re.compile(rb'(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|hf_[A-Za-z0-9]{20,})') | |
| CODE_EXT={'.py','.sh','.mod','.hoc','.toml','.yaml','.yml','.cff','.R','.m'} | |
| ALL={};excluded=[] | |
| def admissible(p):return p.is_file() and not BAD_PARTS.intersection(p.parts) and p.suffix not in {'.pyc','.pyo'} | |
| def add(p,role): | |
| try:p=p.resolve();rel=p.relative_to(R) | |
| except (ValueError,OSError):return | |
| if not admissible(p):return | |
| if p==R/'20261102_吴老师组会纪要.pdf': | |
| excluded.append({'path':str(rel),'reason':'Internal meeting record, not a scientific public-data payload'});return | |
| ALL.setdefault(p,role) | |
| def resolve(s,base): | |
| if not isinstance(s,str) or len(s)>1000 or '\n' in s or '://' in s:return None | |
| x=Path(s) | |
| for p in ([x] if x.is_absolute() else [R/x,base/x]): | |
| if p.exists() and p.is_file():return p | |
| return None | |
| def walk(x,base): | |
| if isinstance(x,dict): | |
| for k,v in x.items(): | |
| if isinstance(v,str) and k in {'path','source','source_file','file','swc_path','local_path','local','input_path'}: | |
| p=resolve(v,base) | |
| if p:add(p,'manifest_dependency') | |
| elif isinstance(v,(list,dict)):walk(v,base) | |
| elif isinstance(x,list): | |
| for v in x:walk(v,base) | |
| for root in SEEDS: | |
| for p in root.rglob('*'):add(p,'task_project' if root.parent.name=='projects' else 'structural_atlas') | |
| for p in (R/'simulation/src').rglob('*'):add(p,'shared_simulation_code') | |
| # Dependencies as recorded by sealed input manifests; expand until no new manifests found. | |
| visited=set() | |
| for iteration in range(6): | |
| todo=[p for p in ALL if p not in visited and any(z in p.name.lower() for z in ['manifest','dependenc','provenance','registry']) and p.suffix in {'.csv','.json'}] | |
| if not todo:break | |
| for p in todo: | |
| visited.add(p) | |
| try: | |
| if p.suffix=='.json':walk(json.loads(p.read_text()),p.parent) | |
| else: | |
| with p.open(newline='') as f: | |
| for row in csv.DictReader(f):walk(row,p.parent) | |
| except (ValueError,UnicodeError,csv.Error):pass | |
| # All original physiology files are inventoried even where public redistribution terms remain unresolved. | |
| for p in EXTERNAL.rglob('*'):add(p,'third_party_source_retrieval_required') | |
| for p in [R/'pyproject.toml',R/'simulation/README.md',R/'simulation/src/bio_fly/__init__.py']:add(p,'shared_simulation_code') | |
| # Retrieve rather than relicense unlicensed author-source bundles. Derived outputs are retained. | |
| def terms(p): | |
| rel=str(p.relative_to(R)) | |
| if str(EXTERNAL.relative_to(R)) in rel or 'AusbornLab__KC_NaChBac_Model__' in p.name: | |
| return 'SOURCE_RETRIEVAL_ONLY','Author model repository has no explicit license in source audit' | |
| if ('published_KC_KC_model' in p.parts and any(t in p.parts for t in ['author_release','current_commit'])): | |
| return 'SOURCE_RETRIEVAL_ONLY','Pinned external model-source snapshot; preserve original repository terms' | |
| return 'INCLUDE','Own/derived scientific output or attributed source; original terms retained, no blanket license' | |
| def hash_one(item): | |
| p,role=item;h=hashlib.sha256();hits=0 | |
| scan=p.suffix.lower() in {'.py','.sh','.json','.csv','.txt','.md','.toml','.yaml','.yml','.ini','.cfg','.log','.m','.R','.hoc','.mod','.xml'} or p.suffix=='' | |
| tail=b'' | |
| with p.open('rb') as f: | |
| while b:=f.read(4*1024*1024): | |
| h.update(b) | |
| if scan: | |
| hits+=len(SECRET.findall(tail+b));tail=b[-150:] | |
| disposition,reason=terms(p) | |
| if hits:disposition='EXCLUDE_CREDENTIAL_PATTERN';reason='Credential-shaped strings detected; values suppressed and no upload allowed' | |
| return dict(path=str(p.relative_to(R)),bytes=p.stat().st_size,sha256=h.hexdigest(),role=role,public_disposition=disposition,reason=reason,credential_matches=hits) | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:rows=list(pool.map(hash_one,sorted(ALL.items()))) | |
| fields=list(rows[0]);out=P/'metadata/release_inventory.csv' | |
| with out.open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=fields);w.writeheader();w.writerows(rows) | |
| retrieval=[] | |
| source_tree=R/'projects/wu_20261102_followup_20261103/sources/AusbornLab__KC_NaChBac_Model_tree.json' | |
| tracked={x['path'] for x in json.loads(source_tree.read_text())['tree'] if x['type']=='blob'} | |
| source_commit='b799ccd7bd37dc080d717d8ca2b75699bf94eae2' | |
| for row in rows: | |
| if row['public_disposition']=='SOURCE_RETRIEVAL_ONLY': | |
| path=row['path'];url='';q='';revision='';action='RESTORE_FROM_RECORDED_SOURCE_ARCHIVE_VERIFY_SHA256' | |
| if 'simulation/data/external/kc_nachbac_model_2025/' in path: | |
| q=path.split('simulation/data/external/kc_nachbac_model_2025/',1)[1] | |
| elif 'AusbornLab__KC_NaChBac_Model__' in path: | |
| q=path.split('AusbornLab__KC_NaChBac_Model__',1)[1].replace('__','/') | |
| is_author='kc_nachbac' in path.lower() or 'AusbornLab' in path | |
| if is_author: | |
| revision=source_commit | |
| if q in tracked: | |
| url='https://raw.githubusercontent.com/AusbornLab/KC_NaChBac_Model/'+source_commit+'/'+urllib.parse.quote(q,safe='/');action='FETCH_PINNED_SOURCE_VERIFY_SHA256' | |
| else:action='REBUILD_FROM_PINNED_SOURCE_MACHINE_SPECIFIC_HASH_NOT_PORTABLE' | |
| elif '/author_release/' in path: | |
| revision='v1.0.0 / 3710a03';url='https://zenodo.org/api/records/17698635/files/nawrotlab/KC_KC_lateral_interactions-v1.0.0.zip/content' | |
| retrieval.append({**row,'original_url':url,'source_repo':'https://github.com/AusbornLab/KC_NaChBac_Model' if is_author else 'https://github.com/nawrotlab/KC_KC_lateral_interactions','source_revision':revision,'original_relative_path':q,'retrieval_action':action}) | |
| with (P/'metadata/source_retrieval_ledger.csv').open('w',newline='') as f: | |
| w=csv.DictWriter(f,fieldnames=fields+['original_url','source_repo','source_revision','original_relative_path','retrieval_action']);w.writeheader();w.writerows(retrieval) | |
| summary={'status':'INVENTORIED_NOT_UPLOADED','task_rounds':len([s for s in SEEDS if s.parent.name=='projects']),'seed_roots':[str(x.relative_to(R)) for x in SEEDS],'files':len(rows),'bytes':sum(x['bytes'] for x in rows),'included_files':sum(x['public_disposition']=='INCLUDE' for x in rows),'included_bytes':sum(x['bytes'] for x in rows if x['public_disposition']=='INCLUDE'),'source_retrieval_files':len(retrieval),'credential_pattern_files':[x['path'] for x in rows if x['credential_matches']],'excluded_internal_files':list({x['path']:x for x in excluded}.values()),'dependency_manifest_files_parsed':len(visited),'bulk_destination':'cyd0806/neuronmimic-data/wu_20261104_structure_function','note':'Scientific project payload; no virtual environments, private meeting minutes, git internals or unrelated dirty artifacts.'} | |
| (P/'metadata/release_inventory_summary.json').write_text(json.dumps(summary,indent=2,ensure_ascii=False));print(json.dumps(summary,ensure_ascii=False,indent=2)) | |