Skip to content

Commit 8169027

Browse files
committed
fix: RunCommand calling scripts with incorrect executable path
Fixes python-poetryGH-965 Calling `sys.argv` should run the same program as the currently running program. To make calling Poetry scripts through RunCommand match this behavior, we must set `sys.argv[0]` to be the full path of the executable. This change makes the behavior of calling a script through `poetry run` the same as calling a script directly from the .venv/bin.
1 parent e2ca061 commit 8169027

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

poetry/console/commands/run.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ def handle(self):
2020
return self.env.execute(*args)
2121

2222
def run_script(self, script, args):
23+
# Calling `sys.argv` should run the same program as the currently
24+
# running program. To make calling Poetry scripts through RunCommand
25+
# match this behavior, we must set `sys.argv[0]` to be the full path of
26+
# the executable.
27+
full_path_args = args.copy()
28+
full_path_args[0] = self.env._bin(full_path_args[0])
29+
2330
if isinstance(script, dict):
2431
script = script["callable"]
2532

@@ -34,7 +41,7 @@ def run_script(self, script, args):
3441
"from importlib import import_module; "
3542
"sys.argv = {!r}; {}"
3643
"import_module('{}').{}()\"".format(
37-
args, src_in_sys_path, module, callable_
44+
full_path_args, src_in_sys_path, module, callable_
3845
)
3946
]
4047

0 commit comments

Comments
 (0)