Permalink
Browse files

Introduced configuration kw argument to setup. This fixes long lasted…

… long configuration messages when setup command line has only help request or errors.
  • Loading branch information...
1 parent da78766 commit 471196b6dfc3f45decc18dc34e044842e5fa2c21 @pearu pearu committed Mar 31, 2006
Showing with 102 additions and 72 deletions.
  1. +66 −0 numpy/distutils/core.py
  2. +0 −44 numpy/distutils/misc_util.py
  3. +36 −28 setup.py
View
@@ -47,6 +47,45 @@
numpy_cmdclass['easy_install'] = easy_install.easy_install
numpy_cmdclass['egg_info'] = egg_info.egg_info
+def _dict_append(d, **kws):
+ for k,v in kws.items():
+ if not d.has_key(k):
+ d[k] = v
+ continue
+ dv = d[k]
+ if isinstance(dv, tuple):
+ dv += tuple(v)
+ continue
+ if isinstance(dv, list):
+ dv += list(v)
+ continue
+ if isinstance(dv, dict):
+ _dict_append(dv, **v)
+ continue
+ if isinstance(dv, str):
+ assert isinstance(v,str),`type(v)`
+ d[k] = v
+ raise TypeError,`type(dv)`
+ return
+
+def _command_line_ok(_cache=[]):
+ """ Return True if command line does not contain any
+ help or display requests.
+ """
+ if _cache:
+ return _cache[0]
+ ok = True
+ display_opts = ['--'+n for n in Distribution.display_option_names]
+ for o in Distribution.display_options:
+ if o[1]:
+ display_opts.append('-'+o[1])
+ for arg in sys.argv:
+ if arg.startswith('--help') or arg=='-h' or arg in display_opts:
+ ok = False
+ break
+ _cache.append(ok)
+ return ok
+
def setup(**attr):
cmdclass = numpy_cmdclass.copy()
@@ -56,6 +95,33 @@ def setup(**attr):
cmdclass.update(new_attr['cmdclass'])
new_attr['cmdclass'] = cmdclass
+ if new_attr.has_key('configuration'):
+ # To avoid calling configuration if there are any errors
+ # or help request in command in the line.
+ configuration = new_attr.pop('configuration')
+
+ import distutils.core
+ old_dist = distutils.core._setup_distribution
+ old_stop = distutils.core._setup_stop_after
+ distutils.core._setup_distribution = None
+ distutils.core._setup_stop_after = "commandline"
+ try:
+ dist = setup(**new_attr)
+ distutils.core._setup_distribution = old_dist
+ distutils.core._setup_stop_after = old_stop
+ except Exception,msg:
+ distutils.core._setup_distribution = old_dist
+ distutils.core._setup_stop_after = old_stop
+ raise msg
+ if dist.help or not _command_line_ok():
+ # probably displayed help, skip running any commands
+ return dist
+
+ # create setup dictionary and append to new_attr
+ config = configuration()
+ if hasattr(config,'todict'): config = config.todict()
+ _dict_append(new_attr, **config)
+
# Move extension source libraries to libraries
libraries = []
for ext in new_attr.get('ext_modules',[]):
@@ -1252,50 +1252,6 @@ def get_info(self,*names):
dict_append(info_dict,**get_info(a))
return info_dict
-class BadConfiguration(Configuration):
- """
- When the command line is not ok, use this as the configuration class.
- """
- def _do_nothing(self, *args, **kw):
- pass
- add_subpackage = _do_nothing
- add_extension = _do_nothing
- add_library = _do_nothing
- add_data_dir = _do_nothing
- add_data_files = _do_nothing
- add_scripts = _do_nothing
- add_headers = _do_nothing
- add_include_dirs = _do_nothing
- make_config_py = _do_nothing
-
- def get_info(self, *args, **kw):
- return {}
- def have_f77c(self, *args, **kw):
- return False
- def have_f90c(self, *args, **kw):
- return False
-
-def command_line_ok(_cache=[]):
- """ Return True if command line does not contain any
- help or display requests.
- """
- if _cache:
- return _cache[0]
- ok = True
- from distutils.dist import Distribution
- display_opts = ['--'+n for n in Distribution.display_option_names]
- for o in Distribution.display_options:
- if o[1]:
- display_opts.append('-'+o[1])
- for arg in sys.argv:
- if arg.startswith('--help') or arg=='-h' or arg in display_opts:
- ok = False
- break
- _cache.append(ok)
- return ok
-
-if not command_line_ok():
- Configuration = BadConfiguration
def get_cmd(cmdname, _cache={}):
if not _cache.has_key(cmdname):
View
@@ -31,46 +31,54 @@
Operating System :: MacOS
"""
+def configuration(parent_package='',top_path=None):
+ from numpy.distutils.misc_util import Configuration
+
+ config = Configuration(None, parent_package, top_path,
+ maintainer = "NumPy Developers",
+ maintainer_email = "numpy-discussion@lists.sourceforge.net",
+ description = DOCLINES[0],
+ long_description = "\n".join(DOCLINES[2:]),
+ url = "http://numeric.scipy.org",
+ download_url = "http://sourceforge.net/projects/numpy",
+ license = 'BSD',
+ classifiers=filter(None, CLASSIFIERS.split('\n')),
+ author = "Travis E. Oliphant, et.al.",
+ author_email = "oliphant@ee.byu.edu",
+ platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
+ )
+ config.set_options(ignore_setup_xxx_py=True,
+ assume_default_configuration=True,
+ delegate_options_to_subpackages=True,
+ quiet=True)
+
+ config.add_subpackage('numpy')
+
+
+ config.name = 'numpy'
+ #config.dict_append(version=version)
+ #print config.name,'version',config.version
+
+ config.add_data_files(('numpy',['*.txt','COMPATIBILITY',
+ 'scipy_compatibility']))
+
+ return config
+
def setup_package():
from numpy.distutils.core import setup
- from numpy.distutils.misc_util import Configuration
old_path = os.getcwd()
local_path = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir(local_path)
sys.path.insert(0,local_path)
try:
- config = Configuration(
- maintainer = "NumPy Developers",
- maintainer_email = "numpy-discussion@lists.sourceforge.net",
- description = DOCLINES[0],
- long_description = "\n".join(DOCLINES[2:]),
- url = "http://numeric.scipy.org",
- download_url = "http://sourceforge.net/projects/numpy",
- license = 'BSD',
- classifiers=filter(None, CLASSIFIERS.split('\n')),
- author = "Travis E. Oliphant, et.al.",
- author_email = "oliphant@ee.byu.edu",
- platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
- )
- config.set_options(ignore_setup_xxx_py=True,
- assume_default_configuration=True,
- delegate_options_to_subpackages=True,
- quiet=True)
-
- config.add_subpackage('numpy')
from numpy.version import version
- config.name = 'numpy'
- config.dict_append(version=version)
- #print config.name,'version',config.version
-
- config.add_data_files(('numpy',['*.txt','COMPATIBILITY',
- 'scipy_compatibility']))
-
- setup( **config.todict() )
+ setup( configuration=configuration,
+ version = version
+ )
finally:
del sys.path[0]
os.chdir(old_path)

0 comments on commit 471196b

Please sign in to comment.