[PATCH 1 of 5 stable] crecord: use try/except for import of curses
Yuya Nishihara
yuya at tcha.org
Wed Dec 16 09:45:31 CST 2015
On Tue, 15 Dec 2015 16:06:12 -0800, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean at farley.io>
> # Date 1450223509 28800
> # Tue Dec 15 15:51:49 2015 -0800
> # Branch stable
> # Node ID 7ceba88969e51bb825748f69b45e4677e0a02815
> # Parent 59d5f619e69ec43f1957eddd85d4e1deddd64925
> crecord: use try/except for import of curses
>
> Not only does this improve fragility with 'if os.name == ...' it will help
> future patches enable the behavior to fallback to use plain record when curses
> is unavailable (e.g. python compiled without curses support).
>
> diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> --- a/mercurial/crecord.py
> +++ b/mercurial/crecord.py
> @@ -28,16 +28,15 @@ from . import (
>
> # This is required for ncurses to display non-ASCII characters in default user
> # locale encoding correctly. --immerrr
> locale.setlocale(locale.LC_ALL, '')
>
> -# os.name is one of: 'posix', 'nt', 'dos', 'os2', 'mac', or 'ce'
> -if os.name == 'posix':
> +try:
> import curses
> import fcntl
> import termios
> -else:
> +except ImportError:
If demandimport is enabled, these imports won't raise ImportError here.
(I didn't read the patches carefully, so I might be wrong.)
More information about the Mercurial-devel
mailing list