Publishing well-formed Python packages

Julin S (~ju-sh)


2

Votes

Description:

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.


Why?

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.


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.


How

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 vulture.

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.


Intended audience

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.


Talk outline

  • 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

Prerequisites:

Basic Python programming

Git.

Video URL:

https://www.youtube.com/watch?v=zIOkhc09vYE

Speaker Info:

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.

Speaker Links:

Stackoverflow: https://stackoverflow.com/users/5375464/j-s

Section: Developer tools and automation
Type: Talks
Target Audience: Intermediate
Last Updated: