Live data from Hacker News

How to create a Python package in 2022

mathspp.com

1–10 of 153 posts

Re: How to create a Python package in 2022

#6
This is really nicely written; kudos to the author for compiling a great deal of information in a readable format.

If I can be forgiven one nitpick: Poetry does not use a PEP 518-style[1] build configuration by default, which means that its use of `pyproject.toml` is slightly out of pace with the rest of the Python packaging ecosystem. That isn't to say that it isn't excellent, because it is! But you the standards have come a long way, and you can now use `pyproject.toml` with any build backend as long as you use the standard metadata.

By way of example, here's a project that's completely PEP 517 and PEP 518 compatible without needing a setup.py or setup.cfg[2]. Everything goes through pyproject.toml.

[1]: https://peps.python.org/pep-0518/

[2]: https://github.com/trailofbits/pip-audit/blob/main/pyproject...

Re: How to create a Python package in 2022

#7
I guess it's a great exercise to set up a repository yourself in this way, but once you have experience with the technologies involved, it's much easier to just use a cookiecutter template [1] to set up your package. Another aspect to consider is that there are often different tools to achieve the same goal, thus, it makes sense to experiment until you've found your perfect package setup.

[1] https://github.com/search?q=python+package+cookiecutter

Re: How to create a Python package in 2022

#8
You can take this a step further and completely automate the release of your package. That means the tagging, publishing and the GitHub release notes.

I don't have a blog post but you can see the process on my personal project https://github.com/DontShaveTheYak/cf2tf

Check out the merged PR's and the GitHub actions.

I even do alpha releases to test pypi.

Re: How to create a Python package in 2022

#9

"How do you create a Python package? How do you set up automated testing and code coverage? How do you publish the package? That's what this article teaches you." — delivered as promised!

Even more: "created a Python package; set up Poetry for dependency management; set up a GitHub repository to host the code; defined some pre-commit hooks to make sure we only make commits that meet certain criteria; added a (fairly permissive) license to the project; configured Poetry to allow uploading to PyPI and a test version of PyPI; tested uploading the package to a test version of PyPI; added Scriv to help us with changelog management and generation; tagged and published a release of our project; wrote a bunch of tests; automated testing and linting with tox; checked code coverage and got it to 100%; set up CI/CD with GitHub actions to run linting and testing; integrated with Codecov to get coverage reports in our pull requests; created a GitHub action to publish our package to PyPI automatically; and added some nifty badges to the README file."
Post reply on HN