diff --git a/.github/workflows/check-python-compatibility.yml b/.github/workflows/check-python-compatibility.yml index c82fb35..fdeb02b 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: python3.5 -m simple_term_menu --version + run: TERM=dumb python3.5 -m simple_term_menu --version diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 869274f..3acb08d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -8,7 +8,7 @@ jobs: - name: Check out repository code uses: actions/checkout@v2 - name: Install pre-commit - run: pip install "pre-commit==2.17.0" + run: pip install "pre-commit==3.5.0" - name: Run pre-commit checks run: | TMP_MSG_FILE="$(mktemp)" && diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 48b660f..55d73dd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ pre-commit: stage: check image: python:3 before_script: - - pip install "pre-commit==2.17.0" + - pip install "pre-commit==3.5.0" script: - TMP_MSG_FILE="$(mktemp)" - git log -1 --pretty=%B > "${TMP_MSG_FILE}" @@ -39,7 +39,7 @@ check-python-compatibility:py35: image: sciapp/python-testing:latest-ubuntu-20.04 script: - python3.5 -m pip install . - - python3.5 -m simple_term_menu --version + - TERM=dumb python3.5 -m simple_term_menu --version build-linux-executable: stage: build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe27ad1..8fa7314 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_stages: ['commit'] repos: # pre-commit repo: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.5.0 hooks: # general hooks: - id: check-added-large-files # Prevent giant files from being committed @@ -29,7 +29,7 @@ repos: - id: requirements-txt-fixer # Sorts entries in requirements.txt and removes incorrect entry `pkg-resources==0.0.0` # General repos: - repo: https://github.com/editorconfig-checker/editorconfig-checker.python - rev: 2.4.0 + rev: 2.7.3 hooks: - id: editorconfig-checker exclude_types: [markdown] @@ -39,7 +39,7 @@ repos: - id: detect-direct-checkins args: ['--branch=master', '--allow-root'] - repo: https://github.com/jorisroovers/gitlint - rev: v0.17.0 + rev: v0.19.1 hooks: - id: gitlint args: [ @@ -47,18 +47,18 @@ repos: '--msg-filename', ] - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.31.1 + rev: v0.37.0 hooks: - id: markdownlint - repo: https://github.com/adrienverge/yamllint - rev: v1.26.3 + rev: v1.32.0 hooks: - id: yamllint args: [ '--config-data={extends: default, rules: {indentation: {indent-sequences: consistent}, line-length: {max: 120}}}' ] - repo: https://github.com/sirosen/check-jsonschema - rev: 0.14.0 + rev: 0.27.1 hooks: - id: check-jsonschema name: 'Validate GitLab CI configuration' @@ -68,17 +68,17 @@ repos: 'https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json', ] - repo: https://github.com/sirosen/check-jsonschema - rev: 0.14.0 + rev: 0.27.1 hooks: - id: check-github-workflows # Python specific repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.10.1 hooks: - id: black args: ['--line-length=120'] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort args: [ # Arguments for `black` compatibility @@ -90,7 +90,7 @@ repos: '--ensure-newline-before-comments', ] - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 6.1.0 hooks: - id: flake8 args: [ @@ -98,7 +98,7 @@ repos: '--ignore=E203,W503', # Otherwise, `flake8` is not compatible with `black` ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.910 + rev: v1.6.1 hooks: - id: mypy args: ['--ignore-missing-imports', '--strict'] diff --git a/Makefile b/Makefile index a6330f4..e6e0393 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PRECOMMIT_VERSION = 2.17.0 +PRECOMMIT_VERSION = 3.5.0 PRECOMMIT_ENV := $(shell git rev-parse --git-dir 2>/dev/null || echo ".")/.pre-commit_env diff --git a/setup.py b/setup.py index 54fa305..d0e0b28 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,13 @@ import os import runpy import subprocess -from distutils.cmd import Command from tempfile import TemporaryDirectory -from typing import List, Optional, Tuple, cast +from typing import List, Optional, Tuple, cast # noqa: F401 -from setuptools import setup +from setuptools import Command, setup -class PyinstallerCommand(Command): +class PyinstallerCommand(Command): # type: ignore description = "create a self-contained executable with PyInstaller" user_options = [] # type: List[Tuple[str, Optional[str], str]] @@ -51,6 +50,8 @@ 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 507348b..086e153 100755 --- a/simple_term_menu.py +++ b/simple_term_menu.py @@ -38,12 +38,20 @@ 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, 1) +__version_info__ = (1, 6, 2) __version__ = ".".join(map(str, __version_info__)) @@ -1270,7 +1278,7 @@ def limit_string_with_escape_codes(string: str, max_len: int) -> Tuple[str, int] BoxDrawingCharacters.upper_left + (2 * BoxDrawingCharacters.horizontal + " " + self._preview_title)[: num_cols - 3] + " " - + (num_cols - len(self._preview_title) - 6) * BoxDrawingCharacters.horizontal + + (num_cols - wcswidth(self._preview_title) - 6) * BoxDrawingCharacters.horizontal + BoxDrawingCharacters.upper_right )[:num_cols] + "\n" @@ -1475,7 +1483,7 @@ def _read_next_key(self, ignore_case: bool = True) -> str: def show(self) -> Optional[Union[int, Tuple[int, ...]]]: def init_signal_handling() -> None: # `SIGWINCH` is send on terminal resizes - def handle_sigwinch(signum: signal.Signals, frame: FrameType) -> None: + def handle_sigwinch(signum: int, frame: Optional[FrameType]) -> None: # pylint: disable=unused-argument if self._reading_next_key: self._paint_menu()