Skip to content

Migrate setuptools configuration to pyproject.toml + PEP621 #1570

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

GabDug
Copy link
Contributor

@GabDug GabDug commented Jun 23, 2023

I have made things!

This PR is an experiment to migrate from setuptools setup.py configuration to the more declarative pyproject.toml format, following PEP 621.

It allows to remove custom discovery functions in setup.py, that are also apparently not needed, and moving to pyproject.toml may also enable the project (or its contributors) to use PEP621 compliant project managers like PDM or hatch.

Note: while using pyproject.toml is now recommended for new projects by setuptools, the [tool.setuptools] configuration is in beta and may change, as indicated by the docs.

Changes to the wheels dist_info

I did not find any differences in included files or modules, but only changes to the metadata:

  1. Author and maintainers format
 "author": "Maksim Kurnikov",
 "author_email": "maxim.kurnikov@gmail.com",
 "maintainer": "Marti Raudsepp",
 "maintainer_email": "marti@juffo.org",

to

"author_email": "Maksim Kurnikov <maxim.kurnikov@gmail.com>",
"maintainer_email": "Marti Raudsepp <marti@juffo.org>",
  1. Added two urls
 {
  "label": "Homepage",
  "url": "https://github.com/typeddjango/django-stubs"
 },
 {
   "label": "Repository",
   "url": "https://github.com/typeddjango/django-stubs"
}
  1. Removed home_page from metadata

Regarding urls/homepage, it may not be issues, see this discussion on setuptools project.

I'm willing to investigate/see upstream if you consider it might be important :)

Related issues

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Let's please separate comma and setup.py changes

@GabDug
Copy link
Contributor Author

GabDug commented Jun 23, 2023

Let's please separate comma and setup.py changes

Yes, unfortunately it seems pre-commit.ci wanted to make the changes.

@GabDug GabDug force-pushed the chore/pyproject-build branch from 9699a4e to 840ac67 Compare June 23, 2023 13:42
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great!

"Framework :: Django :: 4.2",
]
requires-python = ">=3.8"
maintainers = [{ name = "Marti Raudsepp", email = "marti@juffo.org" }]
Copy link
Member

Choose a reason for hiding this comment

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

Oh, we can now add all team as maintainers :)
Will do later.

@sobolevn
Copy link
Member

You can create a PR with , changes first. Later we can rebase this one.

@GabDug
Copy link
Contributor Author

GabDug commented Jun 24, 2023

Seems like mypy has trouble detecting the source/stubs with this new way of declaring the project. I've tried a few things with no luck, any insights are appreciated :)

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Looking into it

@sobolevn
Copy link
Member

I have no idea what is going on :)

@GabDug
Copy link
Contributor Author

GabDug commented Jun 27, 2023

I have no idea what is going on :)

I'm puzzled as well!

I'll probably try to use another build-backend like hatchling, we never know.

@intgr
Copy link
Collaborator

intgr commented Jun 27, 2023

  • Please update django_stubs_ext/setup.py as well.

@intgr
Copy link
Collaborator

intgr commented Jun 27, 2023

Please update django_stubs_ext/setup.py as well.

Ugh, that can be a bit problematic. Black for example only looks for the closest pyproject.toml, so we would need to duplicate Black configuration? Not sure about other tools.

GabDug and others added 2 commits September 17, 2023 13:31
@GabDug GabDug force-pushed the chore/pyproject-build branch from 912f5e2 to dbcb64a Compare September 17, 2023 11:32
@intgr
Copy link
Collaborator

intgr commented Oct 19, 2023

Seems like mypy has trouble detecting the source/stubs with this new way of declaring the project.

This may be related to the changes regarding editable installs in recent setuptools. We've since added SETUPTOOLS_ENABLE_FEATURES=legacy-editable in #1759 which may help with this.

@@ -31,15 +31,16 @@ known-first-party = ["django_stubs_ext", "mypy_django_plugin"]
split-on-trailing-comma = false

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
Copy link
Member

Choose a reason for hiding this comment

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

No idea what hatchling is.

If other maintainers also don't know what this is, I prefer not to rely on it :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll test again with setuptools then :)

Copy link
Member

Choose a reason for hiding this comment

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

I've used hatchling for other projects, a totally fair build system that does its job. It also comes with a sort of ecosystem for package management called hatch, which is completely optional and I've only used the build system named hatchling.

One thing I did like about it was that it validates the project section in your pyproject.toml, which was quite nice. I found that the documentation for hatchling was quite simple to pick up on too, here: https://hatch.pypa.io/latest/config/build/

It's maintained by https://github.com/pypa/ and e.g. https://github.com/pypa/virtualenv/ is packaged with hatchling: https://github.com/pypa/virtualenv/blob/9eac8a6b85c047e2287c95bdb9caf6f0fbf35041/pyproject.toml#L1-L6

It's nice to extend hatchling with hatchling-vcs to get versioning via version control(git). Should be similar to setuptools-vcs. Which is 1 less thing to remember/do when crafting a release.


I'm +1 on using hatchling

Copy link
Member

Choose a reason for hiding this comment

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

Here are their own reasons why to use hatchling as build backend instead of setuptools:

https://hatch.pypa.io/latest/why/#build-backend

@flaeppe
Copy link
Member

flaeppe commented Apr 25, 2024

Is it possible to revive this PR? Would be nice if we could upgrade to a pyproject.toml

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

Successfully merging this pull request may close these issues.

setup.py install is deprecated
5 participants