Skip to content

Commit

Permalink
run: Edit sys.path before running args.script
Browse files Browse the repository at this point in the history
this enables finding local modules

Signed-off-by: tal66 <77445020+tal66@users.noreply.github.com>
  • Loading branch information
tal66 committed May 8, 2022
1 parent 79427ae commit 949ba85
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/memray/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ def _get_free_port() -> int:
return int(sock.getsockname()[1])


def edit_sys(args: argparse.Namespace) -> None:
"""Edit sys variables before running the user's script"""
sys.argv = [args.script, *args.script_args]
if args.run_as_module:
sys.argv.insert(0, "-m")

script_cwd = pathlib.Path("")
if not args.run_as_cmd:
script_cwd = pathlib.Path(args.script).resolve().parent.absolute()
if pathlib.Path.exists(script_cwd):
sys.path.insert(0, str(script_cwd))


def _run_tracker(
destination: Destination,
args: argparse.Namespace,
post_run_message: Optional[str] = None,
follow_fork: bool = False,
) -> None:
sys.argv = [args.script, *args.script_args]
if args.run_as_module:
sys.argv.insert(0, "-m")
edit_sys(args)
try:
kwargs = {}
if follow_fork:
Expand Down

0 comments on commit 949ba85

Please sign in to comment.