Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoMeyer441 committed Nov 26, 2024
2 parents 7f8f06f + 0d27308 commit 434f4b7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ indent_style = tab
# 2 space indentation for YAML files
[*.{yml,yaml}]
indent_size = 2

# Only allow 72 character line length for commit messages
# See <https://www.git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines> for a reference
[COMMIT_EDITMSG]
max_line_length = 72
10 changes: 5 additions & 5 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
container: python:3
steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Add the project directory to safe directories in Git
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- name: Install pre-commit
run: |
pip install "virtualenv<v20.24.6" && # temporary fix for gitlint
pip install "pre-commit==3.5.0"
run: pip install "pre-commit==4.0.1"
- name: Run pre-commit checks
run: |
TMP_MSG_FILE="$(mktemp)" &&
Expand All @@ -19,7 +19,7 @@ jobs:
--all-files \
--color=always \
--show-diff-on-failure \
--hook-stage commit &&
--hook-stage pre-commit &&
pre-commit run \
--all-files \
--color=always \
Expand Down
30 changes: 20 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ stages:
pre-commit:
stage: check
image: python:3
variables:
GIT_CLONE_PATH: "${CI_BUILDS_DIR}/${CI_PROJECT_NAME}"
PIP_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/pip"
PRE_COMMIT_HOME: "${CI_PROJECT_DIR}/.cache/pre-commit"
cache:
key: pre-commit
paths:
- .cache
before_script:
- pip install "virtualenv<v20.24.6" # temporary fix for gitlint
- pip install "pre-commit==3.5.0"
- pip install "pre-commit==4.0.1"
script:
- TMP_MSG_FILE="$(mktemp)"
- git log -1 --pretty=%B > "${TMP_MSG_FILE}"
- pre-commit run
--all-files
--color=always
--show-diff-on-failure
--hook-stage commit &&
--hook-stage pre-commit &&
pre-commit run
--all-files
--color=always
Expand All @@ -44,13 +51,13 @@ check-python-compatibility:py35:

build-linux-executable:
stage: build
image: centos:7
image: rockylinux:8
before_script:
- yum install -y epel-release
- yum install -y python36-pip upx
- dnf install -y epel-release
- dnf install -y python39-pip upx
script:
- python3 setup.py bdist_pyinstaller
- PLATFORM=$(python3 -c 'import platform; print("{}_{}".format(platform.system(), platform.machine()).lower())');
- python3.9 setup.py bdist_pyinstaller
- PLATFORM=$(python3.9 -c 'import platform; print(f"{platform.system()}_{platform.machine()}".lower())');
mv "dist/${CI_PROJECT_NAME}" "dist/${CI_PROJECT_NAME}_${PLATFORM}"
artifacts:
expire_in: 1 week
Expand All @@ -64,7 +71,7 @@ build-macos-executable:
- libvirt
script:
- python3 setup.py bdist_pyinstaller
- PLATFORM=$(python3 -c 'import platform; print("{}_{}".format(platform.system(), platform.machine()).lower())');
- PLATFORM=$(python3 -c 'import platform; print(f"{platform.system()}_{platform.machine()}".lower())');
mv "dist/${CI_PROJECT_NAME}" "dist/${CI_PROJECT_NAME}_${PLATFORM}"
artifacts:
expire_in: 1 week
Expand Down Expand Up @@ -101,13 +108,16 @@ deploy-to-pypi:
only:
- tags@imeyer/simple-term-menu
script:
- pip install twine
- echo "[distutils]" > ~/.pypirc;
echo "index-servers =" >> ~/.pypirc;
echo " pypi" >> ~/.pypirc;
echo "[pypi]" >> ~/.pypirc;
echo "username = __token__" >> ~/.pypirc;
echo "password = ${PYPI_DEPLOY_KEY}" >> ~/.pypirc;
- pip install
setuptools
twine
wheel
- python setup.py sdist
- python setup.py bdist_wheel
- twine upload dist/*.tar.gz dist/*.whl
Expand Down
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
default_stages: ['commit']
default_stages: ['pre-commit']
repos:
# pre-commit repo:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
# general hooks:
- id: check-added-large-files # Prevent giant files from being committed
Expand All @@ -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.7.3
rev: 3.0.3
hooks:
- id: editorconfig-checker
exclude_types: [markdown]
Expand All @@ -47,18 +47,18 @@ repos:
'--msg-filename',
]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
rev: v0.43.0
hooks:
- id: markdownlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
rev: v1.35.1
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.27.1
rev: 0.29.4
hooks:
- id: check-jsonschema
name: 'Validate GitLab CI configuration'
Expand All @@ -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.27.1
rev: 0.29.4
hooks:
- id: check-github-workflows
# Python specific repos:
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 24.10.0
hooks:
- id: black
args: ['--line-length=120']
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
args: [ # Arguments for `black` compatibility
Expand All @@ -90,15 +90,15 @@ repos:
'--ensure-newline-before-comments',
]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.1.1
hooks:
- id: flake8
args: [
'--max-line-length=120',
'--ignore=E203,W503', # Otherwise, `flake8` is not compatible with `black`
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.13.0
hooks:
- id: mypy
args: ['--ignore-missing-imports', '--strict']
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRECOMMIT_VERSION = 3.5.0
PRECOMMIT_VERSION = 4.0.1

PRECOMMIT_ENV := $(shell git rev-parse --git-dir 2>/dev/null || echo ".")/.pre-commit_env

Expand Down Expand Up @@ -41,7 +41,7 @@ check: install-pre-commit
"$(PRECOMMIT_ENV)/bin/pre-commit" run \
--all-files \
--show-diff-on-failure \
--hook-stage commit && \
--hook-stage pre-commit && \
"$(PRECOMMIT_ENV)/bin/pre-commit" run \
--all-files \
--show-diff-on-failure \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ yay -S python-simple-term-menu

You also find self-contained executables for 64-bit Linux distributions and macOS High Sierra and newer on the
[releases page](https://github.com/IngoMeyer441/simple-term-menu/releases/latest). They are created with
[PyInstaller](http://www.pyinstaller.org) and only require glibc >= 2.17 on Linux (should be fine on any recent
[PyInstaller](http://www.pyinstaller.org) and only require glibc >= 2.28 on Linux (should be fine on any recent
Linux system).

## Usage
Expand Down
26 changes: 17 additions & 9 deletions simple_term_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
__email__ = "i.meyer@fz-juelich.de"
__copyright__ = "Copyright © 2021 Forschungszentrum Jülich GmbH. All rights reserved."
__license__ = "MIT"
__version_info__ = (1, 6, 4)
__version_info__ = (1, 6, 5)
__version__ = ".".join(map(str, __version_info__))


Expand Down Expand Up @@ -904,9 +904,11 @@ def _init_terminal_codes(cls) -> None:
return
supported_colors = int(cls._query_terminfo_database("colors"))
cls._codename_to_terminal_code = {
codename: cls._query_terminfo_database(codename)
if not (codename.startswith("bg_") or codename.startswith("fg_")) or supported_colors >= 8
else ""
codename: (
cls._query_terminfo_database(codename)
if not (codename.startswith("bg_") or codename.startswith("fg_")) or supported_colors >= 8
else ""
)
for codename in cls._codenames
}
cls._codename_to_terminal_code.update(cls._name_to_control_character)
Expand Down Expand Up @@ -964,10 +966,14 @@ def _init_term(self) -> None:
self._tty_out = open("/dev/tty", "w", encoding=self._user_locale, errors="replace")
self._old_term = termios.tcgetattr(self._tty_in.fileno())
self._new_term = termios.tcgetattr(self._tty_in.fileno())
# set the terminal to: unbuffered, no echo and no <CR> to <NL> translation (so <enter> sends <CR> instead of
# <NL, this is necessary to distinguish between <enter> and <Ctrl-j> since <Ctrl-j> generates <NL>)
# set the terminal to: no line-buffering, no echo and no <CR> to <NL> translation (so <enter> sends <CR> instead
# of <NL, this is necessary to distinguish between <enter> and <Ctrl-j> since <Ctrl-j> generates <NL>)
self._new_term[3] = cast(int, self._new_term[3]) & ~termios.ICANON & ~termios.ECHO & ~termios.ICRNL
self._new_term[0] = cast(int, self._new_term[0]) & ~termios.ICRNL
# Set the timings for an unbuffered read: Return immediately after at least one character has arrived and don't
# wait for further characters
cast(list[bytes], self._new_term[6])[termios.VMIN] = b"\x01"
cast(list[bytes], self._new_term[6])[termios.VTIME] = b"\x00"
termios.tcsetattr(
self._tty_in.fileno(), termios.TCSAFLUSH, cast(List[Union[int, List[Union[bytes, int]]]], self._new_term)
)
Expand Down Expand Up @@ -1220,9 +1226,11 @@ def get_preview_string() -> Optional[str]:
)
def strip_ansi_codes_except_styling(string: str) -> str:
stripped_string = strip_ansi_codes_except_styling.ansi_escape_regex.sub( # type: ignore
lambda match_obj: match_obj.group(0)
if strip_ansi_codes_except_styling.ansi_sgr_regex.match(match_obj.group(0)) # type: ignore
else "",
lambda match_obj: (
match_obj.group(0)
if strip_ansi_codes_except_styling.ansi_sgr_regex.match(match_obj.group(0)) # type: ignore
else ""
),
string,
)
return cast(str, stripped_string)
Expand Down

0 comments on commit 434f4b7

Please sign in to comment.