Python packaging

… to be updated.

Cool

  • Poetry: basically does all the building work for you. See here for an example.
  • I also think having setup.py and installing from GH is the move with github CI actions for auto-version updating. See here for minimal example.

Poetry tutorial

Create

  1. poetry new package-name:
package-name/
├── package-name/
│   └── __init__.py
├── tests/
│   ├── __init__.py
│   └── test_package-name.py
├── pyproject.toml
└── README.md
  1. Edit pyproject.toml as needed
  2. Run pipreqs ../ in package-name/package-name
  3. Make poetry lock file and auto-specify dependecies via poetry add $( cat requirements.txt )
  4. Build the dist: poetry build
  5. (First time) configure PyPI credentials poetry config pypi-token.pypi my-token where my-token is your api token.
  6. Publish to PyPI: poetry publish
  7. (Optional) add dist/ to a .gitignore.

Update

  1. (Optional) dependency resolvation:
    1. Run pipreqs ../ in package-name/package-name
    2. Make poetry lock file and auto-specify dependecies via poetry add $( cat requirements.txt )
  2. Edit version number in pyproject.toml
  3. Build the dist: poetry build
  4. Publish to PyPI: poetry publish