Publishing well-formed Python packages
Julin S (~ju-sh) |
Most of us have written python programs. Many have written modules. Some have packaged and uploaded them to servers for distribution. And a significant portion of these packages could be made better.
Most of the well established projects follow some practices and has some mechanism in place to ensure better maintainability.
But we can find a good number of packages online which are being developed without an equivalent mechanism.
In this talk, I will mention some tools, which when used, can lay the foundation for a well formed package.
A package whose source has some structure which makes testing and development more efficient and less error-prone.
Such a package also makes working with its source a more pleasant experience.
A well-formed package makes things easier for both the developer and the user.
But it is easier to get started with a structure than to maintain that form. Which calls for a mechanism to maintain that structure.
The source code should adopt a style and stick with it. A linting tool like pylint can help with it. Or you could use black.
Use type annotations along with tools like mypy.
Eliminate unused code with
Add tests to be sure that the different functionalities work as intended using tools like pytest or the built-in unittest. This will be extremely useful to be sure that further modifications do not break existing code.
Ensure proper test coverage with coverage.py After all, adding tests isn't everything. One got to make sure it reaches every nook and corner.
Automate tests with tox, nox, etc.
Package the project in tune with the future of packaging. setuptools, flit or poetry
And add some CI/CD.
Other tools like pre-commit, bumpversion, etc may also be used.
People who create and publish python packages.
The presentation is from the package developer's perspective and not exactly about the innards of the different python packaging tools.
- Linting and style: 2 minutes
- Static type check: 2 minutes
- Dead code: 1 minute
- Package layout: 2 minute
- Unit testing: 3 minute
- Test coverage: 2 minutes
- Test automation: 4 minutes
- Packaging: 2 minutes
- Publishing: 1 minutes
- Other tools: 2 minutes
- CI/CD: 2 minutes
- The way ahead: 2 minute
Basic Python programming
Using Python for 5 years. Interested in text processing.
Published a few packages to PyPI using different packaging tools.
The proposed talk is derived from experience of creating them.