Integrating GitHub with PyPi, Travis-CI, ReadTheDocs, and Code Climate

Integrating GitHub with PyPi, Travis-CI, ReadTheDocs, and Code Climate

After change is pushed into GitHub, Travis is used to build and deploy PyPi package. Generated documentation is readable in PyPi, GitHub, and Read The Docs.

Results

Final results looks like this:

How To Get There

Register and create new repository on GitHub. Register on PyPi and Read The Docs (RTFD). Sign up with GitHub account for Travis-CI and Code Climate.

Selecting Markup Syntax

PyPi requires reStructuredText, RTFD depends on Sphinx which is also using reStructuredText as markup. GitHub also supports reStructuredText, so it’s best to use reStructuredText.

Creating Python Package

First step is to create a python package. Detailed documentation is available here, but in practice it’s sufficient to use some existing setup.py, requirements.txt, and README.rst and modify them. For list of available classifiers for setup.py check following list. LICENSE file you will get for free when you create new repository on GitHub.

Generating Documentation

Now, when you have your initial README.rst file, it’s time to set up documentation generation. Sphinx tutorial describes whole process in details. You need to run: pip install Sphinx and sphinx-quickstart in your package directory. When you answer some questions, you will get conf.py which contains instructions for sphinx/RTFD and Makefile for generating documentation.

You can generate you documentation with make html and see it with chromium-browser _build/html/README.html. Although, it will look completely fine, it will be reported as failed build in RTFD, if you don’t include:

.. toctree::
   :maxdepth: 2

However, if you try to generate documentation in the same way, as it will be generated by PyPi with

python3 setup.py --long-description | rst2html.py > pypi-doc.html

You will get error

<stdin>:11: (ERROR/3) Unknown directive type "toctree".

To avoid this, it’s necessary to preprocess README.rst before it’s used as long description in PyPi documentation. I have achieved that by introducing two special tags – PYPI-BEGIN and PYPI-END which mark section which should be omitted for PyPi. Then setup.py contains following helper function:

def fix_doc(txt):
	return re.sub(r'\.\. PYPI-BEGIN([\r\n]|.)*?PYPI-END', '', txt, re.DOTALL)

with open('README.rst') as fileR:
    README = fix_doc(fileR.read())

...
  long_description=README,

Now, your documentation is updated on RTFD, it’s readable on GitHub and it will also look good on PyPi.
Version, that you have specified in setup.py should match version specified in conf.py.

Deploying to PyPi

It’s great to have automatically generated documentation, but without package itself it’s useless. So, lets create PyPi package. To do that, you can use Travis-CI. They have documentation how to use travis client as well as how to set up travis config to deploy packages on PyPi.

First, you have to install travis client with gem install travis and then you have to create .travis.yml file. You can also use following template.

language: python
python:
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
install: pip install -r requirements.txt
deploy:
  provider: pypi
  user: user_name
  password:
    secure: somelongstring
  on:
    tags: true
    branch: master

To make it work, you have to do few more steps. Login to GitHub with travis client with travis login. You have to use your GitHub credentials in this step. Then you have to change user_name to your user name, that you use on PyPi in .travis.yml. Last step is to run command travis encrypt --add deploy.password and type your password for PyPi. This will modify .travis.yml file. Now it will contain some real value for key secure.

If you password contains some special characters, you should check documentation how to escape them properly.

Based on our configuration, deployment will be executed only when new tag is created, so we have to create one with following commands.

git tag 0.1 -m "Initial commit"
git push --tags origin master

It would be also nice if tag would match version used in setup.py.

Code Climate

Code Climate will analyze your code after each push. Integration with Travis is easy. Generate token and specify it in .travis.yml.

after_sucess:
- CODECLIMATE_REPO_TOKEN=yourtoken codeclimate-test-reporter

Congratulations!!! Now, you have your package available on PyPi.

Deploying New Version

To deploy new version you have to change its number in setup.py and conf.py. After that, you can create new tag and push changes into GitHub repository with

git tag 0.2 -m "New version"
git push --tags origin master

Troubleshooting

Wrong Python Used For Sphinx

I have received this error, when I have on my Ubuntu package python-sphinx which is using Python 2. Solution is to change SPHINXBUILD = python -msphinx to SPHINXBUILD = python3 -msphinx in Makefile.

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/sphinx/__main__.py", line 14, in 
    sys.exit(main(sys.argv))
  File "/usr/lib/python2.7/dist-packages/sphinx/__init__.py", line 51, in main
    sys.exit(build_main(argv))
  File "/usr/lib/python2.7/dist-packages/sphinx/__init__.py", line 61, in build_main
    from sphinx import cmdline
  File "/usr/lib/python2.7/dist-packages/sphinx/cmdline.py", line 14, in 
    import optparse
  File "/usr/lib/python2.7/optparse.py", line 419, in 
    _builtin_cvt = { "int" : (_parse_int, _("integer")),
  File "/usr/lib/python2.7/gettext.py", line 584, in gettext
    return dgettext(_current_domain, message)
  File "/usr/lib/python2.7/gettext.py", line 548, in dgettext
    codeset=_localecodesets.get(domain))
  File "/usr/lib/python2.7/gettext.py", line 483, in translation
    mofiles = find(domain, localedir, languages, all=1)
  File "/usr/lib/python2.7/gettext.py", line 440, in find
    for nelang in _expand_lang(lang):
  File "/usr/lib/python2.7/gettext.py", line 133, in _expand_lang
    from locale import normalize
ImportError: cannot import name normalize
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 5, in 
    from apport.report import Report
  File "/usr/lib/python2.7/dist-packages/apport/report.py", line 12, in 
    import subprocess, tempfile, os.path, re, pwd, grp, os, time
  File "/usr/lib/python2.7/tempfile.py", line 32, in 
    import io as _io
  File "/usr/lib/python2.7/dist-packages/sphinx/io.py", line 11, in 
    from docutils.io import FileInput
  File "/usr/lib/python2.7/dist-packages/docutils/io.py", line 18, in 
    from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
  File "/usr/lib/python2.7/dist-packages/docutils/utils/__init__.py", line 21, in 
    from docutils.utils.error_reporting import ErrorOutput, SafeString
  File "/usr/lib/python2.7/dist-packages/docutils/utils/error_reporting.py", line 47, in 
    locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
AttributeError: 'module' object has no attribute 'getlocale'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/sphinx/__main__.py", line 14, in 
    sys.exit(main(sys.argv))
  File "/usr/lib/python2.7/dist-packages/sphinx/__init__.py", line 51, in main
    sys.exit(build_main(argv))
  File "/usr/lib/python2.7/dist-packages/sphinx/__init__.py", line 61, in build_main
    from sphinx import cmdline
  File "/usr/lib/python2.7/dist-packages/sphinx/cmdline.py", line 14, in 
    import optparse
  File "/usr/lib/python2.7/optparse.py", line 419, in 
    _builtin_cvt = { "int" : (_parse_int, _("integer")),
  File "/usr/lib/python2.7/gettext.py", line 584, in gettext
    return dgettext(_current_domain, message)
  File "/usr/lib/python2.7/gettext.py", line 548, in dgettext
    codeset=_localecodesets.get(domain))
  File "/usr/lib/python2.7/gettext.py", line 483, in translation
    mofiles = find(domain, localedir, languages, all=1)
  File "/usr/lib/python2.7/gettext.py", line 440, in find
    for nelang in _expand_lang(lang):
  File "/usr/lib/python2.7/gettext.py", line 133, in _expand_lang
    from locale import normalize
ImportError: cannot import name normalize
Makefile:23: recipe for target 'html' failed
make: *** [html] Error 1

Travis Permissions

If you are receiving error message user-name has not granted Travis CI the required permissions, please log in via travis-ci.com, it’s caused by using travis login --pro instead of travis login. You should modify all commands to not to use --pro flag.

21 comments

  • Thus it is a problem-solving programme.
    The curriculum is oriented to studying medicine in the
    community using the community as a teaching
    laboratory and learning environment for studying
    medicine, science and engineering (community-based ).

    The curriculum thus has three pillars: student
    centered, community based, and problem
    solving. The working principle of the COBES
    programme is to create awareness in students
    to formulate hypothesis, collect, analyze and
    interpret data, suggest solutions and to
    evaluate methods thereby ultimately providing
    services to the community.
    It is mandatory for all 500level to actively participate in the program, students are
    divided into groups and sent to various communities accross Kwara state to render
    all kinds of technical services to the community that will benefit the occupants of such community.

    All groups must have atleast one students from
    each of engineering department so as to render technical services to the group with respect to his or her department
    when the need arises. I am a mechanical engineering student assigned
    to Idofian community in Ifelodun local government, Kwara state.
    We have taken our time to identify common problems in the community
    and sat to delibrate on long lasting solutions to each of the problems and wrote
    proposal to the university to seek financial grants in other to execute most of the probems.

    This program lasted for two weeks and the following are what we ‘ve
    been able to acheive in just two weeks;
    (1). Rehabilitation of one and only community bus-stop, this will
    enable passangers to relax and stay under shade while waiting for next available bus.

    (2). Most drainages that poses serious threats to roads and residential buildings has
    been cleared and are properly channeled.

    (3). We are enbarked on massive water purification and replacement of damaged taps.

    (4). Major wells were treated to make it safe for
    domestic consumption and most of the damaged taps were replaced
    with new taps.
    (5). Installation of gate arround electric power transformer.

    We are bent on restoring all the road signs, repainting Zebra crossing, covering
    all uncovered wells in the community and installing new signs as the
    need arises.
    (6). We painted Oludofian palace for free to give it a new look.

    Also, resuscitating major street lights accross the community,
    going to various school for career-talks and giving technical advise to the occupants as regards how to maintain the existing amenities,
    the restored and rehabilitated ones.
    I urge all other students that were posted to other communities to attest to this by uploading pictures of community projects that they were able
    to execute during the program.
    Finally, this is one of many ways in which BETTER BY FAR university is contributing to our society, we take the lead in society and human development oriented projects while others follows.

    1 LikeRe: How Unilorin Impact Lives With (cobes) by autofreak2020:7:37am On Oct 11, 2013.

    Re: How Unilorin Impact Lives With (cobes) by ebsuguy(m):8:
    39am On Oct 11, 2013other schools are also involved….delsu and d
    likes of ebsu
    Re: How Unilorin Impact Lives With (cobes) by ruffytosin:10:25am On Feb 07, 2015Better
    by Far all d way!!! Love ma sch like chocolate
    Re: How Unilorin Impact Lives With (cobes) by oyatmicah(m):
    4:50am On Oct 08, 2016i wan book space to talk later, bt as I don read abt dat unilag guy
    wey dem expel cos of bashing, i go just come here come read
    comments
    Re: How Unilorin Impact Lives With (cobes) by oyatmicah(m):4:50am On Oct 08,
    2016i wan book space to talk later, bt as I
    don read abt dat unilag guy wey dem expel cos of bashing,
    i go just come here come read comments.

    (0) (Reply)
    Who Knows About School Of Banking Honours? / Breaking News:
    Jamb Fixes New Deadline For Registration / When U Passed Jamb CBT 2015,
    And U Want To Celebrate! (photo)(Go Up)
    Sections: politics (1) business autos (1) jobs
    (1) career education (1) romance computers phones travel sports fashion health
    religion celebs tv-movies music-radio literature webmasters programming techmarketLinks: (0) (1) (2)
    (3) (4) (5) (6) (7) (8) (9)Nairaland – Copyright © 2005
    – 2017 Oluwaseun Osewa. All rights reserved.
    See How To Advertise.

  • I see you don’t monetize your page, don’t waste your traffic,
    you can earn extra cash every month because
    you’ve got hi quality content. If you want to know how
    to make extra bucks, search for: best adsense alternative Wrastain’s
    tools

  • Someone essentially assist to make critically articles I’d state. That is the first time I frequented your web page and to this point? I surprised with the analysis you made to create this actual submit amazing. Magnificent process!

  • Viagra is undoubtedly an impotence issues substance which you could
    discover in native drugstore suppliers. Certified drug retailer merchants
    normally hold the model viagra. If you don’t just like the considered getting Viagra
    in the actual world, you’ll uncover on-line on-line pharmacy shops the place you may spend money on that.A number
    of well being and well being complement retailers by
    no means have product Viagra. You can not come throughout viagra throughout favourite
    web retailers much like GNC or just Rain forest on-line retailers.
    It’s often provided from public sale internet sites nonetheless, you actually ought to watch out of buying this following that.
    Graphs clear-lower. There are two types of Viagra.

    They’re faux together with preliminary types of this impotence formulation. You’ll have heard of generic viagra, it would be
    the type of that impotence issues system which isn’t coated by the use of trademark.
    You would possibly find various the actual phony sorts throughout public sale internet sites.

    This is the rationale if you probably not check shopping for it by amazon irrespective of how low cost it
    appears.The main Viagra is manufactured by Pfizer. It is very
    favourite a results of the amount of money put into its promotion. Dokter On-line is a web based native
    drugstore retailer which you could possibly choose the Viagra.
    They’ve a number of mgs with Viagra. Yow will discover your fifty five,seventy five mgs etcetera.
    Them markets at cheap costs. Viagra is costed every product in addition to capsule.
    The precise viagra supplied from Dokter On the net doesn’t require doctor’s prescription however it’s a foul thought to make
    use of above Three pills concerning Viagra day by day. In case you get
    the type of Viagra that may want prescription, you won’t
    be suggested greater than Three supplements every day. While you buy your Viagra by the next world huge
    internet drug retailer retail outlet, it’s provided inside a discreet method.
    The lamp that might be employed for product packaging your Viagra could be naked.
    You may neglect will acknowledge this text of your erectile dysfunction capsule you get hold of.

    Dokter on the web is an sincere drugstore retailer. You’ll be able to get hold of viagra supposed
    for low-cost

    Buy Viagra OnlineViagra might be probably the most usually
    invested in medicine on-line and as a result of the event of medicine on-line together with apothecaries it is feasible to buy model title Viagra throughout
    scale back prices. You will get printed Viagra and in addition different Male impotence medications using safe on the web shopping for packages when experiencing total prudence over the shopping for
    along with supply process. A quantity of individuals consider
    that it’s embarrassing to amass Viagra from their drug retailer and even to
    have the ability to require that off their
    medical skilled plus reliable, environment friendly on-line websites may stop the next
    embarrassment coming from blocking shoppers out of receiving the prescription medicine
    which they want.Low cost ViagraViagra will be an excessive priced pharmaceutical if
    it isn’t totally on prescription. Acquiring on-line offers you the possibility pay for an expert site that has full consideration together with safeguarded inserting
    your order whereas selling lowered value ranges upon Viagra and different
    medicinal medicine. Cialis together with Levitra are often fairly common drug therapies that include comparable features to assist Viagra nonetheless they’re supplied by
    decrease costs in addition to for better number of named.DiscretionAmbarassment
    does certainly sadly protect towards a great deal of affected people by getting Viagra options from them physician.
    Viagra allows you to keep away from and even treatment impotence issues which
    regularly can result in psychological points contained in the consumer whom already should endure the precise bodily complications
    linked with erectile dysfunction.Model MedicationWhen you pay
    for Viagra in addition to different medication on the web you need to be no doubt the actual treatment you’ll
    get are the kind of so that you can order.

    Generic remedy include a number of the an identical components however are ordinarily a lot
    inexpensive simply in case it’s important to pay the price of Viagra tablets however be
    given generic drug remedies then this signifies that an individual receiving your present total worth.
    Reliable on the web pharmacists will all the time present top of the range
    medication that you just simply buy.Get hold of Viagra OnlineWhen you purchase Viagra on-line that you’re paid for plenty of
    constructive points which you can undoubtedly
    not love in the true world. You’ll be able to buy on the consolation and likewise solitude
    of ones personal property and have the medicines despatched to your door ensuring full acumen all through the method.

    There’s no have to are stricken with erection dysfunction or some other erection points so you don’t must undergo your embarrassment of buying Viagra from a neighborhood
    drugstore or one other retail outlet.

    American Belief Pharmacy – Purchase Generic Viagra

  • I would like to thnkx for the efforts you’ve put in writing this website. I am hoping the same high-grade blog post from you in the upcoming as well. In fact your creative writing skills has encouraged me to get my own web site now. Really the blogging is spreading its wings rapidly. Your write up is a good example of it.

  • I’d have to check with you here. Which isn’t some thing It’s my job to do! I love reading a post which will get people to believe. Also, appreciate your permitting me to comment!

  • Wonderful blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Cheers

  • In this awesome design of things you’ll secure a B+ for hard work. Exactly where you actually misplaced me ended up being on your specifics. You know, it is said, details make or break the argument.. And it couldn’t be more true at this point. Having said that, let me tell you precisely what did give good results. Your authoring is actually quite convincing and that is most likely why I am making the effort in order to opine. I do not make it a regular habit of doing that. Next, despite the fact that I can see the jumps in reasoning you come up with, I am not necessarily certain of just how you appear to unite your points which in turn make your conclusion. For the moment I will, no doubt subscribe to your issue but wish in the near future you connect your dots better.

  • Thanks so much for giving everyone a very spectacular opportunity to read critical reviews from this site. It is often so sweet and full of a good time for me personally and my office peers to search the blog not less than thrice a week to learn the latest secrets you have. Not to mention, I’m also usually fulfilled for the special opinions you serve. Selected 1 facts in this posting are honestly the most effective I’ve ever had.

  • I have noticed you don’t monetize your site, don’t waste your traffic, you can earn additional bucks every month because you’ve got hi quality
    content. If you want to know how to make extra money, search for:
    Mrdalekjd methods for $$$

  • I have noticed that your blog needs some fresh articles.
    Writing manually takes a lot of time, but there is tool
    for this time consuming task, search for: Wrastain’s tools for content

Trackbacks/Pingbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

ˆ Back To Top