Hatchling metadata hook to generate all extras
Project description
hatchling-autoextras-hook
Hatchling metadata hook to automatically generate an all extra that combines all optional
dependencies.
Overview
This package provides a Hatchling metadata hook that
automatically creates an all extra in your project's optional dependencies.
The all extra will contain all dependencies from all other extras, making it easy for users to
install all optional features at once.
Installation
Add this package as a build dependency in your pyproject.toml:
[build-system]
requires = ["hatchling>=1.18.0", "hatchling-autoextras-hook"]
build-backend = "hatchling.build"
Usage
Enable the hook in your pyproject.toml:
[tool.hatch.metadata.hooks.autoextras]
Important: Hatchling metadata hooks are only triggered when there is at least one dynamic field
in your project metadata. If you don't already have any dynamic fields, you can add version as a
dynamic field:
[project]
name = "your-package"
dynamic = ["version"]
[tool.hatch.version]
path = "src/your_package/__init__.py"
Then add __version__ = "x.y.z" to your __init__.py file.
Example
Given this configuration:
[build-system]
requires = ["hatchling>=1.18.0", "hatchling-autoextras-hook"]
build-backend = "hatchling.build"
[project]
name = "my-package"
dynamic = ["version"]
[project.optional-dependencies]
dev = ["pytest>=7.0", "black>=22.0"]
docs = ["sphinx>=5.0", "sphinx-rtd-theme>=1.0"]
typing = ["mypy>=1.0"]
[tool.hatch.version]
path = "src/my_package/__init__.py"
[tool.hatch.metadata.hooks.autoextras]
The hook will automatically generate an all extra combining all dependencies:
[project.optional-dependencies]
all = [
"black>=22.0",
"mypy>=1.0",
"pytest>=7.0",
"sphinx-rtd-theme>=1.0",
"sphinx>=5.0",
]
# ... dev, docs, typing remain unchanged
Users can then install all optional dependencies with:
pip install your-package[all]
Features
- Automatically combines all optional dependencies
- Removes duplicates across extras
- Sorts dependencies alphabetically for consistency
- Works seamlessly with the Hatchling build system
- Zero configuration required - just enable the hook
- Compatible with all Hatchling build targets (wheel, sdist)
Configuration
The hook requires minimal configuration. Simply add it to your pyproject.toml:
[tool.hatch.metadata.hooks.autoextras]
Currently, the hook does not support any additional configuration options. It automatically:
- Creates an
allextra containing all dependencies from all other extras - Excludes any pre-existing
allextra from being included in the newallextra - Maintains all original extras unchanged
Advanced Usage
Excluding the Hook from Certain Extras
If you want to manually manage your all extra or prevent certain extras from being included,
you can work around this by using a different extra name (like all-deps) and then creating
your own all extra manually.
Using with Other Metadata Hooks
This hook is compatible with other Hatchling metadata hooks. They will run in the order specified in your configuration.
Troubleshooting
Hook Not Triggering
Problem: The all extra is not being generated.
Solutions:
-
Ensure you have at least one dynamic field in your
[project]section:[project] dynamic = ["version"]
Hatchling metadata hooks only run when there are dynamic fields.
-
Verify the hook is properly registered in your
[build-system]:[build-system] requires = ["hatchling>=1.18.0", "hatchling-autoextras-hook"]
-
Check that the hook configuration exists:
[tool.hatch.metadata.hooks.autoextras]
all Extra Missing Dependencies
Problem: Some dependencies are missing from the generated all extra.
Solution: Ensure all your extras are defined in [project.optional-dependencies].
The hook only processes extras defined there.
Build Failures
Problem: Build fails with errors related to the hook.
Solutions:
- Verify you're using Hatchling >= 1.18.0
- Check that your
pyproject.tomlsyntax is correct - Try building with verbose output:
python -m build -v
FAQ
Q: Will this hook override my manually defined all extra?
A: Yes, if you have a manually defined all extra in your [project.optional-dependencies],
it will be replaced with the auto-generated one. The hook regenerates the all extra from all
other extras each time the build runs.
Q: Can I exclude specific extras from being included in all?
A: Not currently. The hook includes all extras by default. If you need this functionality, please open a feature request on GitHub.
Q: Does this work with dependency groups (PEP 735)?
A: This hook specifically works with optional dependencies defined in
[project.optional-dependencies]. It does not process dependency groups defined in
[dependency-groups] as those are not part of the package metadata.
Q: Will this slow down my build process?
A: No, the performance impact is negligible. The hook simply collects and sorts dependency strings, which is a fast operation even for projects with many extras.
Q: Can I use this with Poetry or PDM?
A: This hook is specifically designed for Hatchling. It won't work with Poetry or PDM's build systems. Those tools have their own mechanisms for managing extras.
Q: How do I verify the hook is working?
A: Build your package and inspect the generated wheel's metadata:
python -m build
unzip -p dist/your_package-*.whl '*/METADATA' | grep -A 10 "Provides-Extra: all"
Q: Does this hook modify my source files?
A: No, the hook only modifies the package metadata during the build process. Your source
files, including pyproject.toml, remain unchanged.
Development
This project uses uv for dependency management.
Dependencies
batcharray |
hatchling |
python |
|---|---|---|
main |
>=1.18,<2.0 |
>=3.10 |
0.1.0 |
>=1.18,<2.0 |
>=3.10 |
0.0.2 |
>=1.18,<2.0 |
>=3.10,<3.15 |
0.0.1 |
>=1.18,<2.0 |
>=3.10,<3.15 |
Contributing
Please check the instructions in CONTRIBUTING.md.
Suggestions and Communication
Everyone is welcome to contribute to the community. If you have any questions or suggestions, you can submit Github Issues. We will reply to you as soon as possible. Thank you very much.
API stability
:warning: While hatchling-autoextras-hook is in development stage, no API is guaranteed to be
stable from one release to the next.
In fact, it is very likely that the API will change multiple times before a stable 1.0.0 release.
In practice, this means that upgrading hatchling-autoextras-hook to a new version will possibly
break any code that was using the old version of hatchling-autoextras-hook.
Security
For information about security policies and how to report vulnerabilities, please see our Security Policy.
License
hatchling-autoextras-hook is licensed under BSD 3-Clause "New" or "Revised" license available
in LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatchling_autoextras_hook-0.1.0.tar.gz.
File metadata
- Download URL: hatchling_autoextras_hook-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39d619b9ce5114b9675397c50172c1615bae36f2ebb8fcd3890a3f0a11c0a716
|
|
| MD5 |
8c06aaecbe81b62a2154d0b3a5f213e1
|
|
| BLAKE2b-256 |
9378c828b6de98410d174d82d44307e4c7c94d5874bef692f5ec4da3126ddeb1
|
File details
Details for the file hatchling_autoextras_hook-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hatchling_autoextras_hook-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b789595620190eebe5be73bf820574748bba18c3cb435e481deb77ba1c35ab8
|
|
| MD5 |
f60fd6e31c2a22fa2e30c34cccb547d0
|
|
| BLAKE2b-256 |
7c4b25ab453c2400a691c054096c6bff860d3bbc70fd0c1fc23fe526794bec65
|