[Distutils] Distutils 1.0.1 releasee
Bastian Kleineidam
calvin@cs.uni-sb.de
Wed Nov 8 08:54:01 2000
Hi all,
Im Jahre 2000 schrieb Greg Ward:
> but I don't think the two should be confused.
Yes, I agree.
>all we can do for run-time configuration is promote a standard place for
>Python applications to install and find such config data, whereas we can
>specify everything about build-time config data. So which are you
>talking about here?
I am talking about both, but lets have a look my source:
class MyDistribution(Distribution):
def __init__(self, attrs=None):
Distribution.__init__(self, attrs=attrs)
self.config_file = self.get_name()+"Conf.py"
def create_conf_file(self, directory, data=[]):
"""generate a configuration file with all metadata the data
supplied in the 'data' argument"""
data.insert(0, "# this file is automatically created by setup.py")
filename = os.path.join(directory, self.config_file)
# add metadata
metanames = dir(self.metadata) + \
['fullname', 'contact', 'contact_email']
for name in metanames:
method = "get_" + name
cmd = "%s = %s" % (name, `getattr(self.metadata, method)()`)
data.append(cmd)
util.execute(write_file, (filename, data),
"creating %s" % filename, self.verbose>=1,self.dry_run)
So create_conf_file generates a file <package>Conf.py. You can call the
function from any place in your code (or you can call it never).
I call in two places:
1) If I need to store some configuration values, my custom
"config" command creates this file with the config values in the
'data' list.
2) When installing. This way the <package>Conf.py is installed as a
module and my program has runtime information by importing the module.
I think this approach is nice because you can have both configuration and
runtime information stored in the file. Furthermore the patch is just
adding a function so it does not break any existing apps.
Bastian