Tutorial¶
Important note: Package Helper is no longer maintained. We recommend you to migrate to Package Helper 2.
Package Helper helps you create, develop and maintain a package. If you use all the tools presented in this tutorial, things will work this way:
You create the file structure of your package in less than a minute with Cookiecutter.
You use the IDE PyCharm. It is configured to:
- Generate the documentation of your package locally,
- Run the unit tests.
Your project is on GitHub. When you push modifications:
- ReadTheDocs automatically generates the documentation and publishes it online.
- Travis-CI automatically runs the unit tests on several versions of Python,
- Codecov displays what parts of the package are covered by the unit tests.
When you make a release on GitHub, Travis-CI automatically publishes your package on PyPI. This way, any Python user can install it with
pip install.Pyup helps you keep your development requirements up to date, such as
sphinxorpytest.
Tick the tools that you want to use:
Develop and Maintain Your Package¶
Release a Version
Test your package:
Run the tests (in PyCharm and/or in Travis).
Check your coverage on Codecov and add tests if necessary.
In PyCharm:
Check that all new classes are in the file
__init__.pyand in the Reference section of the documentation.Generate the documentation locally in order to check that it is working.
If you were working on a secondary branch (which is desirable), do what you have to do: pull request to master, etc.
Ensure that you are now in the master branch.
Update the file
HISTORY.rst. Stick to pure.rstsyntax: never use Sphinx' specific directives such as:class:`MyClass`.In PyCharm's terminal, do one of the following:
bumpversion patch(version x.y.z → x.y.(z+1)) when you made a backwards-compatible modification (such as a bug fix).bumpversion minor(version x.y.z → x.(y+1).0) when you added a functionality.bumpversion major(version x.y.z → (x+1).0.0) when you changed the API. Note: in versions 0.y.z, the API is not expected to be stable anyway.
Commit/push.
Check that the documentation compiles on ReadTheDocs.
On GitHub's website:
Go to “releases”.
Select “Draft a new release”.
Add a tag name (e.g.
v0.1.0) and a message (e.g.First stable version).Select “Publish release”.
After a few minutes, Travis CI has finished the built and it is deployed on PyPI.
If the Deployment on PyPI Fails...
Check that the readme will be correctly rendered on PyPI.
In a terminal:
python setup.py bdist
twine check dist/the_name_of_the_file.zip
where the_name_of_the_file must be replaced by the relevant file name.
Add a Module (= a File)
Typically, this is a file SubPackage\MyClass, containing the class MyClass.
In the file
__init__.py: add the shortcut.In the file
reference.rst: add the auto-documentation.
Use a Third-Party Package
For example, you want to use Numpy in your module.
Open the file
setup.py.In the list
requirements, add the name of the package (e.g.'numpy').
When You Receive a Pull Request from Pyup
You use some third-party packages for the development, such as
sphinx or
pytest. These packages and
their versions are listed in the file
requirements_dev.txt of your package.
Pyup informs you when a new version of these third-party packages is released: you receive a pull request in
GitHub and you just have to accept it.
On GitHub's website:
Open the pull request.
If necessary, wait until Travis CI has finished the build, so that you know there is no problem.
Merge pull request.
Confirm merge.
Delete branch.
In the front page, you Pyup badge should be up-to-date. If not, this is probably just a matter of time. You can go to Pyup's website, click on the gear → reload.
In PyCharm, Menu VCS → Update project.