Skip to content

Dev PyPI Packaging And Release

Tarun Aditya Thurlapati edited this page Apr 26, 2020 · 2 revisions

Packages implementation

We are packaging our entire app to form a python package, so that we can implement it as an API if required, and also to reduce the number of files an average app user has to deal with directly.

Packaging is the combination of all the related files into one directory and making an interface for that directory so that we can talk to the app from within the python console. This is more or less like Data-Hiding feature of OOP.

This is implemented by the setup.py which helps to install the python module we created using PIP (The default python package manager).

Local installation/development of package

Since this is a local Package this is how we install the todopoc Package:

  1. Using CLI, navigate to the folder where the setup.py is located
  2. Then use pip install . to install that package
  3. This is fine, but has a disadvantage to consider. If you are still testing and developing your module, you are going to change and alter its code base. However, you are going to modify only the source, not the compressed and installed module. If you want to reflect any change in the source immediately to anywhere the module is used, you need to use -e. This is known as symlink. pip install -e .
  4. To uninstall the package use pip uninstall todopoc
  5. You can verify if the packages is installed using pip list command

For installation requisites go HERE

Packaging the module for PyPI

This link has details regarding various methods and more detail, for reference.

For building a package for distribution, you need to run release.ps1 or release.sh and choose the appropriate options. To, publish to a PyPI account/project, you must have your username and password at hand.

The same version number of a package can't be published twice, not even if you delete the older package.

Each time you generate a package, you must increment the version number, in order to publish it.
The binaries are produced inside the dist folder in the parent folder of the main package.

Also, You can't have multiple packages of the same module (todopoc) and the same version installed at the same time (like, one for development and the other for general use). They HAVE to be different versions.

Making the package

  1. To make the package we need setuptools, wheel, and twine which can be obtained by running pip3 install setuptools wheel twine and make sure they are up-to-date.
  2. Running python setup.py sdist bdist_wheel creates the binaries.
  3. And you can upload them to your PyPI account by running twine upload dist/*

The Contents of MAINFEST.in make sure that all the files are included. Otherwise, only __init__.py will be in the package. All package data is specified in the setup.py, including metadata for online searches for your package.