Introduction to python packaging with `pipy`

Introduction to python packaging with `pipy`

"In this module, you will learn how to package python modules using pypi. This will let you install some of your own code with pip, dealing cleanly with dependencies, as well as share publicly a package."

Information

The estimated time to complete this training module is 4h.

The prerequisites to take this module are:

If you have any questions regarding the module content please ask them in the relevant module channel on the school Discord server. If you do not have access to the server and would like to join, please send us an email at school [dot] brainhack [at] gmail [dot] com.

Resources

This module was presented by ValΓ©rie Hayot-Sasson during BrainHack School 2020. The slides are available here.

The video of the presentation is available below (57:51):

Exercice

  • To run this exercise, you will need a small python module. You can create a toy python module by following this tutorial. It would be better to start creating one (or a couple of) module(s) for your project, so you work directly with a meaningful code base.
  • Add your module to a new git repository under your personal account. This is not necessary, but putting code on git control should be second nature at this stage :) Note that the module will read in a folder inside the repository. The top level directory is for configuration files for the project, not the code itself.
  • Create and populate a README.md file
  • Create and populate a license.txt file
  • Fill a requirements.txt file. Include everything needed for development, including e.g. jupyter-notebook and pytest.
  • Fill a pyproject.toml file. Start from a template. These two last steps are much more meaningful if you are working with a code base for your project, rather than a toy module with no dependencies.
  • Configure the meta-data of your project with setup.cfg. Check the documentation of pypi for more info.
  • Add on __init.py__ in your module folder. See this example
  • Try installing your package locally by running pip install -e . in your repository.
  • Optional: You can try to create the distribution files and publish this package on a test server of pypi. This step is described in this tutorial. The pypi test server is made to test how publishing a package works - so don’t worry if this is just a test or if you make mistakes, the server exists for that purpose. If you upload the package on pipy itself, anybody will be able to install your software by typing pip install <my_package> but beware! pipy is a community resource, and you should only publish serious, well tested projects on there.
  • Follow up with your local TA(s) to validate you completed the exercises correctly.
  • πŸŽ‰ πŸŽ‰ πŸŽ‰ you completed this training module! πŸŽ‰ πŸŽ‰ πŸŽ‰

More resources