Python Packaging Notes

July 12, 2020 - 4 minute read - Category: Tech - Tags: Coding , Productivity , Python

After writing exciting code, you may want to publish and share your code with others. It seems pretty intuitive to do so - organize the python file folder, write some installation instructions, and upload them to Github and PyPI. However, this process is usually tricker than we’ve expected: We may encounter various issues like hidden bugs in the code, incompatible environments, etc.

There are many good resources available online, but they usually appear in separate posts or individual code snippets. And some important tricks are seldom mentioned in the popular tutorials.

To this end, I cleaned up the Python package building pipeline, and include some important posts that help a lot when I am making the package layoutparser. Though this post is majorly for personal reference, I hope it could also be useful to you.

Starter Reading

Pipeline for Building a Library

  1. Write the code and package them into a folder, add the __init__.py file when necessary → Project Structure
  2. Test them and ensure the there weren’t bugs → Code Quality Management & CI
  3. Add documentation if necessary → Write Documentation
    1. Create an account on the readthdocs website
  4. Extra document work
    1. Choose a license
    2. Add a readme file
  5. Prepare to distribute your work → Dependency and Distribution
    1. Add a [setup.py](http://setup.py) file listing dependencies and installation instructions
    2. Upload your package to pypi

Project Structure

Code Quality Management and CI

Write Documentation

Dependency and Distribution

Automation

Misc