Proposed patch: allowing unknown keywords
I'd like to check in the following patch; it causes unknown keywords in the setup() invocation to trigger a warning instead of an exception. This will make it possible to add more metadata arguments to setup() in future versions while still letting packages be installed with Distutils versions lacking the added arguments. Any objections? Should it be backported to Python 2.2? --amk Index: dist.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/dist.py,v retrieving revision 1.56 diff -u -u -r1.56 dist.py --- dist.py 11 Sep 2002 16:31:52 -0000 1.56 +++ dist.py 31 Oct 2002 00:24:55 -0000 @@ -9,7 +9,7 @@ __revision__ = "$Id: dist.py,v 1.56 2002/09/11 16:31:52 jhylton Exp $" -import sys, os, string, re +import sys, os, string, re, warnings from types import * from copy import copy from distutils.errors import * @@ -206,8 +206,7 @@ elif hasattr(self, key): setattr(self, key, val) else: - raise DistutilsSetupError, \ - "invalid distribution option '%s'" % key + warnings.warn("Unknown distribution option: %r" % key) self.finalize_options()
[A.M. Kuchling]
I'd like to check in the following patch; it causes unknown keywords in the setup() invocation to trigger a warning instead of an exception. This will make it possible to add more metadata arguments to setup() in future versions while still letting packages be installed with Distutils versions lacking the added arguments.
+1. Fine idea! The only caution is that a package may *need* those "future options" to install correctly -- but then that's up to the package's authoer to keep straight.
Any objections? Should it be backported to Python 2.2?
I think so -- looks like the 2.2 line will be around for a long time.
On Wed, 30 Oct 2002 21:42:47 -0500, Tim Peters wrote:
+1. Fine idea! The only caution is that a package may *need* those "future options" to install correctly -- but then that's up to the package's authoer to keep straight.
To make that last task easier, can we also add a distutils.dist.Distribution.getSupportedOptions() -> list of strings method? That would make the check read like so: from distutils.dist import Distribution assert hasattr(Distribution, "getSupportedOptions") assert "foo" in Distribution.getSupportedOptions() Ciao, Jürgen -- Jürgen Hermann, Developer WEB.DE AG, http://webde-ag.de/
On Thu, Oct 31, 2002 at 10:24:41AM +0200, Juergen Hermann wrote:
from distutils.dist import Distribution assert hasattr(Distribution, "getSupportedOptions") assert "foo" in Distribution.getSupportedOptions()
Distutils uses underscores, so that would be get_supported_options(), but it seems like a reasonable idea. Should I write a micro-PEP about this, or is this addition too trivial? Incidentally, the change's use of warnings.warn() means that it will only work in Python 2.1 or later. For earlier versions, it could just print a message to stderr. There seems little reason to break 1.5.2/2.0 compatibility for this one little thing. --amk
On Thu, Oct 31, 2002 at 10:24:41AM +0200, Juergen Hermann wrote:
from distutils.dist import Distribution assert hasattr(Distribution, "getSupportedOptions") assert "foo" in Distribution.getSupportedOptions()
Now that I look at, why would this be a method on Distribution? Are the options dependent on the Distribution instance, or on the version of Distutils installed? If the latter, then it should probably be a function in distutils/core.py. Given that many people write 'from distutils.core import *', maybe the function should be named get_distutil_options() to make its origin clearer. Here's a proposed docstring for core.py. There aren't any options to record yet, so the returned list is empty. Anyone see problems with this? def get_distutil_options (): """Returns a list of strings recording changes to the Distutils. setup.py files can then do: if 'optional-thing' in get_distutil_options(): ... """ return [] --amk
On Thu, 31 Oct 2002 14:38:45 -0500, A.M. Kuchling wrote:
On Thu, Oct 31, 2002 at 10:24:41AM +0200, Juergen Hermann wrote:
from distutils.dist import Distribution assert hasattr(Distribution, "getSupportedOptions") assert "foo" in Distribution.getSupportedOptions()
Now that I look at, why would this be a method on Distribution?
Because that is the class the setup attributes are finally handed into. Of course, a function in core.py is ok, too. Whether the list should initially be empty or contain the currently handled attributes is a point too (but I have no real preference). Ciao, Jürgen -- Jürgen Hermann, Developer WEB.DE AG, http://webde-ag.de/
A.M. Kuchling wrote:
I'd like to check in the following patch; it causes unknown keywords in the setup() invocation to trigger a warning instead of an exception. This will make it possible to add more metadata arguments to setup() in future versions while still letting packages be installed with Distutils versions lacking the added arguments.
Any objections? Should it be backported to Python 2.2?
No and yes :-)
--amk
Index: dist.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/dist.py,v retrieving revision 1.56 diff -u -u -r1.56 dist.py --- dist.py 11 Sep 2002 16:31:52 -0000 1.56 +++ dist.py 31 Oct 2002 00:24:55 -0000 @@ -9,7 +9,7 @@
__revision__ = "$Id: dist.py,v 1.56 2002/09/11 16:31:52 jhylton Exp $"
-import sys, os, string, re +import sys, os, string, re, warnings from types import * from copy import copy from distutils.errors import * @@ -206,8 +206,7 @@ elif hasattr(self, key): setattr(self, key, val) else: - raise DistutilsSetupError, \ - "invalid distribution option '%s'" % key + warnings.warn("Unknown distribution option: %r" % key)
self.finalize_options()
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Marc-Andre Lemburg CEO eGenix.com Software GmbH _______________________________________________________________________ eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/
On Thu, 31 Oct 2002 12:40 pm, A.M. Kuchling wrote:
I'd like to check in the following patch; it causes unknown keywords in the setup() invocation to trigger a warning instead of an exception. This will make it possible to add more metadata arguments to setup() in future versions while still letting packages be installed with Distutils versions lacking the added arguments.
Any objections? Should it be backported to Python 2.2?
No objections, yes to 2.2 please :) Richard
participants (5)
-
A.M. Kuchling
-
Juergen Hermann
-
M.-A. Lemburg
-
Richard Jones
-
Tim Peters