Pypi-publisher: a simple cli for publishing python libraries
I’ve just finished the first release of pypi-publisher (ppp), a library for simple command line publishing of python libraries. You can grab the source or an install here:
https://github.com/wdm0006/pypi-publisher
In previous posts, I’ve shown how with a cookiecutter framework and some fast typing, you can release a package to pypi in pretty much no time at all. In it’s current state, ppp can cut down on that slightly. But as it grows to support more distribution types and more robust linting it will really cut down on the boring parts of releasing python code. Today it handles 4 main tasks:
- Update the .pypi file with potentially new servers or information
- Lint the candidate repository to make sure nothing critical is missing
- Create and push a tag to git for the release
- Register and publish the repository to a pypi server
The first release targets support for sdist (source distributions), but later releases will support wheels and other packaging options.
To install use pip:
pip install pypi-publisher
Then to use just:
ppp publish [-options]
Available options are:
-u/--username
-p/--password
-i/--index-url
-s/--server-name
-d/--dry-run
-v/--verbose
-t/--create-tag
To go into a little more detail of those 4 tasks mentioned above:
Updating .pypi file
If you already have a .pypi file at ~ on the box, then you can just pass -s to reference a server in that. If you pass -s and -u, -p, and/or -i for a server that is in the file already, the parameters passed will be upserted into that file. If you pass -s, -u, -p, and -i for a server that is not in the file, it will be inserted as a new server.
A few examples:
ppp publish -s=foo
To update some values (username and index url) for an existing server:
ppp publish -s=foo -u=bar -i=baz
To create a whole new server in the file:
ppp publish -s=foo -u=bar -p=baz -i=bat
Linting the candidate repository
Currently, the linting is very basic, and is just checking that a few files actually exist (manifest.in, setup.py and setup.cfg). This happens in all runs, regardless of flags passed.
Pushing a tag to git
If you pass the -t flag, ppp will try to find the version number in the setup.py file and push a tag with the version to git. The search looks for any line (case insensitive) that starts with version or version, and takes it’s value, so:
__version__ = '1.0.0'
or
VERSION = '1.0.0'
Would both work perfectly. It’s worth noting that if you push tags on the initial publishing to a test server, you won’t need to push the same tag again for the following publishing to the prod server.
Publishing the repository
Currently, this only supports sdist uploads, in the future we plan to add more sophisticated packaging functionality, like wheels.
Contributing and Issues
If you’d like to help development or have any feedback, let me know, and if you run into any issues with ppp please open up a ticket on github and I’ll look into it.
Subscribe to the Newsletter
Get the latest posts and insights delivered straight to your inbox.