5

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!

3
  • I don't understand what are you talking about. Some authors use a convention of placing some __version__ variables in the main files of their programs, but this is not an official convention and the interpreter doesn't look at that. There exist some python's package managers and libraries that are used to handle this(e.g. distutils/setuptools). Commented Jun 14, 2013 at 14:33
  • Do i understand you correctly, that you basically want a loader, which checks first if there's a more recent version online and downloads/installs it if so, else it just starts the local version? Commented Jun 14, 2013 at 14:41
  • actually what i want is to make my program able to handle versions, so if in the future i want to install a newer version of my program, it will know what i am talking about. I guess i have to add some line which says "this version is .." so that when i install a new version it can notice it Commented Jun 14, 2013 at 14:55

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

2

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.