Skip to content

Commit

Permalink
Require explicit file selection for the wheel target (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Dec 5, 2023
1 parent a9536fc commit 350ca03
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 4 additions & 2 deletions backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def set_default_file_selection(self) -> None:
self.__packages.append(namespace)
break
else:
self.__include.append('*.py')
self.__exclude.append('test*')
message = (
'At least one file selection option must be defined, see: https://hatch.pypa.io/latest/config/build/'
)
raise ValueError(message)

def default_include(self) -> list[str]:
if not self.__include_defined:
Expand Down
1 change: 1 addition & 0 deletions docs/history/hatchling.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
***Changed:***

- An error will now be raised if a force-included path does not exist
- An error will now be raised for the `wheel` target if no file selection options are defined

***Added:***

Expand Down
5 changes: 3 additions & 2 deletions docs/plugins/builder/wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The builder plugin name is `wheel`.
| Version | Description |
| --- | --- |
| `standard` (default) | The latest standardized format |
| `editable` | A wheel that only ships `.pth` files or import hooks for real-time development |
| `editable` | A wheel that only ships `.pth` files or import hooks for real-time development |

## Default file selection

Expand All @@ -37,7 +37,8 @@ When the user has not set any [file selection](../../config/build.md#file-select
2. `src/<NAME>/__init__.py`
3. `<NAME>.py`
4. `<NAMESPACE>/<NAME>/__init__.py`
5. Otherwise, every Python package and file that does not start with the word `test` will be included

If none of these heuristics are satisfied, an error will be raised.

## Reproducibility

Expand Down
23 changes: 14 additions & 9 deletions tests/backend/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ def test_default(self, temp_dir):
config = {'project': {'name': 'my-app', 'version': '0.0.1'}}
builder = WheelBuilder(str(temp_dir), config=config)

for i in range(2):
namespace_root = temp_dir / f'ns{i}' / 'my_app' / '__init__.py'
namespace_root.ensure_parent_dir_exists()
namespace_root.touch()

assert builder.config.default_include() == ['*.py']
assert builder.config.default_exclude() == ['test*']
assert builder.config.default_packages() == []
assert builder.config.default_only_include() == []
for method in (
builder.config.default_include,
builder.config.default_exclude,
builder.config.default_packages,
builder.config.default_only_include,
):
with pytest.raises(
ValueError,
match=(
'At least one file selection option must be defined, see: '
'https://hatch.pypa.io/latest/config/build/'
),
):
_ = method()

def test_unnormalized_name_with_unnormalized_directory(self, temp_dir):
config = {'project': {'name': 'MyApp', 'version': '0.0.1'}}
Expand Down

0 comments on commit 350ca03

Please sign in to comment.