Skip to content

Commit e1e79c7

Browse files
committed
Fix runner_cli to support relative file paths and same-directory imports
1 parent 60312c4 commit e1e79c7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

idaes/core/util/structfs/runner_cli.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ def main():
5353
return _error(sys.stderr, f"Cannot open output file '{args.output}': {err}", -1)
5454

5555
module_name = args.module
56+
# Only reject relative Python module names (like .module), not file paths (like ./file.py)
57+
if module_name.startswith(".") and not module_name.startswith("./") and not module_name.startswith("..\\"):
58+
return _error(ofile, "Relative module names not allowed", 1)
5659
try:
5760
mod = _load_module(module_name)
58-
except ValueError as err:
59-
return _error(ofile, str(err), 1)
60-
except ModuleNotFoundError:
61-
return _error(ofile, f"Could not find module '{module_name}'", 2)
61+
except (ModuleNotFoundError, FileNotFoundError) as e:
62+
return _error(ofile, f"Could not find module '{module_name}': {e}", 2)
6263

6364
obj_name = args.object
6465
try:
@@ -119,8 +120,11 @@ def _load_module(module_or_path: str):
119120
] # e.g., "test"
120121
full_module_name = f"{package_name}.{module_basename}" # e.g., "subdir.test"
121122

122-
# Add parent directory to sys.path so Python can find sibling packages
123-
# This enables imports like "from ..fsrunner import ..."
123+
# Add both current directory and parent directory to sys.path
124+
# Current dir is needed for same-directory imports (import hda_ideal_VLE)
125+
# Parent dir is needed for sibling package imports
126+
if dir_path not in sys.path:
127+
sys.path.insert(0, dir_path)
124128
if parent_dir not in sys.path:
125129
sys.path.insert(0, parent_dir)
126130

0 commit comments

Comments
 (0)