Skip to content

Commit

Permalink
Fix handling of metadata and Python resolution (#1014)
Browse files Browse the repository at this point in the history
Fix handling of metadata and Python resolution
  • Loading branch information
ofek authored Oct 26, 2023
1 parent 838b494 commit c77df9d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/hatch/env/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable

from packaging.specifiers import SpecifierSet
from virtualenv.discovery.py_info import PythonInfo

from hatch.python.core import PythonManager
Expand Down Expand Up @@ -210,7 +211,7 @@ def get_interpreter_resolver_env(self) -> dict[str, str]:
return env

internal_path = os.pathsep.join(python_dirs)
old_path = os.environ.pop('PATH', None)
old_path = env.pop('PATH', None)
env['PATH'] = internal_path if old_path is None else f'{old_path}{os.pathsep}{internal_path}'

return env
Expand All @@ -231,7 +232,7 @@ def _interpreter_is_compatible(self, interpreter: PythonInfo) -> bool:
return (
interpreter.executable
and self._is_stable_path(interpreter.executable)
and self.metadata.core.python_constraint.contains(interpreter.version_str)
and self._python_constraint.contains(interpreter.version_str)
)

def _get_concrete_interpreter_path(self, python_version: str = '') -> str | None:
Expand Down Expand Up @@ -349,6 +350,15 @@ def _python_resolvers(self) -> dict[str, Callable[[str], str | None]]:
'internal': self._resolve_internal_interpreter_path,
}

@cached_property
def _python_constraint(self) -> SpecifierSet:
from packaging.specifiers import SpecifierSet

# Note that we do not support this field being dynamic because if we were to set up the
# build environment to retrieve the field then we would be stuck because we need to use
# a satisfactory version to set up the environment
return SpecifierSet(self.metadata.core_raw_metadata.get('requires-python', ''))

@contextmanager
def safe_activation(self):
# Set user-defined environment variables first so ours take precedence
Expand Down

0 comments on commit c77df9d

Please sign in to comment.