From f5dc400b58714eac331a2c87c3d1cc82d661666a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 01/28] Run Flake8 only once on CI --- .github/workflows/flake8.yml | 17 +++++++++++++++++ .github/workflows/python-package.yml | 2 +- setup.cfg | 5 ----- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/flake8.yml diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml new file mode 100644 index 000000000..9198446dd --- /dev/null +++ b/.github/workflows/flake8.yml @@ -0,0 +1,17 @@ +--- +name: Flake8 + +on: push # yamllint disable-line rule:truthy + +jobs: + flake8: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: TrueBrain/actions-flake8@v2 + with: + plugins: > + flake8-2020>=1.6.1 + flake8-bugbear>=22.1.11 + flake8-comprehensions>=3.7.0 diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 80701edf3..1cdeee641 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -59,7 +59,7 @@ jobs: - '3.9' - '3.10' constraints: [''] - lint: ['--darker --flake8 --isort'] + lint: ['--darker --isort'] include: - os: ubuntu-latest python-version: '3.7' diff --git a/setup.cfg b/setup.cfg index af22cd34c..46a67c176 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,16 +55,11 @@ test = black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189 codespell>=2.1.0 defusedxml>=0.7.1 - flake8<4 - flake8-2020>=1.6.1 - flake8-bugbear>=22.1.11 - flake8-comprehensions>=3.7.0 mypy>=0.940 pygments pylint>=2.13.0 pytest>=6.2.0 pytest-darker - pytest-flake8>=1.0.6 pytest-isort>=1.1.0 pytest-kwparametrize>=0.0.3 pytest-mypy From c48343d3c7cf1b185a6694333925104320714cfa Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 02/28] Run isort only once on CI --- .github/workflows/isort.yml | 18 ++++++++++++++++++ .github/workflows/python-package.yml | 6 +++--- .github/workflows/test-future.yml | 2 +- setup.cfg | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/isort.yml diff --git a/.github/workflows/isort.yml b/.github/workflows/isort.yml new file mode 100644 index 000000000..0f58fcd1f --- /dev/null +++ b/.github/workflows/isort.yml @@ -0,0 +1,18 @@ +--- +name: isort + +on: push # yamllint disable-line rule:truthy + +jobs: + isort: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: pip install 'isort>=5.0.1' + - uses: Gobot1234/lint-action@v.1.8.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + isort: true + continue_on_error: false diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 1cdeee641..3612a80dd 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -38,7 +38,7 @@ jobs: --run ' python -m venv venv source venv/bin/activate - pip install -e '.[isort,test]' + pip install -e '.[test]' pytest ' \ ./default.nix @@ -59,7 +59,7 @@ jobs: - '3.9' - '3.10' constraints: [''] - lint: ['--darker --isort'] + lint: ['--darker'] include: - os: ubuntu-latest python-version: '3.7' @@ -102,7 +102,7 @@ jobs: env: pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }} run: pip install ${pip_options} - "dist/darker-${{ env.VERSION }}-py3-none-any.whl[isort,test]" + "dist/darker-${{ env.VERSION }}-py3-none-any.whl[test]" - name: Run Pytest without Mypy and Pylint if Python < 3.9 if: env.RUN_MYPY_AND_PYLINT == 'false' run: | diff --git a/.github/workflows/test-future.yml b/.github/workflows/test-future.yml index 7dae08a7b..472f6b80b 100644 --- a/.github/workflows/test-future.yml +++ b/.github/workflows/test-future.yml @@ -27,7 +27,7 @@ jobs: --constraint=constraints-future.txt \ --upgrade \ --upgrade-strategy=eager \ - -e '.[isort,test]' + -e '.[test]' - name: Test with pytest run: | pytest diff --git a/setup.cfg b/setup.cfg index 46a67c176..a3ca25b93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,6 +55,7 @@ test = black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189 codespell>=2.1.0 defusedxml>=0.7.1 + isort>=5.0.1 mypy>=0.940 pygments pylint>=2.13.0 From 2f3efe09dba1397a798f4d3ddcef985f9a8601db Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 03/28] Unique CI job names --- .github/workflows/bandit.yml | 2 +- .github/workflows/test-future.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bandit.yml b/.github/workflows/bandit.yml index 5479305d7..126939d9c 100644 --- a/.github/workflows/bandit.yml +++ b/.github/workflows/bandit.yml @@ -4,7 +4,7 @@ name: Security check - Bandit on: push # yamllint disable-line rule:truthy jobs: - build: + bandit: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test-future.yml b/.github/workflows/test-future.yml index 472f6b80b..de64a670a 100644 --- a/.github/workflows/test-future.yml +++ b/.github/workflows/test-future.yml @@ -9,7 +9,7 @@ on: # yamllint disable-line rule:truthy - cron: "05 20 * * 6" jobs: - build: + test-future: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From c9023fefba86822b1f7b04fbdf084d4237ea7cc1 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 04/28] No need for deep fetch for YAML lint --- .github/workflows/yaml-lint.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/yaml-lint.yml b/.github/workflows/yaml-lint.yml index abd3fc96b..ba25d1bf3 100644 --- a/.github/workflows/yaml-lint.yml +++ b/.github/workflows/yaml-lint.yml @@ -6,7 +6,5 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: yaml-lint uses: ibiqlik/action-yamllint@v3 From 23455b6776f1ed9f33826603f2757bfbf2a2a9b5 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 05/28] Update change log --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 16e122b6b..050c7cfaf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,7 @@ Added ----- - Add a CI workflow which verifies that the ``darker --help`` output in ``README.rst`` is up to date. +- Only run ``isort`` and ``flake8`` once in the CI build. Fixed ----- From cd801c6bf462e104f94b1f0d64a14a71a6c47061 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:37:58 +0300 Subject: [PATCH 06/28] Run mypy only once in CI --- .github/workflows/mypy.yml | 18 ++++++++++++++++++ .github/workflows/python-package.yml | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/mypy.yml diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 000000000..d9a1bba7f --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,18 @@ +--- +name: mypy + +on: push # yamllint disable-line rule:truthy + +jobs: + mypy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: pip install 'mypy>=0.940' + - uses: Gobot1234/lint-action@v.1.8.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + mypy: true + continue_on_error: false diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3612a80dd..29943211a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -69,7 +69,7 @@ jobs: constraints: '--constraint constraints-future.txt' upgrade: '--upgrade --upgrade-strategy=eager' env: - RUN_MYPY_AND_PYLINT: >- + RUN_PYLINT: >- ${{ matrix.python-version == '3.9' || matrix.python-version == '3.10' }} steps: - uses: actions/checkout@v3 @@ -103,12 +103,12 @@ jobs: pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }} run: pip install ${pip_options} "dist/darker-${{ env.VERSION }}-py3-none-any.whl[test]" - - name: Run Pytest without Mypy and Pylint if Python < 3.9 - if: env.RUN_MYPY_AND_PYLINT == 'false' + - name: Run Pytest without Pylint if Python < 3.9 + if: env.RUN_PYLINT == 'false' run: | pytest ${{ matrix.lint }} - - name: Run Pytest with Mypy and Pylint if Python >= 3.9 - if: env.RUN_MYPY_AND_PYLINT == 'true' + - name: Run Pytest with Pylint if Python >= 3.9 + if: env.RUN_PYLINT == 'true' shell: python run: | import sys @@ -117,7 +117,7 @@ jobs: import toml data = toml.load("pyproject.toml") - data["tool"]["darker"]["lint"] = ["pylint", "mypy"] + data["tool"]["darker"]["lint"] = ["pylint"] Path("pyproject.toml").write_text(toml.dumps(data)) pytest_cmd = ["pytest"] + "${{ matrix.lint }}".split() retval = run(pytest_cmd).returncode From a840ffebd6e5eede886f0dd544ef48320869d1a4 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:53:14 +0300 Subject: [PATCH 07/28] Switch to upstream lint-action, update to July 11 --- .github/workflows/mypy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index d9a1bba7f..023fe62d4 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - run: pip install 'mypy>=0.940' - - uses: Gobot1234/lint-action@v.1.8.2 + - uses: wearerequired/lint-action@v2.0.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} mypy: true From a8ea634f16df61864c3cd1d3dd2d2cebc5aca22b Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:02:33 +0300 Subject: [PATCH 08/28] Run Mypy only for `src/` --- .github/workflows/mypy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 023fe62d4..1fd1f7348 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -15,4 +15,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} mypy: true + mypy_args: "src" continue_on_error: false From eb0870994213fd9b5fba90aeb8138b0bb65272f2 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:05:26 +0300 Subject: [PATCH 09/28] Specify configuration file explicitly --- .github/workflows/mypy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 1fd1f7348..91a1ce6f7 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -15,5 +15,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} mypy: true - mypy_args: "src" + mypy_args: "--config-file=mypy.ini src" continue_on_error: false From f368e806e2d2073aab80baeff6b79e02a65de251 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:31:05 +0300 Subject: [PATCH 10/28] Install some deps for mypy. More specific ignore. --- .github/workflows/mypy.yml | 4 ++-- src/darker/help.py | 2 +- src/darker/import_sorting.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 91a1ce6f7..758b4b00c 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -10,10 +10,10 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - - run: pip install 'mypy>=0.940' + - run: pip install -U isort mypy pytest types-toml - uses: wearerequired/lint-action@v2.0.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} mypy: true - mypy_args: "--config-file=mypy.ini src" + mypy_args: "src" continue_on_error: false diff --git a/src/darker/help.py b/src/darker/help.py index d5b04f470..411f280b0 100644 --- a/src/darker/help.py +++ b/src/darker/help.py @@ -11,7 +11,7 @@ try: import isort except ImportError: - isort = None # type: ignore + isort = None # type: ignore[assignment] DESCRIPTION_PARTS.extend( ["\n", "\n", f"{ISORT_INSTRUCTION} to enable sorting of import definitions"] ) diff --git a/src/darker/import_sorting.py b/src/darker/import_sorting.py index 1174d96f4..4f7344cb0 100644 --- a/src/darker/import_sorting.py +++ b/src/darker/import_sorting.py @@ -33,7 +33,7 @@ def isort_code(*args: Any, **kwargs: Any) -> str: # type: ignore[misc] ) except ImportError: # `isort` is an optional dependency. Prevent the `ImportError` if it's missing. - isort = None # type: ignore + isort = None # type: ignore[assignment] def isort_code(*args: Any, **kwargs: Any) -> str: # type: ignore[misc] """Fake `isort.code()` function to use when `isort` isn't installed""" From 6334127ad9e01cebceab1cbc887cc59f69e31835 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:37:48 +0300 Subject: [PATCH 11/28] Pytest-flake8, -isort & -mypy not needed --- constraints-oldest.txt | 2 -- setup.cfg | 2 -- 2 files changed, 4 deletions(-) diff --git a/constraints-oldest.txt b/constraints-oldest.txt index 90ea502c9..b497b73ce 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -15,8 +15,6 @@ mypy==0.940 Pygments==2.4.0 pylint==2.13.0 pytest==6.2.0 -pytest-flake8==1.0.6 -pytest-isort==1.1.0 pytest-kwparametrize==0.0.3 pyupgrade==2.31.0 regex==2021.4.4 diff --git a/setup.cfg b/setup.cfg index a3ca25b93..9ecf7d1f2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,9 +61,7 @@ test = pylint>=2.13.0 pytest>=6.2.0 pytest-darker - pytest-isort>=1.1.0 pytest-kwparametrize>=0.0.3 - pytest-mypy pyupgrade>=2.31.0 regex>=2021.4.4 requests_cache>=0.7 From c10b6a9a5ce75fcb9cccb872fbad037496a86fd6 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:40:10 +0300 Subject: [PATCH 12/28] Remove `bandit` dep, being run in its own workflow --- constraints-oldest.txt | 1 - setup.cfg | 1 - 2 files changed, 2 deletions(-) diff --git a/constraints-oldest.txt b/constraints-oldest.txt index b497b73ce..080431eb2 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -4,7 +4,6 @@ # interpreter and Python ependencies. Keep this up-to-date with minimum # versions in `setup.cfg`. airium==0.2.3 -bandit==1.7.1 black==21.8b0 codespell==2.1.0 defusedxml==0.7.1 diff --git a/setup.cfg b/setup.cfg index 9ecf7d1f2..f336b80d4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,7 +51,6 @@ color = test = # NOTE: remember to keep `constraints-oldest.txt` in sync with these airium>=0.2.3 - bandit>=1.7.1 black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189 codespell>=2.1.0 defusedxml>=0.7.1 From 8f616819b1057cfc8d0e70a7694969f05330a20a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:46:14 +0300 Subject: [PATCH 13/28] Add codespell workflow --- .github/workflows/codespell.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/codespell.yml diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 000000000..08eb7a51b --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,15 @@ +--- +name: codespell + +on: push # yamllint disable-line rule:truthy + +jobs: + codespell: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: codespell-project/actions-codespell@master + with: + ignore_words_list: nd + skip: .git,*.json From c74551fabaf59191f36b5c46d34373ac59cb8048 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:48:10 +0300 Subject: [PATCH 14/28] Test if `actions-codespell` reads setup.cfg --- .github/workflows/codespell.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 08eb7a51b..6a5bbf0fe 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,6 +10,3 @@ jobs: steps: - uses: actions/checkout@v3 - uses: codespell-project/actions-codespell@master - with: - ignore_words_list: nd - skip: .git,*.json From 88590c6a20e6ae715812478b75236287f1bffba3 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:50:52 +0300 Subject: [PATCH 15/28] Clean up old codespell related items --- .github/workflows/python-package.yml | 2 -- constraints-oldest.txt | 1 - setup.cfg | 1 - 3 files changed, 4 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 29943211a..cc7725901 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -123,8 +123,6 @@ jobs: retval = run(pytest_cmd).returncode run(["git", "restore", "pyproject.toml"]) sys.exit(retval) - - name: Check English spelling in the code base using codespell - run: codespell - name: Ensure modern Python style using pyupgrade # This script is written in a Linux / macos / windows portable way run: | diff --git a/constraints-oldest.txt b/constraints-oldest.txt index 080431eb2..f49b41591 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -5,7 +5,6 @@ # versions in `setup.cfg`. airium==0.2.3 black==21.8b0 -codespell==2.1.0 defusedxml==0.7.1 flake8-2020==1.6.1 flake8-bugbear==22.1.11 diff --git a/setup.cfg b/setup.cfg index f336b80d4..ece83077b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,6 @@ test = # NOTE: remember to keep `constraints-oldest.txt` in sync with these airium>=0.2.3 black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189 - codespell>=2.1.0 defusedxml>=0.7.1 isort>=5.0.1 mypy>=0.940 From 860ba1f5c6dd800d52581fa30a6383bb9c763ba1 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:10:17 +0300 Subject: [PATCH 16/28] Add separate `pyupgrade` workflow --- .github/workflows/pyupgrade.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/pyupgrade.yml diff --git a/.github/workflows/pyupgrade.yml b/.github/workflows/pyupgrade.yml new file mode 100644 index 000000000..408f4094f --- /dev/null +++ b/.github/workflows/pyupgrade.yml @@ -0,0 +1,23 @@ +--- +name: pyupgrade + +on: push # yamllint disable-line rule:truthy + +jobs: + pyupgrade: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: pip install pyupgrade + - name: Ensure modern Python style using pyupgrade + # This script is written in a Linux / macos / windows portable way + run: | + python -c " + import sys + from pyupgrade._main import main + from glob import glob + files = glob('**/*.py', recursive=True) + sys.exit(main(files + ['--py37-plus'])) + " || ( git diff ; false ) From be2da2b04412c1bad5f93b8a5c179828a6300228 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:11:40 +0300 Subject: [PATCH 17/28] Follow a pyupgrade recommenadtion --- src/darker/tests/test_git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darker/tests/test_git.py b/src/darker/tests/test_git.py index d0ad478c3..112b2d661 100644 --- a/src/darker/tests/test_git.py +++ b/src/darker/tests/test_git.py @@ -422,7 +422,7 @@ def encodings_repo(tmp_path_factory): git_repo.add({"file.py": content}, commit="iso-8859-1") git_repo.create_tag("iso-8859-1") # Commit with a utf-8 encoding cookie - content = "# coding: utf-8\npython = 'パイソン'\n".encode("utf-8") + content = "# coding: utf-8\npython = 'パイソン'\n".encode() git_repo.add({"file.py": content}, commit="utf-8") git_repo.create_tag("utf-8") # Current worktree content (not committed) with a shitfjs encoding cookie From f4e0e21263b257cb9139cad4f4fa0b74eaaabdb3 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:11:50 +0300 Subject: [PATCH 18/28] Remove old pyupgrade items --- .github/workflows/python-package.yml | 9 --------- constraints-oldest.txt | 1 - setup.cfg | 1 - 3 files changed, 11 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index cc7725901..9d867298f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -123,14 +123,5 @@ jobs: retval = run(pytest_cmd).returncode run(["git", "restore", "pyproject.toml"]) sys.exit(retval) - - name: Ensure modern Python style using pyupgrade - # This script is written in a Linux / macos / windows portable way - run: | - python -c " - from pyupgrade._main import main - from glob import glob - files = glob('**/*.py', recursive=True) - main(files + ['--py37-plus']) - " - name: Check dependencies for known security vulterabilities using Safety run: safety check diff --git a/constraints-oldest.txt b/constraints-oldest.txt index f49b41591..158d1d6dc 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -14,7 +14,6 @@ Pygments==2.4.0 pylint==2.13.0 pytest==6.2.0 pytest-kwparametrize==0.0.3 -pyupgrade==2.31.0 regex==2021.4.4 requests_cache==0.7 ruamel.yaml==0.17.21 diff --git a/setup.cfg b/setup.cfg index ece83077b..b781ab241 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,7 +60,6 @@ test = pytest>=6.2.0 pytest-darker pytest-kwparametrize>=0.0.3 - pyupgrade>=2.31.0 regex>=2021.4.4 requests_cache>=0.7 ruamel.yaml>=0.17.21 From 0920bd44bc58fe59913085a3bbeaac6451fe186b Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:17:06 +0300 Subject: [PATCH 19/28] Run Safety as its own workflow --- .github/workflows/safety.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/safety.yml diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml new file mode 100644 index 000000000..e2307455e --- /dev/null +++ b/.github/workflows/safety.yml @@ -0,0 +1,15 @@ +--- +name: safety + +on: push # yamllint disable-line rule:truthy + +jobs: + safety: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: pip install -U safety + - name: Check dependencies for known security vulterabilities using Safety + run: safety check From 1205cd64e105cda87776c8387c9bbbb63f0a2c15 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:19:36 +0300 Subject: [PATCH 20/28] Remove old traces of running Safety --- .github/workflows/python-package.yml | 2 -- constraints-oldest.txt | 1 - setup.cfg | 1 - 3 files changed, 4 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9d867298f..1659844c0 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -123,5 +123,3 @@ jobs: retval = run(pytest_cmd).returncode run(["git", "restore", "pyproject.toml"]) sys.exit(retval) - - name: Check dependencies for known security vulterabilities using Safety - run: safety check diff --git a/constraints-oldest.txt b/constraints-oldest.txt index 158d1d6dc..518ca7479 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -17,7 +17,6 @@ pytest-kwparametrize==0.0.3 regex==2021.4.4 requests_cache==0.7 ruamel.yaml==0.17.21 -safety==1.10.3 toml==0.10.0 twine==2.0.0 types-toml==0.10.4 diff --git a/setup.cfg b/setup.cfg index b781ab241..7a3be8c2d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,7 +63,6 @@ test = regex>=2021.4.4 requests_cache>=0.7 ruamel.yaml>=0.17.21 - safety>=1.10.3 twine>=2.0.0 types-requests>=2.27.9 types-toml>=0.10.4 From 63f5e1d79745c9a96e4148bd49bd1e8e794eac3a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:35:27 +0300 Subject: [PATCH 21/28] Run Pylint in a separate workflow --- .github/workflows/pylint.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 000000000..2e4419f24 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,18 @@ +--- +name: pylint + +on: push # yamllint disable-line rule:truthy + +jobs: + pylint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - run: pip install pylint + - uses: wearerequired/lint-action@v2.0.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + pylint: true + continue_on_error: false From 47194465a109a6d7f6c02446db1bd56b2531aeb0 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:42:06 +0300 Subject: [PATCH 22/28] Remove old traces of running Pylint --- .github/workflows/python-package.yml | 25 ++----------------------- constraints-oldest.txt | 1 - pyproject.toml | 3 --- setup.cfg | 1 - 4 files changed, 2 insertions(+), 28 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 1659844c0..a2ff05034 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -59,7 +59,6 @@ jobs: - '3.9' - '3.10' constraints: [''] - lint: ['--darker'] include: - os: ubuntu-latest python-version: '3.7' @@ -68,9 +67,6 @@ jobs: python-version: '3.10' constraints: '--constraint constraints-future.txt' upgrade: '--upgrade --upgrade-strategy=eager' - env: - RUN_PYLINT: >- - ${{ matrix.python-version == '3.9' || matrix.python-version == '3.10' }} steps: - uses: actions/checkout@v3 with: @@ -103,23 +99,6 @@ jobs: pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }} run: pip install ${pip_options} "dist/darker-${{ env.VERSION }}-py3-none-any.whl[test]" - - name: Run Pytest without Pylint if Python < 3.9 - if: env.RUN_PYLINT == 'false' + - name: Run Pytest run: | - pytest ${{ matrix.lint }} - - name: Run Pytest with Pylint if Python >= 3.9 - if: env.RUN_PYLINT == 'true' - shell: python - run: | - import sys - from pathlib import Path - from subprocess import run - import toml - - data = toml.load("pyproject.toml") - data["tool"]["darker"]["lint"] = ["pylint"] - Path("pyproject.toml").write_text(toml.dumps(data)) - pytest_cmd = ["pytest"] + "${{ matrix.lint }}".split() - retval = run(pytest_cmd).returncode - run(["git", "restore", "pyproject.toml"]) - sys.exit(retval) + pytest --darker diff --git a/constraints-oldest.txt b/constraints-oldest.txt index 518ca7479..48aa296a2 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -11,7 +11,6 @@ flake8-bugbear==22.1.11 flake8-comprehensions==3.7.0 mypy==0.940 Pygments==2.4.0 -pylint==2.13.0 pytest==6.2.0 pytest-kwparametrize==0.0.3 regex==2021.4.4 diff --git a/pyproject.toml b/pyproject.toml index 23d5b00af..5e49fb85a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,3 @@ src = [ "src", ] revision = "origin/master..." -# The empty linter list is here so `.github/workflows/python-package.yml` can -# add Pylint in certain run configurations: -lint = [] diff --git a/setup.cfg b/setup.cfg index 7a3be8c2d..3198bc0f9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,7 +56,6 @@ test = isort>=5.0.1 mypy>=0.940 pygments - pylint>=2.13.0 pytest>=6.2.0 pytest-darker pytest-kwparametrize>=0.0.3 From c93aabc430676771941c1a0639f9b10ee0ba83fa Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 21:32:02 +0300 Subject: [PATCH 23/28] Build Darker distributions only one Use artifact upload/download to share them between jobs --- .github/workflows/python-package.yml | 75 ++++++++++++++++++---------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a2ff05034..e81432a0b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -12,6 +12,42 @@ on: # yamllint disable-line rule:truthy jobs: + build: + runs-on: ubuntu-latest + outputs: + darker-wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v3 + - name: Upgrade pip, install wheel and twine + run: | + # strict dependency resolution added in pip 20.3 + python -m pip install --upgrade 'pip>=20.3' wheel twine + - name: Build source distribution + run: python setup.py sdist + - name: Build wheel distribution + run: python setup.py bdist_wheel + - name: Validate distributions + run: twine check dist/* + - name: Upload distributions for test jobs + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/ + if-no-files-found: error + - name: Find out Darker version and output it for test jobs + id: get-darker-version + shell: python + run: | + from runpy import run_path + version = run_path("src/darker/version.py")["__version__"] + print( + "::set-output name=wheel-path::" + f"dist/darker-{version}-py3-none-any.whl" + ) + test-nixos: runs-on: ${{ matrix.os }} strategy: @@ -23,13 +59,15 @@ jobs: - os: macos-latest python-version: python39 # see https://github.com/cachix/install-nix-action/issues/135 + needs: + - build steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - uses: cachix/install-nix-action@v17 with: nix_path: nixpkgs=channel:nixos-21.11 + - name: Download distributions made by the build job + uses: actions/download-artifact@v3 - name: Run tests in nix-shell run: | nix-shell \ @@ -38,13 +76,12 @@ jobs: --run ' python -m venv venv source venv/bin/activate - pip install -e '.[test]' + pip install "${{needs.build.outputs.darker-wheel-path}}[test]" pytest ' \ ./default.nix - build: - + test: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -67,38 +104,24 @@ jobs: python-version: '3.10' constraints: '--constraint constraints-future.txt' upgrade: '--upgrade --upgrade-strategy=eager' + needs: + - build steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - + # need full history since Pytest runs Darker itself below - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - - name: Upgrade pip, install wheel and twine - run: | - # strict dependency resolution added in pip 20.3 - python -m pip install --upgrade 'pip>=20.3' wheel twine - - name: Build source distribution - run: python setup.py sdist - - name: Build wheel distribution - run: python setup.py bdist_wheel - - name: Validate distributions - run: twine check dist/* - - name: Get Darker version - shell: python - run: | - from os import environ - from pathlib import Path - from runpy import run_path - version = run_path("src/darker/version.py")["__version__"] - Path(environ["GITHUB_ENV"]).write_text(f"VERSION={version}\n") - - name: Install Darker and its dependencies + - name: Download distributions made by the build job + uses: actions/download-artifact@v3 + - name: Install Darker and its dependencies from the wheel build earlier env: pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }} run: pip install ${pip_options} - "dist/darker-${{ env.VERSION }}-py3-none-any.whl[test]" + "${{needs.build.outputs.darker-wheel-path}}[test]" - name: Run Pytest run: | pytest --darker From 0f9426c3f8edf182f68e37a584cda59e258c618a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 21:45:25 +0300 Subject: [PATCH 24/28] Separate sdist build and dist validation job --- .github/workflows/python-package.yml | 48 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e81432a0b..bf7bda87e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,5 +1,5 @@ --- -name: build +name: Build and test on: # yamllint disable-line rule:truthy push: @@ -12,26 +12,18 @@ on: # yamllint disable-line rule:truthy jobs: - build: + build-wheel: runs-on: ubuntu-latest outputs: - darker-wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }} + wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }} steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - uses: actions/setup-python@v3 - - name: Upgrade pip, install wheel and twine - run: | - # strict dependency resolution added in pip 20.3 - python -m pip install --upgrade 'pip>=20.3' wheel twine - - name: Build source distribution - run: python setup.py sdist + - name: Install wheel + run: python -m pip install wheel - name: Build wheel distribution run: python setup.py bdist_wheel - - name: Validate distributions - run: twine check dist/* - - name: Upload distributions for test jobs + - name: Upload wheel for other jobs uses: actions/upload-artifact@v3 with: name: dist @@ -60,13 +52,13 @@ jobs: python-version: python39 # see https://github.com/cachix/install-nix-action/issues/135 needs: - - build + - build-wheel steps: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v17 with: nix_path: nixpkgs=channel:nixos-21.11 - - name: Download distributions made by the build job + - name: Download wheel uploaded by the build-wheel job uses: actions/download-artifact@v3 - name: Run tests in nix-shell run: | @@ -76,7 +68,7 @@ jobs: --run ' python -m venv venv source venv/bin/activate - pip install "${{needs.build.outputs.darker-wheel-path}}[test]" + pip install "${{needs.build-wheel.outputs.wheel-path}}[test]" pytest ' \ ./default.nix @@ -105,7 +97,7 @@ jobs: constraints: '--constraint constraints-future.txt' upgrade: '--upgrade --upgrade-strategy=eager' needs: - - build + - build-wheel steps: - uses: actions/checkout@v3 with: @@ -115,13 +107,29 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - - name: Download distributions made by the build job + - name: Download wheel uploaded by the build-wheel job uses: actions/download-artifact@v3 - name: Install Darker and its dependencies from the wheel build earlier env: pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }} run: pip install ${pip_options} - "${{needs.build.outputs.darker-wheel-path}}[test]" + "${{needs.build-wheel.outputs.wheel-path}}[test]" - name: Run Pytest run: | pytest --darker + + build-sdist-validate-dists: + runs-on: ubuntu-latest + needs: + - build-wheel + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - name: Install twine + run: python -m pip install twine + - name: Download wheel uploaded by the build-wheel job + uses: actions/download-artifact@v3 + - name: Build source distribution + run: python setup.py sdist + - name: Validate distributions + run: twine check dist/* From ede1f34b38bdd49aa77b1133325d3a550d607579 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 22:01:05 +0300 Subject: [PATCH 25/28] Update isort lint-action --- .github/workflows/isort.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/isort.yml b/.github/workflows/isort.yml index 0f58fcd1f..241a17507 100644 --- a/.github/workflows/isort.yml +++ b/.github/workflows/isort.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - run: pip install 'isort>=5.0.1' - - uses: Gobot1234/lint-action@v.1.8.2 + - uses: wearerequired/lint-action@v2.0.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} isort: true From 0b566687e88c19aa3f70284f5e535f18119e84fb Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 22:02:52 +0300 Subject: [PATCH 26/28] Typo in `safety.yml` --- .github/workflows/safety.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml index e2307455e..da8b8ecc8 100644 --- a/.github/workflows/safety.yml +++ b/.github/workflows/safety.yml @@ -11,5 +11,5 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - run: pip install -U safety - - name: Check dependencies for known security vulterabilities using Safety + - name: Check dependencies for known security vulnerabilities using Safety run: safety check From 678b36e295f9f26d5ebfa54efa1582a85931767a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 22:05:28 +0300 Subject: [PATCH 27/28] Update change log --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 050c7cfaf..5c36d3d75 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,7 +7,7 @@ Added ----- - Add a CI workflow which verifies that the ``darker --help`` output in ``README.rst`` is up to date. -- Only run ``isort`` and ``flake8`` once in the CI build. +- Only run linters, security checks and package builds once in the CI build. Fixed ----- From 74eb9aea1f6428cb959c7162ccc772e2356a96c8 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 28 Aug 2022 22:06:50 +0300 Subject: [PATCH 28/28] Remove `mypy` from dependencies --- constraints-oldest.txt | 1 - setup.cfg | 1 - 2 files changed, 2 deletions(-) diff --git a/constraints-oldest.txt b/constraints-oldest.txt index 48aa296a2..b639e274e 100644 --- a/constraints-oldest.txt +++ b/constraints-oldest.txt @@ -9,7 +9,6 @@ defusedxml==0.7.1 flake8-2020==1.6.1 flake8-bugbear==22.1.11 flake8-comprehensions==3.7.0 -mypy==0.940 Pygments==2.4.0 pytest==6.2.0 pytest-kwparametrize==0.0.3 diff --git a/setup.cfg b/setup.cfg index 3198bc0f9..b4b4c5b63 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,6 @@ test = black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189 defusedxml>=0.7.1 isort>=5.0.1 - mypy>=0.940 pygments pytest>=6.2.0 pytest-darker