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

Write version in pyproject toml if available #401

Merged
merged 7 commits into from
Feb 8, 2023
Merged

Conversation

mauritsvanrees
Copy link
Member

  • Added pyproject.toml and moved most metadata there. "Eat your own dog food." I am not sure if we can get rid of the remaining parts of setup.py.
  • Add reader. I added tomli to the dependencies on Pythons earlier than 3.11. Chances are that you already have this via a different dependency. On 3.11 I use the built-in tomllib.
  • Add writer. This is not that different from how we write to setup.py or other files.
  • Checked that bin/prerelease updates the version in our own pyproject.toml. I did not commit this.

This fixes issue #373.

Copy link
Collaborator

@reinout reinout left a comment

Choose a reason for hiding this comment

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

Good idea!
Most important point: I think a test has to be added? There will be corner cases later on, I fear.

pyproject.toml Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
zest/releaser/vcs.py Show resolved Hide resolved
The writing of the version works, which is the main thing I wanted to fix.
But currently zest.releaser only creates an sdist and wheel if there is a `setup.py` file.
In that case it runs `python setup.py sdist`, etc.
So there is room for improvement.

In the new test, I use the tha.example package, remove `setup.cfg` and `setup.py`, and add a `pyproject.toml`.
I compiled this file with help from `pdm`.
See also https://pdm.fming.dev/latest/usage/cli_reference/#exec-0--import
Roughly:

- Extract the example.tar and copy it somewhere.
- In that directory do git init and commit everything.
- Do `pipx install pdm`.
- pdm init
- pdm add setuptools  # otherwise you get an error in the next step
- pdm import setup.py
- Then you can look at the generated pyproject.toml.

It is a basis, but you may need to change stuff.
I did not want a big file, so I removed a lot of lines.

Easiest way that I found to check the result, is to call `pyroma .`
You should first remove `setup.cfg` and `setup.py` of course.
Well, you can also combine two or three of these files.
I think for a package with only `pyproject.toml` you need at least `setuptools` 61.

Just thinking out loud:
For Plone projects, and perhaps also zest.releaser, it may be best to:

- Translate imperative setup.py to declarative setup.cfg.  So keep using setuptools for now.
- Add a pyproject.toml and specify setuptools as the build system:

```
[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"
```

Maybe without minimum version.
Python 3.6 tests fail with:

    ERROR: No matching distribution found for setuptools>=61

And we do seem to need that in this new test with pyproject.toml only.
Python 3.6 is out of support of the Python community anyway.

See https://github.com/zestsoftware/zest.releaser/actions/runs/4127226730/jobs/7130170595
In setup.py this used compatibility code for Python 2, and encoding fallbacks, which are ugly,
pyproject.toml cannot handle multiple files, as far as I can see.
setup.cfg happily does this.
@mauritsvanrees
Copy link
Member Author

Okay, so I added a test, and it works fine. The message from the commit may be interesting: 1bd1315.

Problem: the test does not work on Python 3.6, so I dropped support for that. We will want to make a major release for this.
And the test shows that if you only have a pyproject.toml and no setup.py at all, then fullrelease does not create and upload distributions to PyPI. So that is something that we need to fix. That is basically issue #295.

I think the current PR is fine to merge: it enables updating the version when it is in pyproject.toml. But releasing still needs a setup.py at this point, though it can be mostly empty.
We could make an 8.0.0a1 release with this.

@reinout
Copy link
Collaborator

reinout commented Feb 8, 2023

I agree. I'll merge it.

@reinout reinout merged commit 43febbe into master Feb 8, 2023
@reinout reinout deleted the maurits-pyproject-toml branch February 8, 2023 22:14
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.

2 participants