Skip to content

Replace setuptools build backend with hatchling #551

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ofek
Copy link

@ofek ofek commented Aug 26, 2022

cc @graingert as requested!

Background

Hello there! The Python packaging ecosystem has standardized on the interface for build backends (PEP 517/PEP 660) and the format for metadata declaration (PEP 621/PEP 631). As a result, the execution of setup.py files is now deprecated.

So, I'm spending my free time updating important projects so that they are modernized and set an example for others 😄

Summary of changes

This implements PEP 621, obviating the need for setup.py and MANIFEST.in. The build backend hatchling (of which I am a maintainer in the PyPA) is now used as that is the default in the official Python packaging tutorial. Hatchling is available on all the major distribution channels such as Debian, Fedora, Arch Linux, conda-forge, Nixpkgs, Alpine Linux, FreeBSD/OpenBSD, Gentoo Linux, MacPorts, OpenEmbedded, Spack, MSYS2, etc.

Python support

The earliest supported Python 3 version of Hatchling is 3.7, therefore I've also set that as the minimum here. Python 3.6 is EOL and other build backends like flit-core and setuptools also dropped support. Python 3.6 accounted for 6-8% of downloads in the last month: https://pypistats.org/packages/pytest-cov

Notes

  • The source distributions on PyPI are erroneously shipping a build artifact *.egg-info from python setup.py develop; this is now fixed
  • The CHANGELOG.rst regex substitution was doing nothing so the PyPI landing page continues to be simply README.rst + CHANGELOG.rst
  • The generated pytest-cov.pth was being checked into the repo but is not necessary now so I've removed it

Future

  • Move config for tools like pytest out of setup.cfg and into pyproject.toml

@ionelmc
Copy link
Member

ionelmc commented Aug 26, 2022

What exactly is hatch-autorun? How does it work? I don't get how this replaces the pth file we use.

@ofek ofek force-pushed the modernize-metadata branch from f7d916e to da3db18 Compare August 26, 2022 16:45
@ofek
Copy link
Author

ofek commented Aug 26, 2022

It essentially does the current logic of executing the src/pytest-cov.embed in a PTH file.

@ofek ofek force-pushed the modernize-metadata branch from da3db18 to 804b337 Compare August 26, 2022 16:58
]

[project.optional-dependencies]
testing = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as the "testing" extra right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if nowadays this could be turned into a dependency group finally..

Homepage = "https://github.com/pytest-dev/pytest-cov"
"Issue Tracker" = "https://github.com/pytest-dev/pytest-cov/issues"

[tool.hatch.metadata.hooks.fancy-pypi-readme]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the fancy pypi readme do the ref tag stripping automatically? The ol setup.py had a re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but as I mentioned in the OP it was doing nothing:

Python 3.11.0b3 (main, Jun  1 2022, 13:29:14) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib, re
>>>
>>> before = pathlib.Path('CHANGELOG.rst').read_text(encoding='utf-8')
>>> after = re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', before)
>>>
>>> before == after
True

@ofek
Copy link
Author

ofek commented Sep 4, 2022

CI passing btw

@ofek
Copy link
Author

ofek commented Sep 10, 2022

Just let me know if I can help!

@ionelmc
Copy link
Member

ionelmc commented Sep 28, 2022

I'll be honest here I'm not a fan of redoing something that works. But I am also curious how well this could work so how about this: release it as pytest-cov 5.0.0a (or beta) and we keep this in a special "alpha" branch till people try it out enough? This can only work if you pledge yourself to maintain pytest-cov's packaging from here on out :-)

@RonnyPfannschmidt
Copy link
Member

I'm also in on this, starting with pluggy, then going for other pytest projects

I like hatch enough that i decided to let my own tool die in favour of it.

@ofek ofek force-pushed the modernize-metadata branch from fd71fa5 to 9c11353 Compare October 5, 2022 04:30
@ofek
Copy link
Author

ofek commented Oct 5, 2022

I rebased to fix conflicts. Would you mind triggering the CI with that button below?

@ofek ofek force-pushed the modernize-metadata branch from 9c11353 to c860920 Compare October 20, 2022 04:38
@ofek
Copy link
Author

ofek commented Oct 20, 2022

I rebased again, accounting for #553 (comment)

@ofek
Copy link
Author

ofek commented Oct 20, 2022

flake?

@ofek ofek force-pushed the modernize-metadata branch from c860920 to 7f0fe2e Compare October 22, 2022 20:24
@ofek
Copy link
Author

ofek commented Oct 22, 2022

I rebased again, accounting for #556

@ofek
Copy link
Author

ofek commented Oct 25, 2022

Would you mind triggering the CI with that button below?

@ofek
Copy link
Author

ofek commented Oct 29, 2022

Passing 🙂

@cclauss
Copy link
Contributor

cclauss commented Feb 28, 2023

Please rebase.

flake8 src tests setup.py
isort --check-only --diff src tests setup.py
python -m build
twine check dist/*
Copy link
Member

@webknjaz webknjaz Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably include --strict too

Suggested change
twine check dist/*
twine check --strict dist/*

@ofek
Copy link
Author

ofek commented Jun 5, 2025

I don't know whether to invest time rebasing because of the previous lack of correspondence.

@RonnyPfannschmidt
Copy link
Member

@ionelmc anything preventing committing to this

Im
Happy to take ownership in that case as @ofek already did enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Looks like this is replaced by [tool.hatch.build.targets.wheel.hooks.autorun].

@@ -21,12 +21,12 @@ The process for releasing should follow these steps:
#. Make sure you have a clean checkout, run ``git status`` to verify.
#. Manually clean temporary files (that are ignored and won't show up in ``git status``)::

rm -rf dist build src/*.egg-info
rm -rf dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, this could be replaced by a git clean which is cross-platform.

Comment on lines +12 to +14
authors = [
{ name = "Marc Schlaich", email = "[email protected]" },
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to the conversion but perhaps, a maintainers entry should be added at some point too.

@webknjaz webknjaz changed the title Update package metadata Replace setuptools build backend with hatchling Jun 6, 2025
@webknjaz
Copy link
Member

webknjaz commented Jun 6, 2025

@ofek thanks for the initial effort, though! I was just going through the old PRs to see if anything could be closed and making notes. Hopefully, @RonnyPfannschmidt will get it through the finish line.

@ionelmc
Copy link
Member

ionelmc commented Jun 6, 2025

@ionelmc anything preventing committing to this

I am not against it outright, but I not a fan of fixing what ain't broken either. If you wanna bring this up to date and help with whatever issues will come up (basically own this aspect of the project) then I am ok with it.

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

Successfully merging this pull request may close these issues.

6 participants