At 03:58 PM 7/10/2009 +0300, Marius Gedminas wrote:
What do people use to avoid repeating the version number both in the setup.py as well as in application/library code, when the application/library wants to know its own version number?I've seen several options: 1) put __version__ = '4.2' in yourpackage/__init__.py, have setup.py do from yourpackage import __version__ and pass that to setup() 2) put __version__ = '4.2' in yourpackage/__init__.py, have setup.py execfile(os.path.join(os.path.dirname(__file__), 'src', 'yourpackage', '__init__.py'), d), then use d['__version__'] 3) put a file called version.txt in yourpackage/, have setup.py read it, make sure it's included in MANIFEST.in 4) I don't recall actually ever seeing this one, but it should be possible to use pkg_resources to query the version of yourpackage (downside: if you're running from a source checkout without installing, you won't get the right version number)
You'll get the right version number if you use "setup.py develop" to add it to your global sys.path, and/or run "setup.py egg_info" to update the version info whenever it changes.
The simplest formula for retrieving the version in that case is 'pkg_resources.require("Projectname")[0].version'.
_______________________________________________ Distutils-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/distutils-sig
