There are a lot of instructions online on how to do this, but many of them are out-of-date or outright not working.
In addition to 2–5 minutes of your time, the things you’re going to need:
- a Github (or similar) repo with a python package
- Travis command line tools
- Twine (included in the instructions)
- A working PyPi account login/password
1. Encrypt your PyPi password to be included in the Travis file.
Note that I’m assuming you already have Travis command line tool installed. If you don’t, do it now.
First go to the folder where the package you want to deploy is located. Then continue by typing to your command line:
This will get you where you need to key in or paste your PyPi password. Next you will have to Ctrl-D to complete the process. Before this you will be prompted to confirm the package name based on the folder you are in.
2. Check that your travis.yml file is updated
The previous step should handle modifying the travis.yml file of your repo. Make sure that’s the case. At the end of the file you should have something like this:
With this configuration, whenever the branch ‘production’ is updated, as part of the Travis operations, the package will be deployed to PyPi. Before we can use this, we have to submit the package to PyPi for the first time separately.
3. Submit the package to PyPi (once) the manual way
It looks like the officially recommended version is to use twine. So first
Your package needs to be a proper Python package complete with setup.py and setup.cfg files. With these in place, assuming you are inside the package directory run:
At this point it’s a good idea to run local tests once more to make sure that everything works. Once you’re ready, you can then upload the package to PyPi:
(never mind the underlining on the url).
That’s it, you’re done. You should now see your package in:
https://pypi.org/project/your_package/
From now on you can just use the automated Travis build sequence approach.