0

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:xxxx@gmail.com">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!

debuti
  • 623
  • 2
  • 10
  • 20
  • Yes, you could use requests to get the version number, then compare it with the number in this file and then perform some actions. You could run it in cron to get it executing automatically in intervals. – Peter Sep 30 '15 at 14:52
  • related: [How to remotely update Python applications](http://stackoverflow.com/q/6932389/4279) and [`esky`](https://github.com/cloudmatrix/esky) – jfs Sep 30 '15 at 15:08

2 Answers2

1

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/

postelrich
  • 3,274
  • 5
  • 38
  • 65
1

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.

gerosalesc
  • 2,983
  • 3
  • 27
  • 46