Skip to content

Commit 829dcd9

Browse files
baogorekclaude
andcommitted
Clean up sys.path setup for modal_app.images imports
- Use existing sys/Path imports instead of aliased re-imports - Remove duplicate sys.path block in pipeline.py (now handled once at top) - Add sys.path fix to restage.py (also imports from modal_app) - Consistent pattern across all modal_app/ entrypoints: sys.path gets /root/policyengine-us-data (baked image) and local repo root before any from modal_app.* imports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4375df7 commit 829dcd9

5 files changed

Lines changed: 25 additions & 33 deletions

File tree

modal_app/data_build.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111

1212
import modal
1313

14-
import sys as _sys
15-
from pathlib import Path as _Path
16-
1714
_baked = "/root/policyengine-us-data"
18-
_local = str(_Path(__file__).resolve().parent.parent)
15+
_local = str(Path(__file__).resolve().parent.parent)
1916
for _p in (_baked, _local):
20-
if _p not in _sys.path:
21-
_sys.path.insert(0, _p)
17+
if _p not in sys.path:
18+
sys.path.insert(0, _p)
2219

2320
from modal_app.images import cpu_image as image
2421

modal_app/local_area.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313

1414
import os
1515
import subprocess
16+
import sys
1617
import json
1718
import modal
1819
from pathlib import Path
1920
from typing import List, Dict
2021

21-
import sys as _sys
22-
2322
_baked = "/root/policyengine-us-data"
2423
_local = str(Path(__file__).resolve().parent.parent)
2524
for _p in (_baked, _local):
26-
if _p not in _sys.path:
27-
_sys.path.insert(0, _p)
25+
if _p not in sys.path:
26+
sys.path.insert(0, _p)
2827

2928
from modal_app.images import cpu_image as image
3029

modal_app/pipeline.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import json
3636
import os
3737
import subprocess
38+
import sys
3839
import time
3940
import traceback
4041
from dataclasses import asdict, dataclass, field
@@ -44,13 +45,12 @@
4445
from typing import Optional
4546

4647
import modal
47-
import sys as _sys
4848

4949
_baked = "/root/policyengine-us-data"
5050
_local = str(Path(__file__).resolve().parent.parent)
5151
for _p in (_baked, _local):
52-
if _p not in _sys.path:
53-
_sys.path.insert(0, _p)
52+
if _p not in sys.path:
53+
sys.path.insert(0, _p)
5454

5555
from modal_app.images import cpu_image as image
5656

@@ -253,20 +253,7 @@ def _record_step(
253253
# app.include() merges functions from other apps into this one,
254254
# ensuring Modal mounts their files and registers their functions
255255
# (with their GPU/memory/volume configs) in the ephemeral run.
256-
#
257-
# Inside Modal containers the auto-mounted package root may not be
258-
# on sys.path when the module first loads; ensure it is importable.
259-
import sys
260-
261-
_parent = str(Path(__file__).resolve().parent.parent)
262-
if _parent not in sys.path:
263-
sys.path.insert(0, _parent)
264-
# The image bakes the repo at /root/policyengine-us-data, but Modal
265-
# auto-mounts the entrypoint elsewhere, so _parent may not contain
266-
# modal_app/. Ensure the baked repo root is always importable.
267-
_baked = "/root/policyengine-us-data"
268-
if _baked not in sys.path:
269-
sys.path.insert(0, _baked)
256+
# sys.path setup is handled at the top of this file.
270257

271258
from modal_app.data_build import app as _data_build_app
272259
from modal_app.data_build import build_datasets

modal_app/remote_calibration_runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import os
22
import subprocess
3-
import modal
3+
import sys
4+
from pathlib import Path
45

5-
import sys as _sys
6-
from pathlib import Path as _Path
6+
import modal
77

88
_baked = "/root/policyengine-us-data"
9-
_local = str(_Path(__file__).resolve().parent.parent)
9+
_local = str(Path(__file__).resolve().parent.parent)
1010
for _p in (_baked, _local):
11-
if _p not in _sys.path:
12-
_sys.path.insert(0, _p)
11+
if _p not in sys.path:
12+
sys.path.insert(0, _p)
1313

1414
from modal_app.images import gpu_image as image
1515

restage.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
"""Re-upload files from Modal staging volume to HF staging."""
22

3+
import sys
4+
from pathlib import Path
5+
6+
_baked = "/root/policyengine-us-data"
7+
_local = str(Path(__file__).resolve().parent)
8+
for _p in (_baked, _local):
9+
if _p not in sys.path:
10+
sys.path.insert(0, _p)
11+
312
from modal_app.local_area import app, validate_staging, upload_to_staging
413

514
branch = "fix-would-file-blend-and-entity-weights"

0 commit comments

Comments
 (0)