[PATCH] Make setup usable on systems missing cygwin compiler package

Ludovic Chabant ludovic at chabant.com
Wed Dec 24 04:04:51 UTC 2014


# HG changeset patch
# User Ludovic Chabant <ludovic at chabant.com>
# Date 1419393288 28800
#      Tue Dec 23 19:54:48 2014 -0800
# Node ID a2257105e7ec58fa47d29c4a24e17ed2ad2adefd
# Parent  67d63ec85eb72187508692e52f14be46101707a5
setup: don't fail when Python doesn't have the cygwinccompiler package

Some Python installations like the ones available from the optware
project
for the Synology DiskStation NASes don't have that package, which means
running the setup script will crash and exit right away. Instead, we now
just use an empty/fake class for the HackedMingw32CCompiler, which we
likely won't use anyway.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -76,7 +76,7 @@
 from distutils.command.install_lib import install_lib
 from distutils.command.install_scripts import install_scripts
 from distutils.spawn import spawn, find_executable
-from distutils import cygwinccompiler, file_util
+from distutils import file_util
 from distutils.errors import CCompilerError, DistutilsExecError
 from distutils.sysconfig import get_python_inc, get_config_var
 from distutils.version import StrictVersion
@@ -509,19 +509,28 @@
                                 extra_link_args=osutil_ldflags,
                                 depends=common_depends))
 
-# the -mno-cygwin option has been deprecated for years
-Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler
+try:
+    from distutils import cygwinccompiler
 
-class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler):
-    def __init__(self, *args, **kwargs):
-        Mingw32CCompiler.__init__(self, *args, **kwargs)
-        for i in 'compiler compiler_so linker_exe linker_so'.split():
-            try:
-                getattr(self, i).remove('-mno-cygwin')
-            except ValueError:
-                pass
+    # the -mno-cygwin option has been deprecated for years
+    Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler
 
-cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler
+    class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler):
+        def __init__(self, *args, **kwargs):
+            Mingw32CCompiler.__init__(self, *args, **kwargs)
+            for i in 'compiler compiler_so linker_exe
linker_so'.split():
+                try:
+                    getattr(self, i).remove('-mno-cygwin')
+                except ValueError:
+                    pass
+
+    cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler
+except ImportError:
+    # the cygwinccompiler package is not available on some Python
+    # distributions like the ones from the optware project for Synology
+    # DiskStation boxes
+    class HackedMingw32CCompiler(object):
+        pass
 
 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
                              'help/*.txt',


More information about the Mercurial-devel mailing list