Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to version a Python program

Tags:

python

version

I'm doing a Python program (for use in a Linux environment) and I want it to support version actualizations of the program. I read somewhere I should add a line like "__ Version __" but I'm not really sure where and how to put it. What I want to achieve is not having to erase my whole program every time I want to install a new version of it. thanks!

like image 526
Malice Avatar asked Jun 14 '13 14:06

Malice


4 Answers

I highly recommend you to use setuptools instead of manually versioning it. It is the de-facto stanrad now and very simple to use. All you need to do is to create a setup.py in your projects root directory:

from setuptools import setup, find_packages

setup(name='your_programms_name',
      version='major.minor.patch',
      packages=find_packages(),
)

and then just run:

python setup.py sdist

and then there will be eggs under your dist folder.

like image 98
ambodi Avatar answered Oct 10 '22 05:10

ambodi


What you actually want to do is make your Python program into a package using distutils.

You would create a setup.py. A simple example would look something like this:

from distutils.core import setup
setup(name='foo',
      version='1.0',
      py_modules=['foo'],
)

This is the most standard way to version and distribute Python code. If your code is open source you can even register it with the cheese shop^M^M^M^MPyPi and install it on any machine in the world with a simple pip install mypackage.

like image 23
aychedee Avatar answered Oct 10 '22 04:10

aychedee


It depends what you want to be versioned.

Single modules with independent versions, or the whole program/package.

You could theoretically add a __version__ string to every class and do dynamic imports, by testing these variables.

If you want to version the main, or whole program you could add a __version__ string somewhere at the top of your __init__.py file and import this string into you setup.py when generating packages. This way you wouldn't have to manually edit multiple files and setup.py could be left mostly untouched.

Also consider using a string, not a number or tuple. See PEP 396.

like image 24
Don Question Avatar answered Oct 10 '22 04:10

Don Question


If you are only concerned with versions on your local machine, I would suggest becoming familiar with Git. Information about version control in Git can be found here.

If you are concerned with version control on a module that others would use, information can be found here.

like image 1
Tim Morrill Avatar answered Oct 10 '22 06:10

Tim Morrill