From 12c2128bef8059cae61a68313f468d40c3cfc685 Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 4 Feb 2022 07:15:28 +0100 Subject: [PATCH 1/5] Add pre-commit hook and improve its rules --- .github/workflows/pre-commit.yml | 14 +++++ .../{python-publish.yml => publish.yml} | 0 .../{python-test.yml => run-tests.yml} | 4 +- .pre-commit-config.yaml | 31 ++++++----- readchar/key.py | 52 +++++++++---------- readchar/readchar.py | 9 ++-- 6 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/pre-commit.yml rename .github/workflows/{python-publish.yml => publish.yml} (100%) rename .github/workflows/{python-test.yml => run-tests.yml} (95%) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..925b8ac --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.3 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/publish.yml similarity index 100% rename from .github/workflows/python-publish.yml rename to .github/workflows/publish.yml diff --git a/.github/workflows/python-test.yml b/.github/workflows/run-tests.yml similarity index 95% rename from .github/workflows/python-test.yml rename to .github/workflows/run-tests.yml index 1996d19..fc74c2d 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/run-tests.yml @@ -16,12 +16,12 @@ jobs: strategy: matrix: python-version: - - "2.7" - "3.5" - "3.6" - "3.7" - "3.8" - "3.9" + - "3.10" steps: - uses: actions/checkout@v2 @@ -33,8 +33,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install -r requirements-test.txt - - name: Lint with flake8 - run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5399570..73d314b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,17 +1,24 @@ repos: - - repo: https://github.com/PyCQA/isort.git - rev: 5.7.0 - hooks: - - id: isort - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 22.1.0 + hooks: + - name: re-format with black + id: black + language_version: python3 + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 hooks: - - id: black - language_version: python3 - args: - - -l - - "119" + - name: remove whitespaces + id: trailing-whitespace + - repo: https://gitlab.com/pycqa/flake8 - rev: 6de8252c035844f1e679f509b5f37340b44d5c39 + rev: 21d3c70d676007470908d39b73f0521d39b3b997 hooks: - - id: flake8 + - name: check-format with flake8 + id: flake8 + args: + - --show-source + - --statistics + - --count + - --max-complexity=12 diff --git a/readchar/key.py b/readchar/key.py index c7d4df5..865427f 100644 --- a/readchar/key.py +++ b/readchar/key.py @@ -8,32 +8,32 @@ ESC = "\x1b" # CTRL -CTRL_A = '\x01' -CTRL_B = '\x02' -CTRL_C = '\x03' -CTRL_D = '\x04' -CTRL_E = '\x05' -CTRL_F = '\x06' -CTRL_G = '\x07' -CTRL_H = '\x08' -CTRL_I = '\t' -CTRL_J = '\n' -CTRL_K = '\x0b' -CTRL_L = '\x0c' -CTRL_M = '\r' -CTRL_N = '\x0e' -CTRL_O = '\x0f' -CTRL_P = '\x10' -CTRL_Q = '\x11' -CTRL_R = '\x12' -CTRL_S = '\x13' -CTRL_T = '\x14' -CTRL_U = '\x15' -CTRL_V = '\x16' -CTRL_W = '\x17' -CTRL_X = '\x18' -CTRL_Y = '\x19' -CTRL_Z = '\x1a' +CTRL_A = "\x01" +CTRL_B = "\x02" +CTRL_C = "\x03" +CTRL_D = "\x04" +CTRL_E = "\x05" +CTRL_F = "\x06" +CTRL_G = "\x07" +CTRL_H = "\x08" +CTRL_I = "\t" +CTRL_J = "\n" +CTRL_K = "\x0b" +CTRL_L = "\x0c" +CTRL_M = "\r" +CTRL_N = "\x0e" +CTRL_O = "\x0f" +CTRL_P = "\x10" +CTRL_Q = "\x11" +CTRL_R = "\x12" +CTRL_S = "\x13" +CTRL_T = "\x14" +CTRL_U = "\x15" +CTRL_V = "\x16" +CTRL_W = "\x17" +CTRL_X = "\x18" +CTRL_Y = "\x19" +CTRL_Z = "\x1a" # ALT ALT_A = "\x1b\x61" diff --git a/readchar/readchar.py b/readchar/readchar.py index 5c1a75d..8aa352a 100644 --- a/readchar/readchar.py +++ b/readchar/readchar.py @@ -53,10 +53,10 @@ 20960: key.PAGE_DOWN, 18400: key.HOME, 20448: key.END, - 18432: key.UP, # 72 * 256 - 20480: key.DOWN, # 80 * 256 - 19200: key.LEFT, # 75 * 256 - 19712: key.RIGHT, # 77 * 256 + 18432: key.UP, # 72 * 256 + 20480: key.DOWN, # 80 * 256 + 19200: key.LEFT, # 75 * 256 + 19712: key.RIGHT, # 77 * 256 } def readkey(getchar_fn=None): @@ -79,7 +79,6 @@ def readkey(getchar_fn=None): else: return ch.decode() - else: def readkey(getchar_fn=None): From c3be7ce4063c1a2d21b43d0adae95308d6737054 Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 4 Feb 2022 07:21:47 +0100 Subject: [PATCH 2/5] remove flake8 from tests --- .github/workflows/run-tests.yml | 4 ---- Makefile | 12 +++--------- setup.py | 7 +++---- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index fc74c2d..352605d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,10 +33,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install -r requirements-test.txt - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pytest diff --git a/Makefile b/Makefile index 872a7f4..f5ea67e 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,10 @@ -all: flakes test +all: precommit test test: python setup.py test -analysis:: flakes - -flakes: - @echo Searching for static errors... - @flake8 --statistics --count readchar - -coveralls:: - coveralls +precommit:: + pre-commit run -a publish: @python setup.py bdist_wheel upload diff --git a/setup.py b/setup.py index e63b3b1..c5b46b4 100644 --- a/setup.py +++ b/setup.py @@ -7,10 +7,11 @@ from setuptools import find_packages, setup from setuptools.command.test import test as TestCommand -version = "2.0.1" github_ref = os.getenv("GITHUB_REF") if github_ref and github_ref.startswith("refs/tags"): version = github_ref[10:] +else: + version = "0.0.0-local" def read_description(): @@ -81,7 +82,5 @@ def run_tests(self): "wheel", ], install_requires=[], - setup_requires=[ - "flake8", - ], + setup_requires=[], ) From e67ffe37a5b5d5db46944d4d5c1fc0c472747a01 Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 4 Feb 2022 07:37:13 +0100 Subject: [PATCH 3/5] reformat yaml --- .github/workflows/pre-commit.yml | 14 +++++---- .github/workflows/publish.yml | 49 +++++++++++++++++--------------- .github/workflows/run-tests.yml | 49 ++++++++++++++++++-------------- .pre-commit-config.yaml | 6 ++++ .travis.yml | 36 ----------------------- 5 files changed, 68 insertions(+), 86 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 925b8ac..55e230b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,14 +1,18 @@ +--- name: pre-commit on: - pull_request: push: - branches: [master] + branches: + - master + pull_request: + branches: + - master jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.3 + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index affc6a5..ccff13b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,31 +1,34 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries +--- +# This workflow will upload a Python Package using Twine when a release is +# created +# For more information see: +# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries name: Upload Python Package on: - release: - types: [created] + release: + types: [created] jobs: - deploy: + deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 352605d..9f6ea51 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,13 +1,18 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +--- +# This workflow will install Python dependencies, run tests and lint with a +# variety of Python versions +# For more information see: +# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: Python package on: push: - branches: [ master ] + branches: + - master pull_request: - branches: [ master ] + branches: + - master jobs: build: @@ -16,23 +21,23 @@ jobs: strategy: matrix: python-version: - - "3.5" - - "3.6" - - "3.7" - - "3.8" - - "3.9" - - "3.10" + - "3.5" + - "3.6" + - "3.7" + - "3.8" + - "3.9" + - "3.10" steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install -r requirements-test.txt - - name: Test with pytest - run: | - pytest + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements-test.txt + - name: Test with pytest + run: | + pytest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73d314b..45f221f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,10 @@ +--- repos: + - repo: https://github.com/adrienverge/yamllint + rev: v1.26.3 + hooks: + - name: check YAML format + id: yamllint - repo: https://github.com/psf/black rev: 22.1.0 hooks: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5a93ab2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: python - -sudo: false - -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" - - "3.7-dev" - - "pypy" - - "pypy3" - -matrix: - include: - - python: "3.6" - env: TMODE=flake8 -env: - TMODE=test - -install: - - "if [[ $TMODE == 'test' ]]; then pip install pytest; fi" - - "if [[ $TMODE == 'test' ]]; then python setup.py install; fi" - - pip freeze --all - - ls -lh .eggs || true - -script: - - python setup.py $TMODE - -after_success: - - "if [[ $TMODE == 'test' ]]; then pip install python-coveralls; coveralls; fi" - -notifications: - email: - on_success: change - on_failure: change From 908964cf8002dca681faf10cc777d2f694d882da Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 4 Feb 2022 07:38:38 +0100 Subject: [PATCH 4/5] better indentation --- .github/workflows/publish.yml | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ccff13b..d8e6a51 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,28 +7,28 @@ name: Upload Python Package on: - release: - types: [created] + release: + types: [created] jobs: - deploy: + deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.x - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* From c8c9d5c90ae0b09d2b58dc441f8f3d7658cfda31 Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 4 Feb 2022 07:40:21 +0100 Subject: [PATCH 5/5] yamllint configuration --- .yamllint.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .yamllint.yaml diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..e9147c4 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,8 @@ +extends: default + +rules: + truthy: + ignore: | + .github/workflows/* + indentation: + spaces: 2