Closed juftin closed 1 month ago
hatch==1.10.0
hatch-pip-compile==1.11.1
rm -rf ./.venv/ ./requirements.txt ./requirements/ && hatch run test:test
[tool.hatch.env]
requires = [
"hatch-pip-compile"
]
[tool.hatch.envs.default]
dependencies = [
"requests"
]
pip-compile-constraint = "default"
type = "pip-compile"
[tool.hatch.envs.test]
dependencies = [
"requests"
]
[tool.hatch.envs.test.scripts]
test = "echo 'Hello, world!'"
```text ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/__init__.py:221 in │ │ main │ │ │ │ 218 │ │ 219 def main(): # no cov │ │ 220 │ try: │ │ ❱ 221 │ │ hatch(prog_name='hatch', windows_expand_args=False) │ │ 222 │ except Exception: # noqa: BLE001 │ │ 223 │ │ import sys │ │ 224 │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:1157 in │ │ __call__ │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:1078 in main │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:1688 in invoke │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:1434 in invoke │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:783 in invoke │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/decorators.py:33 in │ │ new_func │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/run/__init__.py:141 │ │ in run │ │ │ │ 138 │ elif not env_name: │ │ 139 │ │ env_name = 'system' │ │ 140 │ │ │ ❱ 141 │ ctx.invoke( │ │ 142 │ │ run_command, │ │ 143 │ │ args=[command, *final_args], │ │ 144 │ │ env_names=[env_name], │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/core.py:783 in invoke │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/click/decorators.py:45 in │ │ new_func │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/env/run.py:128 in │ │ run │ │ │ │ 125 │ elif not matrix_selected and (included_variables or excluded_variables): │ │ 126 │ │ app.abort(f'Variable selection is unsupported for non-matrix environments: {", " │ │ 127 │ │ │ ❱ 128 │ for context in app.runner_context( │ │ 129 │ │ environments, │ │ 130 │ │ ignore_compat=ignore_compat or matrix_selected, │ │ 131 │ │ display_header=matrix_selected, │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/application.py:224 │ │ in runner_context │ │ │ │ 221 │ │ │ │ context = ExecutionContext(environment) │ │ 222 │ │ │ │ yield context │ │ 223 │ │ │ │ │ │ ❱ 224 │ │ │ │ self.prepare_environment(environment) │ │ 225 │ │ │ │ with EnvVars(context.env_vars): │ │ 226 │ │ │ │ │ self.run_shell_commands(context) │ │ 227 │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/application.py:143 │ │ in prepare_environment │ │ │ │ 140 │ │ │ │ │ │ ) │ │ 141 │ │ │ │ 142 │ │ with environment.app_status_dependency_state_check(): │ │ ❱ 143 │ │ │ new_dep_hash = environment.dependency_hash() │ │ 144 │ │ │ │ 145 │ │ current_dep_hash = self.env_metadata.dependency_hash(environment) │ │ 146 │ │ if new_dep_hash != current_dep_hash: │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:104 in dependency_hash │ │ │ │ 101 │ │ """ │ │ 102 │ │ Get the dependency hash │ │ 103 │ │ """ │ │ ❱ 104 │ │ self.run_pip_compile() │ │ 105 │ │ hatch_hash = super().dependency_hash() │ │ 106 │ │ if not self.dependencies: │ │ 107 │ │ │ return hatch_hash │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:117 in run_pip_compile │ │ │ │ 114 │ │ Run pip-compile if necessary │ │ 115 │ │ """ │ │ 116 │ │ self.prepare_environment() │ │ ❱ 117 │ │ if not self.lockfile_up_to_date: │ │ 118 │ │ │ with self.safe_activation(): │ │ 119 │ │ │ │ self.resolver.install_pypi_dependencies() │ │ 120 │ │ │ │ if self.piptools_lock_file.exists(): │ │ │ │ /Users/juftin/.pyenv/versions/3.11.8/lib/python3.11/functools.py:1001 in __get__ │ │ │ │ 998 │ │ │ │ # check if another thread filled cache while we awaited lock │ │ 999 │ │ │ │ val = cache.get(self.attrname, _NOT_FOUND) │ │ 1000 │ │ │ │ if val is _NOT_FOUND: │ │ ❱ 1001 │ │ │ │ │ val = self.func(instance) │ │ 1002 │ │ │ │ │ try: │ │ 1003 │ │ │ │ │ │ cache[self.attrname] = val │ │ 1004 │ │ │ │ │ except TypeError: │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:200 in lockfile_up_to_date │ │ │ │ 197 │ │ if not self.dependencies and not self.piptools_lock_file.exists(): │ │ 198 │ │ │ return True │ │ 199 │ │ if self.piptools_constraints_file: │ │ ❱ 200 │ │ │ valid_constraint = self.validate_constraints_file( │ │ 201 │ │ │ │ constraints_file=self.piptools_constraints_file, environment=self.constr │ │ 202 │ │ │ ) │ │ 203 │ │ │ if not valid_constraint: │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:318 in validate_constraints_file │ │ │ │ 315 │ │ │ Whether the constraints file is valid │ │ 316 │ │ """ │ │ 317 │ │ if not constraints_file.exists(): │ │ ❱ 318 │ │ │ self.constraint_env.run_pip_compile() │ │ 319 │ │ │ return False │ │ 320 │ │ else: │ │ 321 │ │ │ up_to_date = environment.piptools_lock.compare_requirements( │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:116 in run_pip_compile │ │ │ │ 113 │ │ """ │ │ 114 │ │ Run pip-compile if necessary │ │ 115 │ │ """ │ │ ❱ 116 │ │ self.prepare_environment() │ │ 117 │ │ if not self.lockfile_up_to_date: │ │ 118 │ │ │ with self.safe_activation(): │ │ 119 │ │ │ │ self.resolver.install_pypi_dependencies() │ │ │ │ /Users/juftin/git/hatch-pip-compile/hatch_pip_compile/plugin.py:367 in prepare_environment │ │ │ │ 364 │ │ but the `Application` class is not exposed to the environment plugin. │ │ 365 │ │ """ │ │ 366 │ │ if not self.virtualenv_exists(): │ │ ❱ 367 │ │ │ self.create() │ │ 368 │ │ │ if not self.dependencies_in_sync(): │ │ 369 │ │ │ │ self.sync_dependencies() │ │ 370 │ │ │ if not self.skip_install: │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/env/virtual.py:157 in │ │ create │ │ │ │ 154 """ │ │ 155 │ │ │ │ ) │ │ 156 │ │ │ │ ❱ 157 │ │ with self.expose_uv(): │ │ 158 │ │ │ self.virtual_env.create(self.parent_python, allow_system_packages=self.confi │ │ 159 │ │ │ 160 │ def remove(self): │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/env/virtual.py:99 in │ │ expose_uv │ │ │ │ 96 │ │ return UVVirtualEnv if self.use_uv else VirtualEnv │ │ 97 │ │ │ 98 │ def expose_uv(self): │ │ ❱ 99 │ │ if not (self.use_uv or self.uv_path): │ │ 100 │ │ │ return nullcontext() │ │ 101 │ │ │ │ 102 │ │ return EnvVars({'HATCH_UV': self.uv_path}) │ │ │ │ /Users/juftin/.pyenv/versions/3.11.8/lib/python3.11/functools.py:1001 in __get__ │ │ │ │ 998 │ │ │ │ # check if another thread filled cache while we awaited lock │ │ 999 │ │ │ │ val = cache.get(self.attrname, _NOT_FOUND) │ │ 1000 │ │ │ │ if val is _NOT_FOUND: │ │ ❱ 1001 │ │ │ │ │ val = self.func(instance) │ │ 1002 │ │ │ │ │ try: │ │ 1003 │ │ │ │ │ │ cache[self.attrname] = val │ │ 1004 │ │ │ │ │ except TypeError: │ │ │ │ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/env/virtual.py:116 in │ │ uv_path │ │ │ │ 113 │ │ │ # Prevent recursive loop │ │ 114 │ │ │ self.name == env_name │ │ 115 │ │ │ # Only if dependencies have been set by the user │ │ ❱ 116 │ │ │ or is_default_environment(env_name, self.app.project.config.internal_envs[en │ │ 117 │ │ ): │ │ 118 │ │ │ uv_env = self.app.get_environment(env_name) │ │ 119 │ │ │ self.app.prepare_environment(uv_env) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ AttributeError: 'SafeApplication' object has no attribute 'project' ```
There's a simple fix to this issue:
- return PipCompileEnvironment(
- root=self.root,
- metadata=self.metadata,
- name=environment_name,
- config=self.pipools_environment_dict.get(environment_name, {}),
- matrix_variables=self.matrix_variables,
- data_directory=self.data_directory,
- isolated_data_directory=self.isolated_data_directory,
- platform=Platform(),
- verbosity=self.verbosity,
- app=None,
- )
+ if isinstance(self.app, hatch.cli.Application):
+ env = self.app.get_environment(env_name=environment_name)
+ else:
+ env = PipCompileEnvironment(
+ root=self.root,
+ metadata=self.metadata,
+ name=environment_name,
+ config=self.pipools_environment_dict.get(environment_name, {}),
+ matrix_variables=self.matrix_variables,
+ data_directory=self.data_directory,
+ isolated_data_directory=self.isolated_data_directory,
+ platform=Platform(),
+ verbosity=self.verbosity,
+ app=None,
+ )
+ return env
However this results in a new Pathlib recursion error (big +1 for HATCH_DEBUG
btw):
```console
❯ rm -rf ./.venv/ ./requirements.txt ./requirements/ && HATCH_DEBUG=1 hatch run test:test
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/juftin/.local/pipx/venvs/hatch/lib/python3.11/site-packages/hatch/cli/__init__.py:221 in │
│ main │
│ │
│ 218 │
│ 219 def main(): # no cov │
│ 220 │ try: │
│ ❱ 221 │ │ hatch(prog_name='hatch', windows_expand_args=False) │
│ 222 │ except Exception: # noqa: BLE001 │
│ 223 │ │ import sys │
│ 224 │
│ │
│ ╭──────────────────────── locals ─────────────────────────╮ │
│ │ Console =
Attention: Patch coverage is 80.86957%
with 22 lines
in your changes missing coverage. Please review.
Project coverage is 91.99%. Comparing base (
251fcd7
) to head (74db67a
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:tada: This PR is included in version 1.11.2 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Resolves an issue where
SafeApplication
is injected into the hatch environment.This PR will resolve a regression issue in hatch
1.10.0
Closes https://github.com/pypa/hatch/issues/1468