[Python-checkins] distutils2: now you can register your custom compilers using the .cfg files

tarek.ziade python-checkins at python.org
Thu Nov 11 22:18:10 CET 2010


tarek.ziade pushed fa383ca473a0 to distutils2:

http://hg.python.org/distutils2/rev/fa383ca473a0
changeset:   810:fa383ca473a0
tag:         tip
user:        Tarek Ziade <tarek at ziade.org>
date:        Thu Nov 11 22:17:50 2010 +0100
summary:     now you can register your custom compilers using the .cfg files
files:       distutils2/compiler/__init__.py, distutils2/config.py, distutils2/tests/test_config.py, docs/source/index.rst

diff --git a/distutils2/compiler/__init__.py b/distutils2/compiler/__init__.py
--- a/distutils2/compiler/__init__.py
+++ b/distutils2/compiler/__init__.py
@@ -111,6 +111,12 @@
               'mingw32': 'distutils2.compiler.cygwinccompiler.Mingw32CCompiler',
               'bcpp': 'distutils2.compilers.bcppcompiler.BCPPCompiler'}
 
+
+def set_compiler(name, location):
+    """Add or change a compiler"""
+    _COMPILERS[name] = location
+
+
 def show_compilers():
     """Print list of available compilers (used by the "--help-compiler"
     options to "build", "build_ext", "build_clib").
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -8,6 +8,7 @@
 
 from distutils2 import logger
 from distutils2.util import check_environ, resolve_name
+from distutils2.compiler import set_compiler
 
 
 class Config(object):
@@ -194,6 +195,10 @@
                 self._read_setup_cfg(parser)
 
             for section in parser.sections():
+                if section == 'compilers':
+                    self._load_compilers(parser.items(section))
+                    continue
+
                 options = parser.options(section)
                 opt_dict = self.dist.get_option_dict(section)
 
@@ -240,3 +245,7 @@
                         setattr(self.dist, opt, val)
                 except ValueError, msg:
                     raise DistutilsOptionError(msg)
+
+    def _load_compilers(self, compilers):
+        for name, location in compilers:
+            set_compiler(name, location)
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -80,9 +80,19 @@
 
 [install_dist]
 sub_commands = foo
+
+[compilers]
+d = distutils2.tests.test_config.DCompiler
 """
 
 
+class DCompiler(object):
+    compiler_type = 'd'
+    description = 'D Compiler'
+
+    def __init__(self, *args):
+        pass
+
 def hook(content):
     content['metadata']['version'] += '.dev1'
 
@@ -179,6 +189,12 @@
         # did the README got loaded ?
         self.assertEquals(dist.metadata['description'], 'yeah')
 
+        # do we have the D Compiler enabled ?
+        from distutils2.compiler import new_compiler, _COMPILERS
+        self.assertIn('d', _COMPILERS)
+        d = new_compiler(compiler='d')
+        self.assertEqual(d.description, 'D Compiler')
+
     def test_sub_commands(self):
         tempdir = self.mkdtemp()
         os.chdir(tempdir)
diff --git a/docs/source/index.rst b/docs/source/index.rst
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -48,6 +48,9 @@
   A guide for for end-users wanting to install a Python application or
   library.
 
+:doc:`setupcfg`
+  Specifications of setup.cfg, the most important file for developers.
+
 :doc:`tutorial`
   A tutorial for Python developers to discover Distutils2 main features.
 
@@ -68,6 +71,7 @@
 
    devresources
    install/index
+   setupcfg
    tutorial
    distutils/index
    library/distutils2

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list