Patchwork [2,of,4] crecord: conditionalize the imports that are not available on Windows

mail settings
Submitter Matt Harbison
Date March 21, 2015, 6:11 a.m.
Message ID <ce3e2b1febb53e893943.1426918262@Envy>
Download mbox | patch
Permalink /patch/8211/
State Accepted
Headers show


Matt Harbison - March 21, 2015, 6:11 a.m.
# HG changeset patch
# User Matt Harbison <>
# Date 1426908720 14400
#      Fri Mar 20 23:32:00 2015 -0400
# Node ID ce3e2b1febb53e893943bae8582d1d75aca48da8
# Parent  d6dd0d5dafcb3d65cdeb5c07e7197204416db879
crecord: conditionalize the imports that are not available on Windows

'fcntl', 'termios' and 'wcurses' are not available on the default Windows python
installation, and importing them caused widespread carnage in the test suite.
There were 29 different changed test files (on top of unrelated errors), mostly
in the form of an ImportError.

The failures weren't related to actual crecord use, and followed the import

    'localrepo' -> 'subrepo' -> 'cmdutil' -> 'crecord' -> 'fcntl'


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -12,7 +12,7 @@ 
 import patch as patchmod
 import util, encoding
-import os, re, sys, fcntl, struct, termios, signal, tempfile, locale, cStringIO
+import os, re, sys, struct, signal, tempfile, locale, cStringIO
 # This is required for ncurses to display non-ASCII characters in default user
 # locale encoding correctly.  --immerrr
@@ -20,10 +20,14 @@ 
 # is one of: 'posix', 'nt', 'dos', 'os2', 'mac', or 'ce'
 if == 'posix':
-    import curses
+    import curses, fcntl, termios
     # I have no idea if wcurses works with crecord...
-    import wcurses as curses
+    try:
+        import wcurses as curses
+    except ImportError:
+        # wcurses is not shipped on Windows by default
+        pass
diff --git a/tests/test-module-imports.t b/tests/test-module-imports.t
--- a/tests/test-module-imports.t
+++ b/tests/test-module-imports.t
@@ -21,6 +21,9 @@ 
 these may expose other cycles.
   $ hg locate 'mercurial/**.py' | sed 's-\\-/-g' | xargs python "$import_checker"
+  mercurial/ mixed imports
+     stdlib:    fcntl, termios
+     relative:  curses
   mercurial/ mixed imports
      stdlib:    commands
      relative:  error, extensions, fancyopts, hg, hook, util