Template for creating python packages that can be published to PyPi
Each folder that should be considered a module must contain an __init__.py
file. The file may be blank, but at can also contain imports to decrease the number of imports needed in files using the package
Use the pyenv library to control which python version is installed in your local virtual environment. With pyenv you can install different versions of python to use for virtual environments and the relevant version is simply activated by running pyenv global 3.9.5
.
For easy collaboration use poetry to handle dependencies. With the correct version of python activated, the virtual environment may be created by running poetry install
. If no pyproject.toml
, then first run poetry init
and then poetry install
.
Regardless of whether poetry is used or not, dependencies should be added to the pyproject.toml
file.
When using file types other than .py, it is necessary to add a MANIFEST.in file
Navigate to this folder and run pip install .
To build wheel based on toml file, simply run python -m pip wheel .
Methods in a module can be made partly private by prefixing the name with and underscore. It makes sure that the methods are not included in imports of type: from package.module import *
, but in other types of imports they will be included
A class method can be made inaccessible outside the class by prefixing the name with two underscores
test