Is there a way that when a user types
python setup.py install
to i开发者_开发百科nstall a Python package, setup.py
can be made to set specific variables at the base of the pacakge? A common example would be to basically set mypackage.__revision__
to be the svn revision of the checkout if one is working from svn. Another example case would be if the user can choose a global option, so that the option mypackage.__option__
be set according to a flag passed to setup.py, e.g.
python setup.py install --set-flag=10
Then when using the package, mypackage.__option__
would equal 10
.
The SVN version can be set by SVN. You don't need to use setup.py to mess with that.
Simply include the $Revision$
flag in the text somewhere and tell SVN to do replacements.
Global options are usually handled by configuration files. Why mess with it at install time? It's much easier (and more flexible) to create and read a configuration file.
You could, for example, install a configuration file with instructions on how to edit it. If the configuration file is in Python, then it's simply a variable in the configuration.
THEOPTION = 10
That would be enough. Very simple. Very standardized. Very easy to manage.
精彩评论