How to add badges in your pypi project

1. pypi badge

To get the pypi badge, go to https://badge.fury.io/for/py page and enter the name of a valid package. Select the code you’d like to insert into your documentation (e.g., RST) and you check get a image like this:

https://badge.fury.io/py/pypiview.svg

2. Number of downloads

Nothing special to do here. Use the link https://crate.io/packages/ and append your package name.

https://pypip.in/d/pypiview/badge.png

3. Continuous integration on Travis

This one is definitely the most difficult but also the most rewarding since you will be able to test your entire software and coverage on different distributions.

First, open an account on https://travis-ci.org/ . It is quite straightforward to synchronise your github with travis. You will see all your repositories and will need to specify those you want to include into the build process. To do so, cick on the repository of your choice in the https://travis-ci.org/profile/username

For a build to start, you will need to commit/push a change in the github and a file in your repository (same level as setup.py and README.rst) called .travis.yml

You can check that the syntax of your file is correct using travis-lint executable.

 travis-lint .travis.yml

This executable can be installed easily using the gem utility:

gem install travis-lint

Here is an example of such as file:

language: python
python:
  - "3.3"
  - "2.7"
  - "2.6"
before_install:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: 
  - pip install .
  - pip install nose coverage
  - pip install coveralls
# # command to run tests, e.g. python setup.py test
script:  
  - python setup.py nosetests --with-coverage --cover-package pypiview
 
after_sucess:
  coveralls

From now one, each time you commit/push a change travis will start a new build. If you do not want to trigger a new build (because you’ve just change a print statement), include this line into your commit statement:

[ci skip]

If you want coverage (next section), you need to use the script and after_sucess sections otherwise just comment or remove them.

Note also that if you use matplotlib in your test, the build may fails with an error related to the DISPLAY. This is the reason for the before_install section and the statement related to the DISPLAY.

Having your first build to pass without errors may take you some time and iterations… Finally, you’ll get a badge as follows

https://secure.travis-ci.org/cokelaer/pypiview.png

4. Coverage

Once you’ve managed to have a succesfuly build on Travis, it is time to look at the coverage. This is very important that the build succeeded otherwise, this step will not work.

Go to https://coveralls.io, create an account and add your github directory. You may need to synchronise your repo.
There, click on an icon called (view on coveralls) on the same line as your pacakge. In the new page, look for the repo token
, which is a list of random character and number. Keep it for later.

You will need to trigger travis CI by committed some changes.

this should then trigger the coveralls website where the badge should now be ready.

THere is another way, which is more manual; I did not manage but instructions are See https://github.com/coagulant/coveralls-python for help.

The final badge looks like:

https://coveralls.io/repos/cokelaer/pypiview/badge.png?branch=master

Quality

an easy one now. Get a badge for the quality of your code (style) by joining landscape website https://landscape.io

add the repository you wish to test going to the bottom of this page

https://landscape.io/repository/add

https://landscape.io/github/cokelaer/pypiview/master/landscape.png

Tasks

Another easy one is the task badge from waffle. Open an account and then go to

https://waffle.io/cokelaer/PROJECT

https://badge.waffle.io/cokelaer/pypiview.png?label=ready&title=Ready

Update pypi

Finally, you need to update your README.rst , which should be in your github repository with the following code (adapted to your needs of course)

.. image:: https://badge.fury.io/py/PROJECT.svg
    :target: https://badge.fury.io/py/PROJECT.svg
 
.. image:: https://pypip.in/d/PROJECT/badge.png
    :target: https://crate.io/packages/PROJECT/
 
.. image:: https://secure.travis-ci.org/USERNAME/PROJECT.png
    :target: http://travis-ci.org/USENAME/PROJECT
 
.. image:: https://coveralls.io/repos/USERNAME/PROJECT/badge.png?branch=master 
    :target: https://coveralls.io/r/USERNAME/PROJECT?branch=master 
 
.. image:: https://landscape.io/github/USERNAME/PROJECT/master/landscape.png
   :target: https://landscape.io/github/USERNAME/PROJECT/master
 
.. image:: https://badge.waffle.io/USERNAME/PROJETC.png?label=ready&title=Ready 
   :target: https://waffle.io/USERNAME/PROJECT
Please follow and like us:
This entry was posted in Python. Bookmark the permalink.

3 Responses to How to add badges in your pypi project

  1. Jerry Lee says:

    Cool~ list the terrific tools for github project!

  2. boardtc says:

    Should be categorized as Python

Leave a Reply

Your email address will not be published.