Patchwork [1,of,2] histedit: conditionalize the imports of 'fcntl' and 'termios'

login
register
mail settings
Submitter Matt Harbison
Date Nov. 15, 2018, 10:41 p.m.
Message ID <3069b205bc1d99e8dc0a.1542321680@mharbison-pc.attotech.com>
Download mbox | patch
Permalink /patch/36615/
State Accepted
Headers show

Comments

Matt Harbison - Nov. 15, 2018, 10:41 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1542321375 18000
#      Thu Nov 15 17:36:15 2018 -0500
# Node ID 3069b205bc1d99e8dc0ad9a15a343670ed0039eb
# Parent  442f933f61e4c81148dcc192f0ac535bc3925529
histedit: conditionalize the imports of 'fcntl' and 'termios'

The recent import of chistedit in c36175456350 made Windows sad.  I'm not sure
if there's other stuff that needs to be done here (e.g. change the default
interface), but this makes the tests run again.

It would have been nicer if the error message indicated these modules were the
problem, but instead it said "*** failed to import extension histedit: No module
named histedit".  I'm not sure if there's anything we can do about that.
Yuya Nishihara - Nov. 16, 2018, 11:48 a.m.
On Thu, 15 Nov 2018 17:41:20 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1542321375 18000
> #      Thu Nov 15 17:36:15 2018 -0500
> # Node ID 3069b205bc1d99e8dc0ad9a15a343670ed0039eb
> # Parent  442f933f61e4c81148dcc192f0ac535bc3925529
> histedit: conditionalize the imports of 'fcntl' and 'termios'

Queued, thanks.

> @@ -183,11 +183,17 @@ unexpectedly::
>  
>  from __future__ import absolute_import
>  
> -import fcntl
> +# chistedit dependencies that are not available everywhere
> +try:
> +    import fcntl

This is fine because fcntl is excluded from the demand importer, but termios
isn't. However, I expect termios will be removed in favor of scmutil function.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -183,11 +183,17 @@  unexpectedly::
 
 from __future__ import absolute_import
 
-import fcntl
+# chistedit dependencies that are not available everywhere
+try:
+    import fcntl
+    import termios
+except ImportError:
+    fcntl = None
+    termios = None
+
 import functools
 import os
 import struct
-import termios
 
 from mercurial.i18n import _
 from mercurial import (