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
- 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 the
setup.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,
README.rst) should explain what your library does and how you install it. (The
- you should have a
testsfolder containing unit tests,
- the documentation related to you project should be contained in the
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
- 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.