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
Switch to pyproject.toml #607
Conversation
487b2a6
to
d2de8c1
Compare
I'm for this, I think it makes everything cleaner, that we need the cfg and setup.py files is not a biggie in my opinion. |
9ee4a70
to
3546df3
Compare
@alejandrogallo Awesome! Can you check that the packaging on your end also works? I just ran The remaining issues are:
|
cc @f0rki This may need some changes for the Docker of nix files, so just a heads up if you have any thoughts! |
@alexfikl FYI: I have tested ruff in the docker branch and also pushed some fixes (missing noqa for ruff and removal of unnecessary noqa). |
I mostly switched to ruff in my own projects too and it's pretty nifty. However, for papis we were supporting python 3.6 just a couple of months ago, so I'm weary of moving to the latest tools too fast.. |
btw. after (or along with) the switch to poetry, we should switch to poetry2nix in the |
This still uses setuptools. They introduced a Having said that, it's probably very easy to switch to another build backend now, since most of this stuff is pretty standardized. |
60b482c
to
7bbea7a
Compare
48cda6d
to
b01f1d5
Compare
7cfa9fa
to
8d32fca
Compare
fd0fe66
to
99c1736
Compare
Agreed, I just don't understand why it works given pypa/installer#128. Setuptools supports both |
Fair enough! It was just an idea given big projects do it. |
It's very easy to move to hatch or pdm or flit or whatnot after this gets in, so I'm not very bothered about choosing one now, since for our purposes they mostly do the same thing anyway. I guess the main thing holding this back is just that we agree to go for it (it's a big packaging change and I was weary of just merging it). @alejandrogallo @jghauser What do you think? 😁 All the issues besides how to install the man pages and completions should be solved. |
@kiike I was just reading through the Why Hatch? thing and it says that the editable installs with setuptools don't work with VSCode. Is that true? That would be a very good reason to switch from it.. |
It's hard to say. Editable installs with setuptools sometimes break but not only with VS Code. My current experience with VS Code is that setup.py-based projects definitely work worse (no or broken debugging and test discovery) than pyproject.toml-based ones. I can't point to setuptools directly being the reason, but I strongly believe that setup.py has to do with the issues more than the build backend. I am adding a feature to papis zotero and, since I was working on main of both projects, suddenly debugging doesn´t work due to setup.py. I'll move to the pyproject branch on papis, then create and move papis-zotero to a pyproject branch too. Then I'll tell you if setuptools makes it work or not. EDIT: Right now, in my machine the problem is setup.py, not setuptools. It really irks me that both things are mixed up. I have a VS Code workspace with both papis and papis-zotero open, I edited the server and ran the program without rebuilding anything, just saving the file. And the edit worked perfectly: For me a compelling reason to move to hatch is that the plugins are super easy to implement and the codebase easier to grasp. Yesterday I was following a fragment of it with the VS Code debugger while trying out my hook and it's very approachable. But I really don't have any horse in this race. |
33bf6ae
to
cd4fe06
Compare
Thanks for testing! I went ahead and removed the |
Awesome!
It is!: https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py has the instructions to fix it. Here is the relevant line in this project: Line 96 in eb1a273
|
Wait. Editable installs with setuptools+wheels+pyproject.toml are broken. But not only in VS Code, but in my regular installation (openSUSE MicroOS with Python 3.12 installed in a nix env) as well as an ephemeral distrobox: I wanted to run I recreated the setup, tried to run Unusable imports. My papis-zotero venv has However, same setup with hatchling works perfectly with editable installs. So it really helps in that regard. If you want to test for yourself, you just need distrobox. On my machine it makes a vm with an openSUSE tumbleweed (a rolling release distro). The repos have Python 3.11 and setuptools 65 as default when you install python3. distrobox-ephemeral --unshare-all --home /tmp/eph
cd
sudo zypper in git python3 make
git clone https://github.com/alexfikl/papis && cd papis && git checkout pyproject && cd
git clone https://github.com/papis/papis-zotero && cd papis-zotero && git checkout build/pyproject
python3 -m venv .venv && source .venv/bin/activate
pip install -e /tmp/eph/papis
pip install -e .
make mypy It will fail. Now, change both pyproject.toml's build-system to:
Next,
It will work. EDIT: I found it quite strange, so tried to reproduce in Ubuntu 22.04 and it's broken there and even in Arch. I thought upgrading setuptools to the latest version would solve this, but I couldn't get it to build both projects with setuptools v69.
EDIT2: There's a setup.cfg setting that apparently solves this:
I added it to both projects (only contents in papis). No effect. Mypy doesn't find the imports. FINAL EDIT (this is fun): It's a known issue with mypy+setuptools editable installs |
Can confirm this is actually happening and it's very annoying. I wasn't seeing it because I had papis installed globally and it picked up the It does seem like Thanks again for looking into this and testing! |
Glad I could help at all! |
19333bc
to
1c95fd4
Compare
I had a quick look at the whole python build landscape, and while I have to say that it's a little over my head, I think moving to |
Co-authored-by: Enric Morales <me@enric.me>
Thank you everybody for taking a look at this and testing! I'll go ahead and merge it 🚀 |
That's awesome! Thanks @alexfikl! ❤️ |
This PR moves all the configuration to a
pyproject.toml
file fromsetup.cfg
andsetup.py
. It uses hatchling as a build backend instead of setuptools because it seems like it has good support for editable installs and other build-related things.Unfortunately, we still need:
setup.cfg
for configuringflake8
.This could be switched to something likeruff
in the future?Usingflake8-pyproject
to get around flake8 not having direct support forpyproject.toml
setup.py
for configuring and installing the bash/fish/zsh completion.Not quite sure what the situation is with this; will need to hunt down some projects installing completions and manpages.This seems to be possible by adding them in a[tool.setuptools.data-files]
section, but it's not platform independent.