4444)
4545from policyengine_us_data .pipeline_metadata import pipeline_node # noqa: E402
4646from policyengine_us_data .pipeline_schema import PipelineNode # noqa: E402
47- from policyengine_us_data .utils .run_context import resolve_run_id # noqa: E402
47+ from policyengine_us_data .utils .run_context import ( # noqa: E402
48+ resolve_candidate_version ,
49+ resolve_run_id ,
50+ )
4851
4952app = modal .App (
5053 os .environ .get ("US_DATA_LOCAL_AREA_APP_NAME" ) or "policyengine-us-data-local-area"
@@ -361,6 +364,17 @@ def get_version() -> str:
361364 return pyproject ["project" ]["version" ]
362365
363366
367+ def get_staging_candidate_version (
368+ fallback_version : str ,
369+ explicit_candidate_version : str = "" ,
370+ ) -> str :
371+ """Resolve the HF staging candidate scope for local-area artifacts."""
372+ return (
373+ resolve_candidate_version (explicit_candidate_version , env = os .environ )
374+ or fallback_version
375+ )
376+
377+
364378@pipeline_node (
365379 PipelineNode (
366380 id = "build_publishing_input_bundle" ,
@@ -901,7 +915,11 @@ def validate_staging(branch: str, run_id: str, version: str = "") -> Dict:
901915 )
902916)
903917def upload_to_staging (
904- branch : str , version : str , manifest : Dict , run_id : str = ""
918+ branch : str ,
919+ version : str ,
920+ manifest : Dict ,
921+ run_id : str = "" ,
922+ candidate_version : str = "" ,
905923) -> str :
906924 """
907925 Upload files to HuggingFace staging only.
@@ -912,6 +930,10 @@ def upload_to_staging(
912930 setup_repo (branch )
913931
914932 manifest_json = json .dumps (manifest )
933+ staging_candidate_version = get_staging_candidate_version (
934+ version ,
935+ explicit_candidate_version = candidate_version ,
936+ )
915937
916938 result = subprocess .run (
917939 _python_cmd (
@@ -924,6 +946,7 @@ def upload_to_staging(
924946
925947manifest = json.loads('''{ manifest_json } ''')
926948version = "{ version } "
949+ staging_candidate_version = "{ staging_candidate_version } "
927950run_id = "{ run_id } "
928951staging_dir = Path("{ VOLUME_MOUNT } ")
929952run_dir = staging_dir / run_id
@@ -947,10 +970,14 @@ def upload_to_staging(
947970
948971# Upload to HuggingFace staging/
949972print(f"Uploading {{len(files_with_paths)}} files to HuggingFace staging/...")
950- hf_count = upload_to_staging_hf(files_with_paths, version, run_id=run_id)
973+ hf_count = upload_to_staging_hf(
974+ files_with_paths,
975+ candidate_version=staging_candidate_version,
976+ run_id=run_id,
977+ )
951978print(f"Uploaded {{hf_count}} files to HuggingFace staging/")
952979
953- print(f"Staged version {{version }} for promotion")
980+ print(f"Staged candidate {{staging_candidate_version }} for promotion")
954981""" ,
955982 ),
956983 text = True ,
@@ -961,7 +988,8 @@ def upload_to_staging(
961988 raise RuntimeError (f"Upload failed: { result .stderr } " )
962989
963990 return (
964- f"Staged version { version } with { len (manifest ['files' ])} files. "
991+ f"Staged candidate { staging_candidate_version } with "
992+ f"{ len (manifest ['files' ])} files. "
965993 f"Run promote workflow to publish to HuggingFace production and GCS."
966994 )
967995
@@ -1065,6 +1093,7 @@ def coordinate_publish(
10651093 n_clones : int = 430 ,
10661094 validate : bool = True ,
10671095 run_id : str = "" ,
1096+ candidate_version : str = "" ,
10681097 expected_fingerprint : str = "" ,
10691098 work_items_override : List [Dict ] | None = None ,
10701099) -> Dict :
@@ -1073,6 +1102,10 @@ def coordinate_publish(
10731102 setup_repo (branch )
10741103
10751104 version = get_version ()
1105+ staging_candidate_version = get_staging_candidate_version (
1106+ version ,
1107+ explicit_candidate_version = candidate_version ,
1108+ )
10761109
10771110 run_id = run_id or resolve_run_id ()
10781111 if not run_id :
@@ -1085,6 +1118,7 @@ def coordinate_publish(
10851118 print (f"Run ID: { run_id } " )
10861119 print ("=" * 60 )
10871120 print (f"Publishing version { version } from branch { branch } " )
1121+ print (f"Staging candidate { staging_candidate_version } " )
10881122 print (f"Using { num_workers } parallel workers" )
10891123
10901124 staging_dir = Path (VOLUME_MOUNT )
@@ -1320,7 +1354,11 @@ def coordinate_publish(
13201354
13211355 print ("\n Starting upload to staging..." )
13221356 result = upload_to_staging .remote (
1323- branch = branch , version = version , manifest = manifest , run_id = run_id
1357+ branch = branch ,
1358+ version = version ,
1359+ manifest = manifest ,
1360+ run_id = run_id ,
1361+ candidate_version = staging_candidate_version ,
13241362 )
13251363 print (result )
13261364
@@ -1382,12 +1420,17 @@ def coordinate_national_publish(
13821420 validate : bool = True ,
13831421 run_id : str = "" ,
13841422 skip_upload : bool = False ,
1423+ candidate_version : str = "" ,
13851424) -> Dict :
13861425 """Build and upload a national US.h5 from national weights."""
13871426 setup_gcp_credentials ()
13881427 setup_repo (branch )
13891428
13901429 version = get_version ()
1430+ staging_candidate_version = get_staging_candidate_version (
1431+ version ,
1432+ explicit_candidate_version = candidate_version ,
1433+ )
13911434
13921435 run_id = run_id or resolve_run_id ()
13931436 if not run_id :
@@ -1400,6 +1443,7 @@ def coordinate_national_publish(
14001443 print (f"Run ID: { run_id } " )
14011444 print ("=" * 60 )
14021445 print (f"Building national H5 for version { version } from branch { branch } " )
1446+ print (f"Staging candidate { staging_candidate_version } " )
14031447
14041448 staging_dir = Path (VOLUME_MOUNT )
14051449
@@ -1557,7 +1601,7 @@ def coordinate_national_publish(
15571601)
15581602upload_to_staging_hf(
15591603 [("{ national_h5 } ", "national/US.h5")],
1560- " { version } ",
1604+ candidate_version=" { staging_candidate_version } ",
15611605 run_id="{ run_id } ",
15621606)
15631607print("Done")
0 commit comments