ITADN

switch hatch to dependency groups, split deps to data file

#144Pull Requestsneakers-the-rat 创建于 2026-01-06
fix: https://github.com/pyOpenSci/pyos-package-template/issues/143 so this does two things, switched us over to dependency groups and splits our dependencies out into data so that the version constraints aren't all mushed up with the form of the template (which is about structure not data). however for the life of me i can't tell what's going on - the `pyproject.toml` seems to be correctly generated, here is an example with the `minimal` option: <details> <summary>expand/collapse pyproject.toml</summary> ```toml ################################################################################ # Build Configuration ################################################################################ [build-system] build-backend = "hatchling.build" requires = ["hatchling"] ################################################################################ # Project Configuration ################################################################################ [project] name = "aaa" # You can chose to use dynamic versioning with hatch or static where you add it manually. version = "0.1.0" description = "a" authors = [ { name = "a", email = "a@a.com" }, ] license = "MIT" requires-python = ">= 3.10" # Adjust based on the minimum version of Python that you support readme = {"file" = "README.md", "content-type" = "text/markdown"} # Please consult https://pypi.org/classifiers/ for a full list. classifiers = [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", ] # TODO: add keywords keywords = [] # TODO: add dependencies dependencies = [] [project.urls] Homepage = "https://github.com/aaa/aaa" "Source Code" = "https://github.com/aaa/aaa" "Bug Tracker" = "https://github.com/aaa/aaa/issues" Documentation = "https://github.com/aaa/aaa/blob/main/README.md" Download = "https://pypi.org/project/aaa/#files" [dependency-groups] dev = [ "hatch", "pre-commit", {include-group = "docs"}, {include-group = "tests"}, ] docs = [ "sphinx~=8.0", "myst-parser>=4.0", "pydata-sphinx-theme~=0.16", "sphinx-autobuild>=2024.10.3", "sphinx-autoapi>=3.6.0", "sphinx_design>=0.6.1", "sphinx-copybutton>=0.5.2", ] build = [ "pip-audit", "twine", ] tests = [ "pytest", "pytest-cov", "pytest-raises", "pytest-randomly", "pytest-xdist", ] ################################################################################ # Tool Configuration ################################################################################ # Hatch is building your package's wheel and sdist # This tells hatch to only include Python packages (i.e., folders with __init__.py) in the build. # read more about package building, here: # https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-distribution-files-sdist-wheel.html [tool.hatch.build] only-packages = true # This tells Hatch to build the package from the src/ directory. # Read more about src layouts here: https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-structure.html [tool.hatch.build.targets.wheel] packages = ["src/aaa"] ######## Configure pytest for your test suite ######## [tool.pytest.ini_options] testpaths = ["tests"] # Tells pytest what directory tests are in markers = ["raises"] # Tells pytest to not raise a warning if you use @pytest.mark.raises [tool.coverage.paths] source = [ "src/aaa", "*/site-packages/aaa", ] [tool.coverage.run] # Ensures code coverage is measured for branches (conditional statements with different outcomes) in your code. branch = true parallel = true [tool.coverage.report] # This configures the output test coverage report exclude_lines = ["pragma: no cover"] precision = 2 # Use UV to create Hatch environments [tool.hatch.envs.default] installer = "uv" builder = true ################################################################################ # Hatch Environments ################################################################################ #--------------- Build and check your package ---------------# # This table installs the tools you need to test and build your package [tool.hatch.envs.build] description = """Test the installation the package.""" dependency-groups = [ "build", ] detached = true builder = true # This table installs created the command hatch run install:check which will build and check your package. [tool.hatch.envs.build.scripts] check = [ "hatch build {args:--clean}", "twine check dist/*", ] #--------------- Run tests ---------------# [tool.hatch.envs.test] description = """Run the test suite.""" dependency-groups = [ "tests", ] [[tool.hatch.envs.test.matrix]] python = ["3.10", "3.11", "3.12", "3.13"] [tool.hatch.envs.test.scripts] run = "pytest {args:--cov=aaa --cov-report=term-missing --cov-report=xml}" #--------------- Build and preview your documentation ---------------# # This sets up a hatch environment with associated dependencies that need to be installed [tool.hatch.envs.docs] description = """Build or serve the documentation.""" # Install optional dependency test for docs dependency-groups = [ "docs", ] # This table contains the scripts that you can use to build and serve your docs # hatch run docs:build will build your documentation # hatch run docs:serve will serve them 'live' on your computer locally [tool.hatch.envs.docs.scripts] build = ["sphinx-build {args:-W -b html docs docs/_build}"] serve = ["sphinx-autobuild docs --watch src/aaa {args:-b html docs/_build/serve}"] #--------------- Check security for your dependencies ---------------# [tool.hatch.envs.audit] description = """Check dependencies for security vulnerabilities.""" dependency-groups = [ "build", ] [tool.hatch.envs.audit.scripts] check = ["pip-audit"] ``` </details> but when we go to actually run the functional tests, hatch doesn't seem to actually be installing any of the dependency group deps, or the package itself... I am pretty positive this has nothing to do with the templating change, when i diff the generated `pyproject.toml` before and after this PR, the only thing that changes pretty much is renaming the table key to `dependency-groups` . I paused the pytest run on errors and went to the generated directory and it also looked fine, and same result - when i tried to run hatch manually it didn't install any of the deps and then errored out. I have been up and down hatch's documentation and i can't figure out why it doesn't seem to want to install anything! the only other thing i can think of is it being related to https://github.com/pypa/hatch/issues/2113 which seems to require that the `builder=true` flag be present for pretty much all the envs. i lay this PR on the mercy of the court, if anyone can figure this out, gr8 I am opening this up here to see if CI behaves differently and something is just wrong on my machine. idk. --- edit: there does seem to be something going wrong where the outer hatch environment that’s running the tests for the template seems to interfere with the inner hatch environment that’s being tested - when i removed the test matrix from the template, another test failed saying that the python 3.10 environment didn’t exist, and it started working again when i removed the matrix from the outer (template) package… i can also replicate the problems here by removing all the template changes except strictly changing the keys to `dependency-group`, i think something broken in hatch. (call me old fashioned, but i am sorta liking my old fashioned ways of "simply using venvs" right now, at least with a venv i know exactly where it is and what's in it and there's no tool in between me and python, but all these environment virtualization tools seem to want to get too fancy and break lol) --- edit2: ope wait no it's just this: https://github.com/pypa/hatch/issues/2152
合并状态:未合并 10 条评论