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: prefer python3 over python when discovering the interpreter #1821

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions src/hatch/env/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ def system_python(self):
if system_python == 'self':
system_python = sys.executable

# Prefer `python3` over `python` in a system context. See PEP-394 for details.
system_python = (
system_python
or self.platform.modules.shutil.which('python')
or self.platform.modules.shutil.which('python3')
or self.platform.modules.shutil.which('python')
or sys.executable
)
if not isabs(system_python):
Expand Down Expand Up @@ -768,7 +769,18 @@ def construct_pip_install_command(self, args: list[str]):
A convenience method for constructing a [`pip install`](https://pip.pypa.io/en/stable/cli/pip_install/)
command with the given verbosity. The default verbosity is set to one less than Hatch's verbosity.
"""
command = ['python', '-u', '-m', 'pip', 'install', '--disable-pip-version-check', '--no-python-version-warning']
# TODO: we should better use either `self.system_python` (in a system context) or `python` (in a virtual environment).
# Since we are called from `hatch.env.virtual` and `hatch.env.system`, we need to handle both contexts.
# According to PEP-394, `python3` should be a safe choice under all circumstances.
command = [
'python3',
'-u',
'-m',
'pip',
'install',
'--disable-pip-version-check',
'--no-python-version-warning',
]

# Default to -1 verbosity
add_verbosity_flag(command, self.verbosity, adjustment=-1)
Expand Down
2 changes: 1 addition & 1 deletion src/hatch/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class PythonInfo:
def __init__(self, platform: Platform, executable: str = 'python') -> None:
def __init__(self, platform: Platform, executable: str = 'python3') -> None:
self.platform = platform
self.executable = executable

Expand Down