debuti
debuti

Reputation: 683

Python auto updater from github

I would like to know if any of you had implemented an autoupdate feature for a python app. My idea is to download the first 100-200 bytes (using requests?) from a github URL, contanining the version tag. Ex.

#!/usr/bin/env python
#######################
__author__ = '<a href="mailto:[email protected]">xxx</a>'
__program__ = 'theprogram'
__package__ = ''
__description__ = '''This program does things'''
__version__ = '0.0.0'
...

So if the version tag is greater than the one in the local module, the updater would download the whole file and replace it, and then (either the way) run it.

What is the best way to do this?

Thanks!

Upvotes: 0

Views: 5598

Answers (2)

gerosalesc
gerosalesc

Reputation: 3063

You can use pip programmatically to schedule updates for your modules in a cron, so you won't be needing to request the version because pip will update only when necessary.

pip install --upgrade yourpackage

or

pip install --upgrade git+https://github.com/youracc/yourepo.git

Also, as @riotburn pointed out, you should be using a virtualenv to isolate your environment and may as well rollback to a previous one if necessary. In that last scenario, you may find this virtualenv wrapper very helpful.

Upvotes: 1

postelrich
postelrich

Reputation: 3496

You should look into using virtualenv or conda for managing the dependencies used in your package. Both allow you to create isolated environments for installing specific versions of packages as well as creating environments from predefined list of dependencies. Conda also has the benefit of being a package manager like pip. If you were to not specify versions in this requirements file, it would install the latest. Then you could just write a bash script to automate the couple of command lines needed to do this for your use case.

Try reading up on python environments:

http://conda.pydata.org/docs/using/envs.html
https://virtualenv.pypa.io/en/latest/

Upvotes: 1

Related Questions