Patchwork [stable] demandimport: blacklist distutils.msvc9compiler (issue4475)

login
register
mail settings
Submitter Augie Fackler
Date Dec. 22, 2014, 10:49 p.m.
Message ID <c3226447cef439d6cd6e.1419288562@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7200/
State Accepted
Commit 2205d00b6d2b0d8abefd5034337f7eb58a970710
Headers show

Comments

Augie Fackler - Dec. 22, 2014, 10:49 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1419287251 18000
#      Mon Dec 22 17:27:31 2014 -0500
# Node ID c3226447cef439d6cd6e4d0f58423051147ca53f
# Parent  43b1be4a152bc27d70d21a698e8db4cd21fe445e
demandimport: blacklist distutils.msvc9compiler (issue4475)

This module depends on _winreg, which is windows-only. Recent versions
of setuptools load distutils.msvc9compiler and expect it to
ImportError immediately when on non-Windows platforms, so we need to
let them do that. This breaks in an especially mystifying way, because
setuptools uses vars() on the imported module. We then throw an
exception, which vars doesn't pick up on well. For example:

In [3]: class wat(object):
   ...:     @property
   ...:     def __dict__(self):
   ...:         assert False
   ...:

In [4]: vars(wat())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-2781ada5ffe6> in <module>()
----> 1 vars(wat())

TypeError: vars() argument must have __dict__ attribute

Which is similar to the problem we run into.
Matt Mackall - Dec. 22, 2014, 10:53 p.m.
On Mon, 2014-12-22 at 17:49 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1419287251 18000
> #      Mon Dec 22 17:27:31 2014 -0500
> # Node ID c3226447cef439d6cd6e4d0f58423051147ca53f
> # Parent  43b1be4a152bc27d70d21a698e8db4cd21fe445e
> demandimport: blacklist distutils.msvc9compiler (issue4475)

Queued for stable, thanks.

Patch

diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py
--- a/mercurial/demandimport.py
+++ b/mercurial/demandimport.py
@@ -164,6 +164,8 @@  ignore = [
     '_ssl', # conditional imports in the stdlib, issue1964
     'rfc822',
     'mimetools',
+    # setuptools 8 expects this module to explode early when not on windows
+    'distutils.msvc9compiler'
     ]
 
 def isenabled():
diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -1,6 +1,16 @@ 
 from mercurial import demandimport
 demandimport.enable()
 
+import os
+if os.name != 'nt':
+    try:
+        import distutils.msvc9compiler
+        print ('distutils.msvc9compiler needs to be an immediate '
+               'importerror on non-windows platforms')
+        distutils.msvc9compiler
+    except ImportError:
+        pass
+
 import re
 
 rsub = re.sub