-
-
Notifications
You must be signed in to change notification settings - Fork 324
Hatch environments support PEP735 dependency-groups #1922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,71 @@ you could then run your tests consecutively in all 4 environments with: | |
hatch run test:cov | ||
``` | ||
|
||
## Dependency Groups | ||
|
||
Environments can use [PEP 735](https://peps.python.org/pep-0735/) dependency groups with the `dependency-groups` option: | ||
|
||
```toml config-example | ||
[dependency-groups] | ||
test = [ | ||
"pytest>=7.0.0", | ||
"pytest-cov>=4.1.0", | ||
] | ||
lint = [ | ||
"black", | ||
"ruff", | ||
"mypy", | ||
] | ||
# Groups can include other groups | ||
dev = [ | ||
{"include-group": "test"}, | ||
{"include-group": "lint"}, | ||
"pre-commit", | ||
] | ||
|
||
[tool.hatch.envs.test] | ||
dependency-groups = ["test"] | ||
|
||
[tool.hatch.envs.lint] | ||
dependency-groups = ["lint"] | ||
|
||
[tool.hatch.envs.dev] | ||
dependency-groups = ["dev"] | ||
``` | ||
|
||
The `dependency-groups` option specifies which PEP 735 dependency groups to include in the environment's dependencies. This is particularly useful for organizing related dependencies and including them in appropriate environments. | ||
|
||
### Combining with Other Dependencies | ||
|
||
Dependency groups can be combined with other dependency mechanisms: | ||
|
||
```toml config-example | ||
[project] | ||
name = "my-app" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"requests>=2.28.0", | ||
] | ||
|
||
[dependency-groups] | ||
test = ["pytest>=7.0.0"] | ||
docs = ["sphinx>=7.0.0"] | ||
|
||
[tool.hatch.envs.test] | ||
# Include the test dependency group | ||
dependency-groups = ["test"] | ||
# Add environment-specific dependencies | ||
dependencies = [ | ||
"coverage[toml]>=7.0.0", | ||
] | ||
# Project dependencies will be included if not skip-install and in dev-mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't really get what this wants to tell me; it seems to be suited for a sentence or two outside the example snippet. |
||
``` | ||
|
||
In this example, the test environment would include: | ||
1. Project dependencies (`requests>=2.28.0`) | ||
2. The test dependency group (`pytest>=7.0.0`) | ||
3. Environment-specific dependencies (`coverage[toml]>=7.0.0`) | ||
|
||
## Option overrides | ||
|
||
You can modify options based on the conditions of different sources like [matrix variables](#matrix-variable-overrides) with the `overrides` table, using [dotted key](https://toml.io/en/v1.0.0#table) syntax for each declaration: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,28 @@ features = [ | |
!!! note | ||
Features/optional dependencies are also known as `extras` in other tools. | ||
|
||
### Dependency Groups | ||
|
||
You can include [PEP 735](https://peps.python.org/pep-0735/) dependency groups in your environments using the `dependency-groups` option: | ||
|
||
```toml config-example | ||
[dependency-groups] | ||
test = [ | ||
"pytest>=7.0.0", | ||
"pytest-cov>=4.1.0", | ||
] | ||
|
||
[tool.hatch.envs.test] | ||
dependency-groups = [ | ||
"test", | ||
] | ||
``` | ||
|
||
Dependency groups provide a standardized way to organize related dependencies and can be shared across different build systems. See [advanced usage](advanced.md#dependency-groups) for more details on dependency group features like including other groups. | ||
|
||
!!! note | ||
Unlike features which affect how the project itself is installed, dependency groups are separate dependencies that are installed alongside the project. | ||
|
||
Comment on lines
+125
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the point here is to point out that dependency groups are no direct project dependencies, i think that aspect can be included in one of the prior paragraphs. |
||
### Dev mode | ||
|
||
By default, environments will always reflect the current state of your project on disk, for example, by installing it in editable mode in a Python environment. Set `dev-mode` to `false` to disable this behavior and have your project installed only upon creation of a new environment. From then on, you need to manage your project installation manually. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can imagine that a completely reflected use-case would be preferable here. i don't know the current affairs reg. user documentation guidelines, maybe @lwasser has some advice.