diff options
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 3f928e5f..c9577e82 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -24,6 +24,7 @@ from typing import ( Dict, Iterable, List, + NamedTuple, Optional, TextIO, Type, @@ -161,7 +162,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]], >>> Node(4) Node(val=4, left=None, right=7) """ - T = collections.namedtuple(typename, field_names) + T: NamedTuple = collections.namedtuple(typename, field_names) # noinspection PyProtectedMember,PyUnresolvedReferences T.__new__.__defaults__ = (None,) * len(T._fields) if isinstance(default_values, collections_abc.Mapping): @@ -353,7 +354,13 @@ def find_editor() -> Optional[str]: else: editors = ['vim', 'vi', 'emacs', 'nano', 'pico', 'joe', 'code', 'subl', 'atom', 'gedit', 'geany', 'kate'] - paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)] + # Get a list of every directory in the PATH environment variable and ignore symbolic links + env_path = os.getenv('PATH') + if env_path is None: + paths = [] + else: + paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)] + for editor, path in itertools.product(editors, paths): editor_path = os.path.join(path, editor) if os.path.isfile(editor_path) and os.access(editor_path, os.X_OK): @@ -408,7 +415,11 @@ def get_exes_in_path(starts_with: str) -> List[str]: return [] # Get a list of every directory in the PATH environment variable and ignore symbolic links - paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)] + env_path = os.getenv('PATH') + if env_path is None: + paths = [] + else: + paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)] # Use a set to store exe names since there can be duplicates exes_set = set() |