Skip to content
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

Update package metadata #1348

Merged
merged 5 commits into from
May 29, 2024
Merged

Update package metadata #1348

merged 5 commits into from
May 29, 2024

Conversation

ofek
Copy link
Contributor

@ofek ofek commented May 29, 2024

Motivation and Context

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 😄

Some other Django projects that have been updated:

Description

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.

Related Issue

jazzband/help#313

How Has This Been Tested?

tox -e py312-djmain-sqlite3

Checklist:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

Notes

  • The project is no longer polluted with build artifacts such as a *.egg-info directory.
  • (See "Why Hatch?") The project now supports static analysis for external tools such as IDEs for editable installations. With setuptools, you must provide additional configuration which means that by default, for example, you would not get autocompletion in Visual Studio Code. This is marked as a legacy feature and may in fact be removed in future versions of setuptools.

ofek and others added 4 commits May 29, 2024 08:24
This can help avoid potential confusion, like what appears to have been
the cause of jazzband#1326.
They're now aligned left-to-right instead of above each other on GitHub.
(The rendered RST on PyPI and in the docs should be unaffected.)

Also changed their order.
Most of the changes to `pyproject.toml` were made by running
`hatch new --init` (see
https://hatch.pypa.io/latest/intro/#existing-project).
Most of the changes to the other files were based on the changes made in
django-commons/django-debug-toolbar#1690.

### `release.yml`:
* `hatch version` is run instead of `hatchling version` (as is done in
  the PR mentioned above), as the latter crashes with the error:
  ```
  hatchling.plugin.exceptions.UnknownPluginError: Unknown version source: vcs
  ```
  Installing `hatch` takes considerably longer than just `hatchling`,
  but I think it's still acceptable.
* Updated the `pypa/gh-action-pypi-publish` action from the sunset
  `master` branch to `release/v1`; see warning at
  https://github.com/jazzband/django-simple-history/actions/runs/9246937361.
  Also replaced the deprecated `repository_url` with `repository-url`; see
  https://github.com/pypa/gh-action-pypi-publish/blob/v1.8.14/action.yml#L15
### `.pre-commit-config.yaml`:
* Added some pre-commit hooks for formatting and validating
  `pyproject.toml`
### `MANIFEST.in`:
* Removed `MANIFEST.in`, as the default
  `[tool.hatch.build.targets.sdist]` configuration (in `pyproject.toml`)
  includes all files not ignored through our `.gitignore`; see
  https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection
### `pyproject.toml`:
* Didn't include the `license` field, as the docs recommend using a
  `License ::` classifier instead - see
  https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license
* The classifier "Programming Language :: Python :: 3"
  was changed to "Programming Language :: Python :: 3 :: Only"
  by the `pyproject-fmt` pre-commit hook
* Set `core-metadata-version = "2.2"` (copied from
  django-commons/django-debug-toolbar#1916) due to
  jazzband/help#360
* Didn't include the last 3 packages from the `packages` kwarg in
  `setup.py` when configuring `[tool.hatch.build.targets.wheel]`, since
  they don't make any difference in the generated wheel, as having just
  `simple_history` will include all its subpackages
* As part of porting long_description's file concatenation from
  `setup.py`, `hatch-fancy-pypi-readme` was added to `requires` and
  configured to concatenate the same files - except with the first title
  of `README.rst` and the "Unreleased" section of `CHANGES.rst` removed
  (facilitated by the added "Start of PyPI readme" comments in those two
  files)
Copy link

codecov bot commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.77%. Comparing base (733f4e0) to head (35c540e).
Report is 17 commits behind head on master.

Current head 35c540e differs from pull request most recent head 19722e2

Please upload reports for the commit 19722e2 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1348      +/-   ##
==========================================
- Coverage   96.83%   96.77%   -0.06%     
==========================================
  Files          24       24              
  Lines        1452     1457       +5     
  Branches      237      240       +3     
==========================================
+ Hits         1406     1410       +4     
- Misses         24       25       +1     
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ddabble ddabble left a comment

Choose a reason for hiding this comment

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

Thank you, this is very much appreciated! 😄

I actually happened to be working on the same update simultaneously, so I merged your changes with mine; please let me know if you have any feedback on my changes 🙂

tox.ini Outdated Show resolved Hide resolved
@ofek
Copy link
Contributor Author

ofek commented May 29, 2024

Wow, that's pretty crazy timing! If you are planning on doing the same to other repositories maybe you could let me know what you're doing next and I'll do the same for others. We could coordinate in the tracking issue I linked in the description if you want!

ddabble added a commit to ofek/django-simple-history that referenced this pull request May 29, 2024
Isolated build environments are enabled by default from tox v4; see
jazzband#1348 (comment)
@ddabble
Copy link
Member

ddabble commented May 29, 2024

Yeah, I was pretty surprised to see your PR in my inbox 😅 I don't have any plans on doing the same in other repos, but I'll keep the tracking issue you mentioned in mind if I make any 😊 (Just to be clear, I'm assuming you were talking about jazzband/help#313, right?)

@ofek
Copy link
Contributor Author

ofek commented May 29, 2024

Yes that is the issue I was referring to! Okay sounds good, I will do some more in my free time tonight.

tim-schilling
tim-schilling previously approved these changes May 29, 2024
pyproject.toml Show resolved Hide resolved
# Conflicts:
#	.github/workflows/release.yml
#	CHANGES.rst
#	pyproject.toml

Changes in `pyproject.toml`:
* Removed `license`, for the reason stated in fef00f6
* Removed duplicate "Framework :: Django" classifier (originating from
  `setup.py`)
* Replaced `version_scheme` with "no-guess-dev", which is the docs'
  recommended replacement for "post-release" - which is deprecated (see
  https://setuptools-scm.readthedocs.io/en/stable/extending/#available-implementations)
* Removed `include`, as the default configuration includes all files not
  ignored through our `.gitignore` (see
  https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection),
  which is what we want in the source distribution (sdist)
* Added link to issue in the comments on the `core-metadata-version`
  fields - see
  jazzband#1348 (comment)

Changes in `tox.ini`:
* Removed `isolated_build`, as isolated build environments are enabled
  by default from tox v4 - see
  jazzband#1348 (comment)
@ddabble
Copy link
Member

ddabble commented May 29, 2024

Yes that is the issue I was referring to! Okay sounds good, I will do some more in my free time tonight.

Nice, keep up the good work! 😄

@ddabble ddabble merged commit 6a8918e into jazzband:master May 29, 2024
17 checks passed
@ofek ofek deleted the modernize-metadata branch May 29, 2024 16:09
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.

3 participants