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 handling of metadata and Python resolution #1014

Merged
merged 1 commit into from
Oct 26, 2023
Merged
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
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