[Distutils] [setuptools] How to maintain version strings?
Phillip J. Eby
pje at telecommunity.com
Sun Dec 18 17:33:34 CET 2005
At 02:47 PM 12/18/2005 +0000, John J Lee wrote:
>I also want to avoid importing code from setup.py, because people
>sometimes want to install using a Python executable other than the one
>with which they intend to import the package (I assume that's sensible &
>possible with setuptools packages), and imports in setup.py have broken
>that in the past.
It's also a big problem if you have dependencies that you import;
setuptools doesn't install your dependencies until after the setup script
has effectively run to completion, so you might be trying to import stuff
that's not yet installed.
>Seems I can't just open('mymodule.py') and find the version string with a
>regexp, I assume because of setuptools' "sandbox".
I don't see why not; the sandbox should only restrict *writing* to files,
not reading them, and in any case it only restricts writing *outside* the
subdirectory tree where the setup script is located.
>Anybody have a way of doing this (or a slap to my forehead to teach me the
>simple way to do it ;-)?
The 'networkx' project on PyPI does this by having a 'release.py' inside
the main package that contains all the variables that need to be shared
between the package and the setup script. The setup script uses
execfile('packagename/release.py') to obtain the variables, while the
package does a 'from release import *'. Thus, the variables are in a
single file.
I use a slightly different technique myself; PEAK includes a tool called
'version' that can automatically edit a variety of files and update the
included version numbers in a variety of user-defined formats. When I bump
setuptools alpha versions, I just run "version incr build" to bump the
micro number. When I move from say, 0.6 to 0.7, I run "version incr
minor". Anyway, it basically works by having a configuration file
describing what to search for and edit in each file that contains the
version number, as well as what parts there are in my versioning scheme and
the different formats for "spelling" that versioning scheme. The
configuration file itself has a "#!peak version-config" line that makes it
executable, so I just run it to update my release scripts, setup.py,
__version__ variables, etc.
I believe there is at least one other tool out there that does something
similar on SourceForge, but I don't remember its name.
More information about the Distutils-SIG
mailing list