Skip to content

Conversation

@eliotwrobson
Copy link

Summary

This PR implements support for PEP 735 dependency groups in the pyos-package-template, addressing issue #143.

Changes Made

1. Updated template/pyproject.toml.jinja

  • Added conditional logic to use [dependency-groups] when use_hatch_envs=True
  • Kept [project.optional-dependencies] for backward compatibility when use_hatch_envs=False
  • Moved all development dependencies (dev, docs, build, tests, style, types) to the new [dependency-groups] section
  • Added twine to the dependency-groups build section

2. Updated Hatch Environments

  • Changed all hatch environments from features = [...] to dependency-groups = [...]
  • Added builder = true to the build environment (required for Hatch 1.16+)
  • Added explicit dependencies = ["twine"] to build environment as a workaround for dependency-groups not being installed in builder environments (see Builder and non-dev environments ignore dependency groups pypa/hatch#2152)
  • Updated environments: build, test, docs, style, audit, and types

3. Added Tests

  • Created test_hatch_deps_groups() to verify dependency-groups are properly configured when using hatch environments
  • Updated test_template_suite() to use hatch run build:check instead of hatch build --clean and explicitly enable hatch environments

4. Updated Documentation

  • Updated CHANGELOG.md with comprehensive notes about the migration
  • Documented the requirement for Hatch 1.16+
  • Explained backward compatibility when use_hatch_envs=False

Key Benefits

Standards-compliant: Uses PEP 735 dependency groups instead of tool-specific optional-dependencies
Less tool lock-in: Makes the template less attached to Hatch-specific configuration
Forward-compatible: Leverages the newly released Hatch 1.16 support for dependency groups
Backward-compatible: Maintains optional-dependencies when not using Hatch environments

Testing

  • Added new test test_hatch_deps_groups() that validates the dependency-groups configuration
  • Updated existing test to use the new build environment command

Notes

  • Requires Hatch 1.16+ for full functionality
  • When use_hatch_envs=False, the template continues to use [project.optional-dependencies] for backward compatibility

Fixes #143

cc @mathematicalmichael @Midnighter @sneakers-the-rat

- Replace [project.optional-dependencies] with [dependency-groups] when use_hatch_envs=True
- Update all hatch environments to use dependency-groups instead of features
- Add builder=true to build environment for Hatch 1.16+ compatibility
- Add workaround for twine in build environment (hatch issue #2152)
- Maintain backward compatibility with optional-dependencies when use_hatch_envs=False
- Add test_hatch_deps_groups() to validate dependency-groups configuration
- Update test_template_suite() to use hatch run build:check
- Document changes in CHANGELOG.md

Fixes #143
@eliotwrobson
Copy link
Author

Ran on the wrong ticket by accident 🤦🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enh: Support dependency groups in our pyproject.toml / template

2 participants