diff --git a/docs/history/hatch.md b/docs/history/hatch.md index d6a1bc601..fa423fa89 100644 --- a/docs/history/hatch.md +++ b/docs/history/hatch.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ***Fixed:*** - When projects derive dependencies from metadata hooks, there is now by default a status indicator for when the hooks are executed for better responsiveness +- Properly support projects with a `pyproject.toml` file but no `project` table e.g. applications - Fix dependency inheritance for the template of the `types` environment for new projects ## [1.9.4](https://github.com/pypa/hatch/releases/tag/hatch-v1.9.4) - 2024-03-12 ## {: #hatch-v1.9.4 } diff --git a/src/hatch/project/core.py b/src/hatch/project/core.py index a4dc2357d..b16a7c8a2 100644 --- a/src/hatch/project/core.py +++ b/src/hatch/project/core.py @@ -121,7 +121,12 @@ def raw_config(self): else: from hatch.utils.toml import load_toml_file - self._raw_config = load_toml_file(str(self._project_file_path)) + raw_config = load_toml_file(str(self._project_file_path)) + # Assume environment management only + if 'project' not in raw_config: + raw_config['project'] = {'name': self.location.name} + + self._raw_config = raw_config return self._raw_config diff --git a/tests/project/test_core.py b/tests/project/test_core.py index c3825519a..5d445df78 100644 --- a/tests/project/test_core.py +++ b/tests/project/test_core.py @@ -107,3 +107,30 @@ def test_project(self, temp_dir, file_name): project = Project(temp_dir) assert project.location == temp_dir assert project.root == temp_dir + + +class TestRawConfig: + def test_missing(self, temp_dir): + project = Project(temp_dir) + project.find_project_root() + + assert project.raw_config == {'project': {'name': temp_dir.name}} + + def test_exists(self, temp_dir): + project_file = temp_dir / 'pyproject.toml' + project_file.touch() + project = Project(temp_dir) + project.find_project_root() + + config = {'project': {'name': 'foo'}, 'bar': 'baz'} + project.save_config(config) + + assert project.raw_config == config + + def test_exists_without_project_table(self, temp_dir): + project_file = temp_dir / 'pyproject.toml' + project_file.touch() + project = Project(temp_dir) + project.find_project_root() + + assert project.raw_config == {'project': {'name': temp_dir.name}}