@@ -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