First things first, you need to properly structure your project. A quick guide on how to structure a python library can be found at the following links: in french and in english.
We will take one example: the sample python package…which only purpose is to explain how to properly structure and distribute a project. The sources can be found on GitHub.
Here is how the library is structured:
qdouasbin@jolly:~/Desktop/sampleproject>find . | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
.
|-tests
| |-test_simple.py
| |-__init__.py
|-MANIFEST.in
|-README.md
|-setup.py
|-tox.ini
|-sample
| |-__init__.py
| |-package_data.dat
|-setup.cfg
|-LICENSE.txt
|-data
| |-data_file
In short:
- the repository must contain a
setup.pyfile to easily install your library using the nice and simple install mechanisms described above. You can also specify your configuration in thesetup.cfgbut thesetup.pystill need to be present. More info here - your sources must be contained in a folder named as the library name (here the
sampledirectory) you want to create, - you should have a LICENSE.txt or LICENSE.md explicitly explaining under which software license your packages falls into,
- the
README.md(orREADME.rst) should explain what your library does and how you install it. (TheMANIFEST.inis - you should have a
testsfolder containing unit tests, - the documentation related to you project should be contained in the
docsfolder - a
requirement.txtfile containing all the dependencies (i.e. the python packages needed by your library)
To create a pip-installable package you need to create a setup.py. To test that your setup.py works you need to run the pip install . in the folder containing the setup.py. If it doesn’t work you need to:
pip uninstall my_project- modify the
setup.py - re-run the
pip install .command
There are a lot of ways to populate a setup.py file as there are many options.
The best option here is to start from an existing one and modify it to your needs.
You can take the one of the sample project for example or the template_module example if you have access to Nitrox (you might need to ask the rights to access this repository to Corentin Lapeyre).
More on this topic can be found in the setuptools’ documentation setuptools’ documentation.