33  Packaging: Python (Hatch)

Learning Objectives

  1. Be able to distinguish between essential software package elements (required to make a minimal software package) and those that are not essential but act to improve the user and developer experiences.
  2. Define what a namespace is.
  3. Explain the role of the code within the following software package files:
  • Python
    • pyproject.toml
    • __init__.py
    • docs/*
    • .github/workflows/ci-cd.yml
  1. Explain at a high level how the Cookiecutter project template tool works.
  2. Generate well formatted function and package-level documentation for software packages using available tools (e.g., numpy-style dosctrings and Sphinx in Python)

33.1 PyOpenSci Package Tutorial

Please follow the PyOpenSci Packaging Tutorial: https://www.pyopensci.org/python-package-guide/tutorials/intro.html

A few changes from the tutorial

33.1.1 Conda environments

We are not using hatch for environment management, you can start the tutorial with a conda environment:

name: pyos
channels:
  - conda-forge
dependencies:
  - python>3.12
  - copier # optional if you want to use the base pyopensci template and follow along their tutorial

Remember to activate this envionment before doing any packaging steps.

All you other dependencies will be in the pyproject.toml file under the dependencies section.

33.2 Publishing

On the publishing step (<https://www.pyopensci.org/python-package-guide/tutorials/publish-pypi.html#steps-for-publishing-a-python-package-on-testpypi-or-pypi), step 1 uses a hatch env create you do not need to run this command or step.