hatch
hatch copied to clipboard
Nit: error message refers to "tool.hatch" even for hatch.toml
To reproduce:
$ cat hatch.toml
[envs.default]
dependencies = "sphinx"
[envs.default.scripts]
build = "python build.py"
$ hatch run build
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/cli/__init__.py:221 in │
│ main │
│ │
│ 218 │
│ 219 def main(): # no cov │
│ 220 │ try: │
│ ❱ 221 │ │ return hatch(prog_name='hatch', windows_expand_args=False) │
│ 222 │ except Exception: # noqa: BLE001 │
│ 223 │ │ from rich.console import Console │
│ 224 │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:1157 in __call__ │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:1078 in main │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:1688 in invoke │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:1434 in invoke │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:783 in invoke │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/decorators.py:45 in │
│ new_func │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/decorators.py:33 in │
│ new_func │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/cli/run/__init__.py:79 │
│ in run │
│ │
│ 76 │ elif not env_name: │
│ 77 │ │ env_name = 'system' │
│ 78 │ │
│ ❱ 79 │ ctx.invoke( │
│ 80 │ │ run_command, │
│ 81 │ │ args=[command, *args], │
│ 82 │ │ env_names=[env_name], │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/core.py:783 in invoke │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/click/decorators.py:45 in │
│ new_func │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/cli/env/run.py:180 in │
│ run │
│ │
│ 177 │ │ │ if env_name == 'system': │
│ 178 │ │ │ │ environment.exists = lambda: True │
│ 179 │ │ │ │
│ ❱ 180 │ │ │ app.prepare_environment(environment) │
│ 181 │ │ │ app.run_shell_commands( │
│ 182 │ │ │ │ environment, │
│ 183 │ │ │ │ [environment.join_command_args(args)], │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/cli/application.py:123 │
│ in prepare_environment │
│ │
│ 120 │ │ │ │ │ with self.status('Running post-installation commands'): │
│ 121 │ │ │ │ │ │ self.run_shell_commands(environment, environment.post_install_co │
│ 122 │ │ │
│ ❱ 123 │ │ dep_hash = environment.dependency_hash() │
│ 124 │ │ current_dep_hash = self.env_metadata.dependency_hash(environment) │
│ 125 │ │ if dep_hash != current_dep_hash: │
│ 126 │ │ │ with self.status('Checking dependencies'): │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/env/plugin/interface.py: │
│ 660 in dependency_hash │
│ │
│ 657 │ │ """ │
│ 658 │ │ from hatch.utils.dep import hash_dependencies │
│ 659 │ │ │
│ ❱ 660 │ │ return hash_dependencies(self.dependencies_complex) │
│ 661 │ │
│ 662 │ @contextmanager │
│ 663 │ def build_environment( │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/env/plugin/interface.py: │
│ 309 in dependencies_complex │
│ │
│ 306 │ @property │
│ 307 │ def dependencies_complex(self): │
│ 308 │ │ if self._dependencies_complex is None: │
│ ❱ 309 │ │ │ all_dependencies_complex = list(self.environment_dependencies_complex) │
│ 310 │ │ │ │
│ 311 │ │ │ # Ensure these are checked last to speed up initial environment creation sin │
│ 312 │ │ │ # they will already be installed along with the project │
│ │
│ /home/jean/.local/pipx/venvs/hatch/lib64/python3.12/site-packages/hatch/env/plugin/interface.py: │
│ 277 in environment_dependencies_complex │
│ │
│ 274 │ │ │ │ │ dependencies = self.config.get(option, []) │
│ 275 │ │ │ │ │ if not isinstance(dependencies, list): │
│ 276 │ │ │ │ │ │ message = f'Field `tool.hatch.envs.{self.name}.{option}` must be │
│ ❱ 277 │ │ │ │ │ │ raise TypeError(message) │
│ 278 │ │ │ │ │ │
│ 279 │ │ │ │ │ for i, entry in enumerate(dependencies, 1): │
│ 280 │ │ │ │ │ │ if not isinstance(entry, str): │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: Field `tool.hatch.envs.default.dependencies` must be an array
When the config is coming from hatch.toml, the error message should ideally say
“Field envs.default.dependencies must be an array”
instead of
“Field tool.hatch.envs.default.dependencies must be an array”
(It would also be nice not to have such a long traceback.)
That will be quite the endeavor to apply a source context to exceptions. Perhaps shorter tracebacks would be more achievable in the short-term however. I want to do both.