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

Start using hatch for Python project management #241

Merged
merged 5 commits into from
May 2, 2024
Merged

Start using hatch for Python project management #241

merged 5 commits into from
May 2, 2024

Conversation

jnikula
Copy link
Owner

@jnikula jnikula commented Apr 23, 2024

Hatch seems more user-friendly than setuptools and twine, and offer more stuff like environments (which could replace the venv thing in the future).

I don't think this should make a difference to contributors or users.

Copy link
Collaborator

@BrunoMSantos BrunoMSantos left a comment

Choose a reason for hiding this comment

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

Hey, sorry for taking so long. Been quite busy with other projects.

This looks ok to me. Though I can't help but wince at just how many different ways there are to do something like this 😅

I can't say I know how this improves things either, but I'm happy to take your word for it. Frankly I have no horse in this race.

Part of me would like to have kept an historical record of what the clean setuptools version was in case we had to roll back for whatever reason, instead of changing tooling and resulting package in one go. It's too minor though, up to you.

Need a small update to my packaging I guess, no impact beyond that.

@jnikula
Copy link
Owner Author

jnikula commented Apr 30, 2024

Hey, sorry for taking so long. Been quite busy with other projects.

No worries at all!

This looks ok to me. Though I can't help but wince at just how many different ways there are to do something like this 😅

I know!

I can't say I know how this improves things either, but I'm happy to take your word for it. Frankly I have no horse in this race.

The main thing for me is reducing the number of tools for building/uploading, with fewer sharp edges, maybe using it to replace the venv script which I believe only I use anyway, and more. Mainly I'm picking hatch because it's a PyPA project.

Part of me would like to have kept an historical record of what the clean setuptools version was in case we had to roll back for whatever reason, instead of changing tooling and resulting package in one go. It's too minor though, up to you.

Yeah, I also felt a bit like too much at once, but it's non-zero effort to convert to pyproject.toml with setuptools. Maybe I'll have another look at that, but if it's too much trouble, I'll just merge this.

Need a small update to my packaging I guess, no impact beyond that.

What's that, out of curiosity?

@BrunoMSantos
Copy link
Collaborator

Part of me would like to have kept an historical record of what the clean setuptools version was in case we had to roll back for whatever reason, instead of changing tooling and resulting package in one go. It's too minor though, up to you.

Yeah, I also felt a bit like too much at once, but it's non-zero effort to convert to pyproject.toml with setuptools. Maybe I'll have another look at that, but if it's too much trouble, I'll just merge this.

Yup, sounds good!

Need a small update to my packaging I guess, no impact beyond that.

What's that, out of curiosity?

Here, Nothing special... I know someone else has installed the package at some point because I got a complaint it was out of date once, but not too popular yet 😅

This will be helpful for comparing the package build results in the
subsequent changes, as some tools sort the PKG-INFO no matter what.
Switch to a more standards compliant license short identifier:
https://spdx.org/licenses/BSD-2-Clause.
Prefer pyproject.toml over setup.cfg for packaging. The changes in the
build results are minimal, only PKG-INFO changes:

-Home-page: https://github.com/jnikula/hawkmoth
-Author: Jani Nikula
-Author-email: [email protected]
+Author-email: Jani Nikula <[email protected]>
 License: BSD-2-Clause
+Project-URL: Homepage, https://github.com/jnikula/hawkmoth

Flake8 configuration remains in setup.cfg.
Start using hatch [1] for the project management.

Due to hatch defaults, we'll need to add explicit include/exclude rules
for some files, e.g. include setup.py and exclude Makefiles.

Due to setuptools defaults [2], we've included some files from test/ as
well as the generated hawkmoth.egg-info in the source tarball. Drop
them.

[1] https://hatch.pypa.io/latest/
[2] https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html
Use hatch build and publish, remove old build-tools target, remove old
.gitignore and distclean files.

The build and upload targets could perhaps be removed in the future in
favour of using hatch directly, but keep them for now.
@jnikula
Copy link
Owner Author

jnikula commented May 1, 2024

Yeah, I also felt a bit like too much at once, but it's non-zero effort to convert to pyproject.toml with setuptools. Maybe I'll have another look at that, but if it's too much trouble, I'll just merge this.

Yup, sounds good!

Wasn't too bad actually, and I compared the build results after each commit.

Need a small update to my packaging I guess, no impact beyond that.

What's that, out of curiosity?

Here, Nothing special... I know someone else has installed the package at some point because I got a complaint it was out of date once, but not too popular yet 😅

Heh, though I did mean what changes are required due to this?

@BrunoMSantos
Copy link
Collaborator

Heh, though I did mean what changes are required due to this?

Oh, don't know. But I expect I need to tweak the PKGBUILD a bit. So (e.g.) in the official release package change the build and install lines I guess.

@jnikula
Copy link
Owner Author

jnikula commented May 1, 2024

Heh, though I did mean what changes are required due to this?

Oh, don't know. But I expect I need to tweak the PKGBUILD a bit. So (e.g.) in the official release package change the build and install lines I guess.

I think it should actually work as-is.

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

tells python3 -m build to install and use hatchling as the build backend.

@BrunoMSantos
Copy link
Collaborator

Hmm, even better then! I saw hatch build in the makefile and assumed that would be the right way(tm) to do it. I still need to add hatch to the build dependencies anyway, so not totally 0 changes.

@jnikula jnikula merged commit 9f67cae into master May 2, 2024
5 checks passed
@jnikula jnikula deleted the hatch branch May 2, 2024 08:50
@jnikula
Copy link
Owner Author

jnikula commented May 2, 2024

@BrunoMSantos Pushed, please let me know if you hit any issues with packaging!

@jnikula
Copy link
Owner Author

jnikula commented May 2, 2024

@BrunoMSantos Oh, might as well ask here about one thing. setup.cfg is now empty save for flake8 config, because flake8 doesn't support configuration via pyproject.toml, and that's a whole can of worms (PyCQA/flake8#234 and they're now closing all PRs/issues even mentioning pyproject.toml as spam...).

What to do?

@BrunoMSantos
Copy link
Collaborator

@BrunoMSantos Oh, might as well ask here about one thing. setup.cfg is now empty save for flake8 config, because flake8 doesn't support configuration via pyproject.toml, and that's a whole can of worms (PyCQA/flake8#234 and they're now closing all PRs/issues even mentioning pyproject.toml as spam...).

Had to read up on this a bit.

What to do?
* Leave it as it is.

Of the 3, I think this is the one. There might be other 3rd party tools that don't yet support the toml one and we might need to extend it before we get rid of it.

* Rename `setup.cfg` to `.flake8`.

I'm fine with this as a 2nd best option.

* Install https://github.com/john-hen/Flake8-pyproject `flake8` plugin to read config from `pyproject.toml`.

Please, no 😅

But here's another option just in case: use pyflakes, pycodestyle and mccabe directly. Pycodestyle supports the toml file and I don't think we will be configuring pyflakes or mccabe away from any default, but they may support the toml file too 🤷‍♂️

Honestly, I never use the flake8 wrapper in my own projects, so I'd switch in a heartbeat. I even had to hack my configs for those few projects I work on that use flake8. And now you know xD

@jnikula
Copy link
Owner Author

jnikula commented May 2, 2024

But here's another option just in case: use pyflakes, pycodestyle and mccabe directly. Pycodestyle supports the toml file and I don't think we will be configuring pyflakes or mccabe away from any default, but they may support the toml file too 🤷‍♂️

I don't think pycodestyle supports pyproject.toml, though: https://pycodestyle.pycqa.org/en/latest/intro.html#configuration

Also has the same maintainer as flake8, so would be suprising if it did.

Honestly, I never use the flake8 wrapper in my own projects, so I'd switch in a heartbeat. I even had to hack my configs for those few projects I work on that use flake8. And now you know xD

👀

@BrunoMSantos
Copy link
Collaborator

But here's another option just in case: use pyflakes, pycodestyle and mccabe directly. Pycodestyle supports the toml file and I don't think we will be configuring pyflakes or mccabe away from any default, but they may support the toml file too 🤷‍♂️

I don't think pycodestyle supports pyproject.toml, though: https://pycodestyle.pycqa.org/en/latest/intro.html#configuration

Hmm, could have sworn it was supported. Maybe the project I saw it in was using some other tool to bridge the gap like the one you pointed out for flake8, maybe I just remember wrong. Sorry for the misdirection then :/

Also has the same maintainer as flake8, so would be suprising if it did.

Can't say I blame him either way, I did mention the wincing 😅

@jnikula
Copy link
Owner Author

jnikula commented May 3, 2024

Hmm, could have sworn it was supported. Maybe the project I saw it in was using some other tool to bridge the gap like the one you pointed out for flake8, maybe I just remember wrong. Sorry for the misdirection then :/

No problem. And thanks for the discussion. I think I'm just going to do nothing about this.

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