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

preserve relative-path at poetry run #7963

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def python(self) -> Path:
"""
Path to current python executable
"""
return self._bin(self._executable)
return Path(self._bin(self._executable))

@property
def marker_env(self) -> dict[str, Any]:
Expand Down Expand Up @@ -1311,7 +1311,7 @@ def pip(self) -> Path:
"""
# we do not use as_posix() here due to issues with windows pathlib2
# implementation
path = self._bin(self._pip_executable)
path = Path(self._bin(self._pip_executable))
if not path.exists():
return self.pip_embedded
return path
Expand Down Expand Up @@ -1431,7 +1431,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 self._bin(self._pip_executable).exists():
if embedded or not Path(self._bin(self._pip_executable)).exists():
return [str(self.python), str(self.pip_embedded)]
# run as module so that pip can update itself on Windows
return [str(self.python), "-m", "pip"]
Expand Down Expand Up @@ -1461,7 +1461,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 [str(self._bin(bin))]
return [self._bin(bin)]

def run(self, bin: str, *args: str, **kwargs: Any) -> str:
cmd = self.get_command_from_bin(bin) + list(args)
Expand Down Expand Up @@ -1541,7 +1541,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) -> Path:
def _bin(self, bin: str) -> str:
radoering marked this conversation as resolved.
Show resolved Hide resolved
"""
Return path to the given executable.
"""
Expand All @@ -1562,11 +1562,11 @@ def _bin(self, bin: str) -> Path:
bin_path = self._path / bin

if bin_path.exists():
return bin_path
return str(bin_path)

return Path(bin)
return bin

return bin_path
return str(bin_path)

def __eq__(self, other: object) -> bool:
if not isinstance(other, Env):
Expand Down Expand Up @@ -1880,8 +1880,8 @@ def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
return super().execute(bin, *args, **kwargs)
return 0

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


@contextmanager
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,3 +1827,10 @@ def test_detect_active_python_with_bat(poetry: Poetry, tmp_path: Path) -> None:
active_python = EnvManager(poetry)._detect_active_python()

assert active_python == wrapped_python


def test_command_from_bin_preserves_relative_path(manager: EnvManager) -> None:
# https://github.com/python-poetry/poetry/issues/7959
env = manager.get()
command = env.get_command_from_bin("./foo.py")
assert command == ["./foo.py"]