Patchwork [hg-experimental-ext] chistedit: fail only when attempting to run if curses is not found

login
register
mail settings
Submitter via Mercurial-devel
Date May 23, 2017, 5:17 a.m.
Message ID <53bbe5f3591b2fde3aba.1495516669@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20856/
State Accepted
Delegated to: Jun Wu
Headers show

Comments

via Mercurial-devel - May 23, 2017, 5:17 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495516223 25200
#      Mon May 22 22:10:23 2017 -0700
# Node ID 53bbe5f3591b2fde3aba487b8d548f44d49478d4
# Parent  e32ef07e0de21267a964a3298e3144701a6a98e7
chistedit: fail only when attempting to run if curses is not found

If curses is not available, we can still be nice and not fail until
the user actually tries to run the chistedit command.
Jun Wu - May 23, 2017, 6:02 a.m.
Pushed. Thanks!

Excerpts from Martin von Zweigbergk's message of 2017-05-22 22:17:49 -0700:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1495516223 25200
> #      Mon May 22 22:10:23 2017 -0700
> # Node ID 53bbe5f3591b2fde3aba487b8d548f44d49478d4
> # Parent  e32ef07e0de21267a964a3298e3144701a6a98e7
> chistedit: fail only when attempting to run if curses is not found
> 
> If curses is not available, we can still be nice and not fail until
> the user actually tries to run the chistedit command.
> 
> diff --git a/hgext3rd/chistedit.py b/hgext3rd/chistedit.py
> --- a/hgext3rd/chistedit.py
> +++ b/hgext3rd/chistedit.py
> @@ -43,7 +43,7 @@
>  try:
>      import curses
>  except ImportError:
> -    print("Python curses library required", file=sys.stderr)
> +    curses = None
>  
>  KEY_LIST = ['pick', 'edit', 'fold', 'drop', 'mess', 'roll']
>  ACTION_LABELS = {
> @@ -548,6 +548,9 @@
>      """Provides a ncurses interface to histedit. Press ? in chistedit mode
>      to see an extensive help. Requires python-curses to be installed."""
>  
> +    if curses is None:
> +        raise error.Abort(_("Python curses library required"))
> +
>      # disable color
>      ui._colormode = None
>

Patch

diff --git a/hgext3rd/chistedit.py b/hgext3rd/chistedit.py
--- a/hgext3rd/chistedit.py
+++ b/hgext3rd/chistedit.py
@@ -43,7 +43,7 @@ 
 try:
     import curses
 except ImportError:
-    print("Python curses library required", file=sys.stderr)
+    curses = None
 
 KEY_LIST = ['pick', 'edit', 'fold', 'drop', 'mess', 'roll']
 ACTION_LABELS = {
@@ -548,6 +548,9 @@ 
     """Provides a ncurses interface to histedit. Press ? in chistedit mode
     to see an extensive help. Requires python-curses to be installed."""
 
+    if curses is None:
+        raise error.Abort(_("Python curses library required"))
+
     # disable color
     ui._colormode = None