3

How can I import or read the VERSION from the setup.py file so that I can log the version at runtime. This way I can make sure that the results obtained are from this particular version of my package.

The following is the contents of my setup.py file (simplified to have the necessary part)

import distutils.core
VERSION = '0.1.0'
LICENSE = 'GPLv2'
distutils.core.setup(**KWARGS)

When I try to do : import setup I get the following error:

distutils.core.setup(**KWARGS)
usr/lib/python2.6/distutils/core.pyc in setup(**attrs)
        ok = dist.parse_command_line()
    except DistutilsArgError, msg:
        raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg

    if DEBUG:

SystemExit: 

error: no commands supplied

2 Answers 2

4

There is a way to get the version from your setup script:

python setup.py --version

But I’m not sure I understand what you mean with “log the version at runtime”; the setup script is normally not installed with your modules, so people use other ways to put a version number in their code, like a __version__ attribute in their module or __init__.py file.

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

Comments

0

In yor example, setup is excecuted automatically, you have to replace:

distutils.core.setup(**KWARGS)

with:

if __name__ == '__main__':
    distutils.core.setup(**KWARGS)

Like this, setup is only executed if you actually run the setup.py

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.