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

Fix incorrect sys.argv[0] path when calling project scripts #6737

Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7273f41
fix: RunCommand calling scripts with incorrect executable path
chdsbd Mar 31, 2019
9173580
Python 2 compatibility
chdsbd Mar 31, 2019
6209264
Add basic test
chdsbd Mar 31, 2019
399ed6d
doc
chdsbd Mar 31, 2019
1a915a9
Rewrite test to run project script
wagnerluis1982 Oct 7, 2022
121e42f
simplify code
wagnerluis1982 Oct 7, 2022
85174c7
fix type on RunCommand.run_script
wagnerluis1982 Oct 7, 2022
ee4a2a7
fix test for windows platform
wagnerluis1982 Oct 7, 2022
fd4cee7
replace comments for a nice docstring
wagnerluis1982 Oct 8, 2022
c925e39
rename Env.{_bin => get_bin_path}
wagnerluis1982 Oct 8, 2022
7ae7d32
Merge remote-tracking branch 'origin/master' into fix-incorrect-execu…
wagnerluis1982 Jan 11, 2023
4c919b8
rename test method
wagnerluis1982 Jan 11, 2023
81232c0
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 12, 2023
c761cfe
improve test readability
wagnerluis1982 Jan 15, 2023
e0e01eb
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 15, 2023
c1d579f
rewrite test assertion
wagnerluis1982 Jan 15, 2023
74b725e
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 16, 2023
0846cd6
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 18, 2023
02c9919
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 20, 2023
e4de1a4
use script_dirs instead of bin_path, make test more realistic
radoering Jan 21, 2023
2bdc670
add script extension ".cmd" when on windows
wagnerluis1982 Jan 21, 2023
713a1de
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 21, 2023
a758197
do not change args list
wagnerluis1982 Jan 22, 2023
bf6c3ca
Merge branch 'master' into fix-incorrect-executable-path
wagnerluis1982 Jan 22, 2023
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
Prev Previous commit
Next Next commit
rename Env.{_bin => get_bin_path}
  • Loading branch information
wagnerluis1982 committed Nov 13, 2022
commit c925e39ff40cf6467903d9fa75022e99194ab2cf
2 changes: 1 addition & 1 deletion src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ def run_script(self, script: str | dict[str, str], args: list[str]) -> int:
Otherwise (when an entry point script does not exist), ``sys.argv[0]`` is the
script name only, i.e. ``poetry run foo`` has ``sys.argv == ['foo']``.
"""
args = [self.env._bin(args[0]), *args[1:]]
args = [self.env.get_bin_path(args[0]), *args[1:]]

if isinstance(script, dict):
script = script["callable"]
12 changes: 6 additions & 6 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
@@ -1249,7 +1249,7 @@ def python(self) -> str:
"""
Path to current python executable
"""
return self._bin(self._executable)
return self.get_bin_path(self._executable)

@property
def marker_env(self) -> dict[str, Any]:
@@ -1317,7 +1317,7 @@ def pip(self) -> str:
"""
# we do not use as_posix() here due to issues with windows pathlib2
# implementation
path = self._bin(self._pip_executable)
path = self.get_bin_path(self._pip_executable)
if not Path(path).exists():
return str(self.pip_embedded)
return path
@@ -1427,7 +1427,7 @@ def get_marker_env(self) -> dict[str, Any]:
raise NotImplementedError()

def get_pip_command(self, embedded: bool = False) -> list[str]:
if embedded or not Path(self._bin(self._pip_executable)).exists():
if embedded or not Path(self.get_bin_path(self._pip_executable)).exists():
return [self.python, self.pip_embedded]
# run as module so that pip can update itself on Windows
return [self.python, "-m", "pip"]
@@ -1457,7 +1457,7 @@ def get_command_from_bin(self, bin: str) -> list[str]:
# embedded pip when pip is not available in the environment
return self.get_pip_command()

return [self._bin(bin)]
return [self.get_bin_path(bin)]

def run(self, bin: str, *args: str, **kwargs: Any) -> str | int:
cmd = self.get_command_from_bin(bin) + list(args)
@@ -1539,7 +1539,7 @@ def script_dirs(self) -> list[Path]:
self._script_dirs.append(self.userbase / self._script_dirs[0].name)
return self._script_dirs

def _bin(self, bin: str) -> str:
def get_bin_path(self, bin: str) -> str:
"""
Return path to the given executable.
"""
@@ -1898,7 +1898,7 @@ def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
return super().execute(bin, *args, **kwargs)
return 0

def _bin(self, bin: str) -> str:
def get_bin_path(self, bin: str) -> str:
return bin