diff --git a/.github/workflows/check-python-compatibility.yml b/.github/workflows/check-python-compatibility.yml index fdeb02b..c82fb35 100644 --- a/.github/workflows/check-python-compatibility.yml +++ b/.github/workflows/check-python-compatibility.yml @@ -10,4 +10,4 @@ jobs: - name: Setup simple-term-menu on Python 3.5 run: python3.5 -m pip install . - name: Run a simple-term-menu check on Python 3.5 - run: TERM=dumb python3.5 -m simple_term_menu --version + run: python3.5 -m simple_term_menu --version diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 250079f..edb6ee0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,7 +40,7 @@ check-python-compatibility:py35: image: sciapp/python-testing:latest-ubuntu-20.04 script: - python3.5 -m pip install . - - TERM=dumb python3.5 -m simple_term_menu --version + - python3.5 -m simple_term_menu --version build-linux-executable: stage: build diff --git a/setup.py b/setup.py index d0e0b28..cae622a 100644 --- a/setup.py +++ b/setup.py @@ -50,8 +50,6 @@ def run(self) -> None: def get_version_from_pyfile(version_file: str = "simple_term_menu.py") -> str: - if "TERM" not in os.environ: - os.environ["TERM"] = "" # Avoid error messages when simple-term-menu is not installed on a terminal file_globals = runpy.run_path(version_file) return cast(str, file_globals["__version__"]) diff --git a/simple_term_menu.py b/simple_term_menu.py index 086e153..23d7544 100755 --- a/simple_term_menu.py +++ b/simple_term_menu.py @@ -38,20 +38,12 @@ except ImportError as e: raise NotImplementedError('"{}" is currently not supported.'.format(platform.system())) from e -if "TERM" not in os.environ: - if "PYCHARM_HOSTED" in os.environ: - raise NotImplementedError( - "simple-term-menu does not work in the PyCharm output console. Use a terminal instead (Alt + F12) or " - 'activate "Emulate terminal in output console".' - ) - raise NotImplementedError("simple-term-menu can only be used in a terminal emulator") - __author__ = "Ingo Meyer" __email__ = "i.meyer@fz-juelich.de" __copyright__ = "Copyright © 2021 Forschungszentrum Jülich GmbH. All rights reserved." __license__ = "MIT" -__version_info__ = (1, 6, 2) +__version_info__ = (1, 6, 3) __version__ = ".".join(map(str, __version_info__)) @@ -640,6 +632,15 @@ def __init__( status_bar_style: Optional[Iterable[str]] = DEFAULT_STATUS_BAR_STYLE, title: Optional[Union[str, Iterable[str]]] = None ): + def check_for_terminal_environment() -> None: + if "TERM" not in os.environ or os.environ["TERM"] == "": + if "PYCHARM_HOSTED" in os.environ: + raise NotImplementedError( + "simple-term-menu does not work in the PyCharm output console. Use a terminal instead (Alt + " + 'F12) or activate "Emulate terminal in output console".' + ) + raise NotImplementedError("simple-term-menu can only be used in a terminal emulator") + def extract_shortcuts_menu_entries_and_preview_arguments( entries: Iterable[str], ) -> Tuple[List[str], List[Optional[str]], List[Optional[str]], List[int]]: @@ -720,6 +721,7 @@ def setup_title_or_status_bar_lines( lines.append(shortcut_hints_line) return tuple(lines) + check_for_terminal_environment() ( self._menu_entries, self._shortcut_keys,