Skip to content

Commit

Permalink
Read default interpreter version from .python-version
Browse files Browse the repository at this point in the history
Closes pypa#1126
  • Loading branch information
edgarrmondragon committed Jul 10, 2024
1 parent 3adae6c commit d62b396
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/hatch/env/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,17 @@ def enter_shell(self, name: str, path: str, args: Iterable[str]):
with self.expose_uv(), self.get_env_vars():
shell_executor(path, args, self.virtual_env.executables_directory)

def _read_dot_python_version(self) -> str:
path = self.root / '.python-version'
try:
return path.read_text().splitlines()[0].strip()
except Exception: # noqa: BLE001
return ''

def check_compatibility(self):
super().check_compatibility()

python_version = self.config.get('python', '')
python_version = self.config.get('python', '') or self._read_dot_python_version()
if (
os.environ.get(AppEnvVars.PYTHON)
or self._find_existing_interpreter(python_version) is not None
Expand All @@ -252,6 +259,9 @@ def parent_python(self):
if explicit_default := os.environ.get(AppEnvVars.PYTHON):
return sys.executable if explicit_default == 'self' else explicit_default

if python_version := self._read_dot_python_version():
return self._get_concrete_interpreter_path(python_version)

return self._get_concrete_interpreter_path()

@cached_property
Expand Down

0 comments on commit d62b396

Please sign in to comment.