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

Python test matrix versions not automatically installed #1881

Open
julia-sprenger opened this issue Jan 9, 2025 · 0 comments
Open

Python test matrix versions not automatically installed #1881

julia-sprenger opened this issue Jan 9, 2025 · 0 comments

Comments

@julia-sprenger
Copy link

I am trying to use hatch for running project tests using Gitlab actions and are running into an issue with test environments not being generated. In detail, when running a test matrix including Python versions not available in the system, the tests fail to install the correct versions and instead raise an OSError. Here's a minimal Dockerfile example demonstrating the issue

FROM python:3-alpine

RUN apk add build-base linux-headers python3-dev
RUN pip install hatch

RUN hatch new myproject ./myproject
WORKDIR myproject
RUN hatch test --all

Trying to build this via docker build - < Dockerfile results in

...
 => ERROR [6/6] RUN hatch test --all                                                                                             5.5s
------
 > [6/6] RUN hatch test --all:
0.940 ────────────────────────────── hatch-test.py3.13 ───────────────────────────────
0.940 Creating environment: hatch-test.py3.13
0.952 Installing Python distribution: 3.13
4.924   × No interpreter found for path
4.924   │ `/root/.local/share/hatch/env/virtual/.pythons/3.13/python/bin/python3` in
4.924   │ managed installations or search path
4.926 Installing project in development mode
5.250 ╭───────────────────── Traceback (most recent call last) ──────────────────────╮
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/cli/__init__.py:221 in main    │
5.250 │                                                                              │
5.250 │   218                                                                        │
5.250 │   219 def main():  # no cov                                                  │
5.250 │   220 │   try:                                                               │
5.250 │ ❱ 221 │   │   hatch(prog_name='hatch', windows_expand_args=False)            │
5.250 │   222 │   except Exception:  # noqa: BLE001                                  │
5.250 │   223 │   │   import sys                                                     │
5.250 │   224                                                                        │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/core.py:1161 in __call__       │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/core.py:1082 in main           │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/core.py:1697 in invoke         │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/core.py:1443 in invoke         │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/core.py:788 in invoke          │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/click/decorators.py:33 in new_func   │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/cli/test/__init__.py:163 in    │
5.250 │ test                                                                         │
5.250 │                                                                              │
5.250 │   160 │   if cover:                                                          │
5.250 │   161 │   │   patched_coverage.write_config_file()                           │
5.250 │   162 │                                                                      │
5.250 │ ❱ 163 │   for context in app.runner_context(selected_envs, ignore_compat=mul │
5.250 │   164 │   │   internal_arguments: list[str] = list(context.env.config.get('e │
5.250 │   165 │   │                                                                  │
5.250 │   166 │   │   if not context.env.config.get('randomize', randomize):         │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/cli/application.py:224 in      │
5.250 │ runner_context                                                               │
5.250 │                                                                              │
5.250 │   221 │   │   │   │   context = ExecutionContext(environment)                │
5.250 │   222 │   │   │   │   yield context                                          │
5.250 │   223 │   │   │   │                                                          │
5.250 │ ❱ 224 │   │   │   │   self.prepare_environment(environment)                  │
5.250 │   225 │   │   │   │   with EnvVars(context.env_vars):                        │
5.250 │   226 │   │   │   │   │   self.run_shell_commands(context)                   │
5.250 │   227                                                                        │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/cli/application.py:127 in      │
5.250 │ prepare_environment                                                          │
5.250 │                                                                              │
5.250 │   124 │   │   │   │                                                          │
5.250 │   125 │   │   │   │   with environment.app_status_project_installation():    │
5.250 │   126 │   │   │   │   │   if environment.dev_mode:                           │
5.250 │ ❱ 127 │   │   │   │   │   │   environment.install_project_dev_mode()         │
5.250 │   128 │   │   │   │   │   else:                                              │
5.250 │   129 │   │   │   │   │   │   environment.install_project()                  │
5.250 │   130                                                                        │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/env/virtual.py:178 in          │
5.250 │ install_project_dev_mode                                                     │
5.250 │                                                                              │
5.250 │   175 │   │   │   self.platform.check_command(self.construct_pip_install_com │
5.250 │   176 │                                                                      │
5.250 │   177 │   def install_project_dev_mode(self):                                │
5.250 │ ❱ 178 │   │   with self.safe_activation():                                   │
5.250 │   179 │   │   │   self.platform.check_command(                               │
5.250 │   180 │   │   │   │   self.construct_pip_install_command(['--editable', self │
5.250 │   181 │   │   │   )                                                          │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/contextlib.py:137 in __enter__                     │
5.250 │                                                                              │
5.250 │   134 │   │   # they are only needed for recreation, which is not possible a │
5.250 │   135 │   │   del self.args, self.kwds, self.func                            │
5.250 │   136 │   │   try:                                                           │
5.250 │ ❱ 137 │   │   │   return next(self.gen)                                      │
5.250 │   138 │   │   except StopIteration:                                          │
5.250 │   139 │   │   │   raise RuntimeError("generator didn't yield") from None     │
5.250 │   140                                                                        │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/env/virtual.py:457 in          │
5.250 │ safe_activation                                                              │
5.250 │                                                                              │
5.250 │   454 │   │   # - This environment                                           │
5.250 │   455 │   │   # - UV                                                         │
5.250 │   456 │   │   # - User-defined environment variables                         │
5.250 │ ❱ 457 │   │   with self.get_env_vars(), self.expose_uv(), self:              │
5.250 │   458 │   │   │   yield                                                      │
5.250 │   459                                                                        │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/env/plugin/interface.py:977 in │
5.250 │ __enter__                                                                    │
5.250 │                                                                              │
5.250 │    974 │   │   │   yield                                                     │
5.250 │    975 │                                                                     │
5.250 │    976 │   def __enter__(self):                                              │
5.250 │ ❱  977 │   │   self.activate()                                               │
5.250 │    978 │   │   return self                                                   │
5.250 │    979 │                                                                     │
5.250 │    980 │   def __exit__(self, exc_type, exc_value, traceback):               │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/env/virtual.py:135 in activate │
5.250 │                                                                              │
5.250 │   132 │   │   return {'system-packages': bool, 'path': str, 'python-sources' │
5.250 │   133 │                                                                      │
5.250 │   134 │   def activate(self):                                                │
5.250 │ ❱ 135 │   │   self.virtual_env.activate()                                    │
5.250 │   136 │                                                                      │
5.250 │   137 │   def deactivate(self):                                              │
5.250 │   138 │   │   self.virtual_env.deactivate()                                  │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/venv/core.py:31 in activate    │
5.250 │                                                                              │
5.250 │    28 │   │   if old_path is None:                                           │
5.250 │    29 │   │   │   os.environ['PATH'] = f'{self.executables_directory}{os.pat │
5.250 │    30 │   │   else:                                                          │
5.250 │ ❱  31 │   │   │   os.environ['PATH'] = f'{self.executables_directory}{os.pat │
5.250 │    32 │   │                                                                  │
5.250 │    33 │   │   for env_var in self.IGNORED_ENV_VARS:                          │
5.250 │    34 │   │   │   self._env_vars_to_restore[env_var] = os.environ.pop(env_va │
5.250 │                                                                              │
5.250 │ /usr/local/lib/python3.12/site-packages/hatch/venv/core.py:91 in             │
5.250 │ executables_directory                                                        │
5.250 │                                                                              │
5.250 │    88 │   │   │   │   │   raise OSError(msg)                                 │
5.250 │    89 │   │   │   else:                                                      │
5.250 │    90 │   │   │   │   msg = f'Unable to locate executables directory within: │
5.250 │ ❱  91 │   │   │   │   raise OSError(msg)                                     │
5.250 │    92 │   │                                                                  │
5.250 │    93 │   │   return self._executables_directory                             │
5.250 │    94                                                                        │
5.250 ╰──────────────────────────────────────────────────────────────────────────────╯
5.250 OSError: Unable to locate executables directory within:
5.250 /root/.local/share/hatch/env/virtual/myproject/tjKdtegc/hatch-test.py3.13

I would expect hatch to setup the virtual environments with the corresponding Python version instead of raising an OSError. Am I missunderstanding the idea behind the virtual test environments? I would be happy for a hint on how to execute the complete test matrix without explicitly installing all Python versions in the docker container / system environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant