[Distutils] What about an info command?
Bastian Kleineidam
calvin@cs.uni-sb.de
Fri, 7 Apr 2000 03:08:04 +0200 (CEST)
Hello,
I'd like to extract some information stored in setup.py, namely
the package version.
A way to provide this is an "info" command. So you can have:
./setup.py info [--version,--name,--url,--author,...]
Heres a patch. It prints the infos in a specific order (as specified
in user_options), each on its own line.
It even prints if you specify -q. You should specify -q because then you
get rid of the "running info" line.
So as a result "python setup.py -q info --version" prints exactly the
package version, nothing more, nothing less.
Bastian Kleineidam
diff -c -r --ignore-all-space --exclude=*.pyc -N distutils.orig/distutils/command/__init__.py distutils.patched/distutils/command/__init__.py
*** distutils.orig/distutils/command/__init__.py Fri Mar 31 12:16:06 2000
--- distutils.patched/distutils/command/__init__.py Fri Apr 7 02:40:42 2000
***************
*** 12,17 ****
--- 12,18 ----
'install',
'install_lib',
'clean',
+ 'info',
'sdist',
'bdist',
'bdist_dumb',
diff -c -r --ignore-all-space --exclude=*.pyc -N distutils.orig/distutils/command/info.py distutils.patched/distutils/command/info.py
*** distutils.orig/distutils/command/info.py Thu Jan 1 01:00:00 1970
--- distutils.patched/distutils/command/info.py Fri Apr 7 03:02:39 2000
***************
*** 0 ****
--- 1,30 ----
+ """distutils.command.info
+
+ Implements the Distutils 'info' command."""
+
+ from distutils.core import Command
+
+ class info (Command):
+
+ description = "print infos stored in setup.py"
+ user_options = [
+ ('version', 'V', "print version"),
+ ('author', None, "print author"),
+ ('author-email', None, "print the authors email"),
+ ('description', None, "print description"),
+ ('url', None, "print url"),
+ # more if needed...
+ ]
+
+ def initialize_options(self):
+ for arg in map(lambda x: x[0], self.user_options):
+ # do not set to None: see Command.__getattr__
+ setattr(self, arg, 0)
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ for arg in map(lambda x: x[0], self.user_options):
+ if getattr(self, arg):
+ print getattr(self.distribution, arg)