Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script dir to python path for multi file scripts #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/paramit/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,13 @@ def run_code(source_code: str, python_path: str, cwd: str, script_path: str) ->
# Write the __file__ variable at the top of the file to the original script path
temp_file.write(f"__file__ = {repr(os.path.abspath(script_path))}\n")

script_dir = os.path.dirname(os.path.abspath(script_path))

# Adjust the Python path to include the directory of the script
temp_file.write(f"import sys\nsys.path.insert(0, {repr(script_dir)})\n")

# Write the code to set the original directory as the working directory
temp_file.write(f"import os\nos.chdir({repr(os.path.dirname(os.path.abspath(script_path)))})\n")
temp_file.write(f"import os\nos.chdir({repr(script_dir)})\n")

temp_file.write(source_code)
temp_file_path = temp_file.name
Expand Down