From aac78b37fba8429b8ca5e0695c2030d5b4b15345 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:32:50 +0300 Subject: [PATCH 01/15] ci: build wheel using uv Might also solve the pip problem with Ubuntu 24.04 on GitHub --- .github/workflows/python-package.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 7e6a25c6f..ff27b8ad5 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -20,11 +20,11 @@ jobs: wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }} steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 - - name: Install wheel - run: python -m pip install wheel - name: Build wheel distribution - run: python setup.py bdist_wheel + run: uv build --wheel - name: Upload wheel for other jobs uses: actions/upload-artifact@v4 with: From 9de6541d948381acc6326e8fc0775002362df3a0 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:07:36 +0300 Subject: [PATCH 02/15] ci: run flake8 with non system python Works around error: externally-managed-environment on Ubuntu 24.04 --- .github/workflows/flake8.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index f689082d1..06499c211 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -9,6 +9,9 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x - uses: TrueBrain/actions-flake8@v2 with: plugins: > From 7ba1e10243da088068759e9cd04f29d94473f323 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:10:35 +0300 Subject: [PATCH 03/15] ci: run darkgray_bump_version using uvx --- .github/workflows/test-bump-version.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-bump-version.yml b/.github/workflows/test-bump-version.yml index 4cf90af6b..d02b0af4e 100644 --- a/.github/workflows/test-bump-version.yml +++ b/.github/workflows/test-bump-version.yml @@ -9,6 +9,8 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 - name: Make sure that `darkgray_bump_version` still finds all version strings @@ -20,9 +22,7 @@ jobs: # This is used to update the call for reviewing pull requests # in `README.rst`. run: | - pip install \ - https://github.com/akaihola/darkgray-dev-tools/archive/refs/heads/main.zip - darkgray_bump_version \ + uvx --from=darkgray-dev-tools darkgray_bump_version \ --minor \ --dry-run \ --token=${{ secrets.GITHUB_TOKEN }} From 0f2e0b65dde475cf1821ec525bf5ce9d1e7baaec Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:14:27 +0300 Subject: [PATCH 04/15] ci: in README verification, install Darker using uvx --- .github/workflows/help-in-readme.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/help-in-readme.yml b/.github/workflows/help-in-readme.yml index 69551ec64..2b70097fc 100644 --- a/.github/workflows/help-in-readme.yml +++ b/.github/workflows/help-in-readme.yml @@ -6,6 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: pip install '.[flynt,isort]' + - name: Install uv + uses: astral-sh/setup-uv@v3 - name: Verify that README contains output of darker --help - run: darker --verify-readme + run: uvx --from '.[flynt,isort]' darker --verify-readme From c82353449e4d5ced7ce5715dd5cb80bcf9867b45 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:15:50 +0300 Subject: [PATCH 05/15] ci: run isort with non system python Works around error: externally-managed-environment on Ubuntu 24.04 --- .github/workflows/isort.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/isort.yml b/.github/workflows/isort.yml index 32c156289..5124fd313 100644 --- a/.github/workflows/isort.yml +++ b/.github/workflows/isort.yml @@ -10,6 +10,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: 3.x - run: pip install 'isort>=5.0.1' - uses: wearerequired/lint-action@v2.3.0 with: From fd6eae167409f7736658edf34007d982a2b10439 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:16:32 +0300 Subject: [PATCH 06/15] ci: run mypy with non system python Works around error: externally-managed-environment on Ubuntu 24.04 --- .github/workflows/mypy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 8545afa59..d4ebc3786 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -10,6 +10,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: 3.x - run: | pip install -U \ black \ From 5070e3ac759a1b77635b5e22bafaf372dbb26cc0 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:16:59 +0300 Subject: [PATCH 07/15] ci: run pylint with non system python Works around error: externally-managed-environment on Ubuntu 24.04 --- .github/workflows/pylint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 72f53dcd1..07cbea7dc 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -10,6 +10,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: 3.x - name: Install dependencies for running Pylint run: | pip install -U \ From 5ff963010f25fdfc106f317228e213609629de88 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:20:05 +0300 Subject: [PATCH 08/15] ci: in pyupgrade workflow, install pyupgrade using uvx --- .github/workflows/pyupgrade.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pyupgrade.yml b/.github/workflows/pyupgrade.yml index 0273248ec..22af5bbdf 100644 --- a/.github/workflows/pyupgrade.yml +++ b/.github/workflows/pyupgrade.yml @@ -9,12 +9,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 - - 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 " + uvx --from pyupgrade python -c " import sys from pyupgrade._main import main from glob import glob From dadd13f015283f9bb32bc2c277e244668134e006 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:21:57 +0300 Subject: [PATCH 09/15] ci: in safety workflow, install pip-tools and safety using uvx --- .github/workflows/safety.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml index 4aab1bfd4..1d4d567c0 100644 --- a/.github/workflows/safety.yml +++ b/.github/workflows/safety.yml @@ -9,9 +9,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 - - run: pip install -U pip-tools - - run: pip-compile setup.cfg - - run: pip install -U safety + - run: uvx --from pip-tools pip-compile setup.cfg - name: Check dependencies for known security vulnerabilities using Safety - run: safety check --file requirements.txt + run: uvx safety check --file requirements.txt From 86f29f24a5659a3adb6a396857044dde4093df5e Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:23:40 +0300 Subject: [PATCH 10/15] ci: use 'uv build' to build the source distribution --- .github/workflows/python-package.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ff27b8ad5..96e4cd6e5 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -146,12 +146,12 @@ jobs: - build-wheel steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 - - name: Install twine - run: python -m pip install twine - name: Download wheel uploaded by the build-wheel job uses: actions/download-artifact@v4.1.7 - name: Build source distribution - run: python setup.py sdist + run: uv build --sdist - name: Validate distributions - run: twine check dist/* + run: uvx twine check dist/* From 9c33fc1aacdb0b0a5afd4a2b6451e4039a302b57 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:32:33 +0300 Subject: [PATCH 11/15] ci: use 'uv install' to install pylint dependencies --- .github/workflows/pylint.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 07cbea7dc..f22c1b532 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -9,12 +9,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 with: python-version: 3.x - name: Install dependencies for running Pylint run: | - pip install -U \ + uv pip install --system -U \ black \ git+https://github.com/akaihola/darkgraylib.git@main \ defusedxml \ @@ -26,7 +28,7 @@ jobs: requests-cache \ ruamel.yaml \ toml - pip list + uv pip list --system - uses: wearerequired/lint-action@v2.3.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} From 3170022acdd15de565f3aebbdc0fc5167604085d Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:32:50 +0300 Subject: [PATCH 12/15] ci: install setuptools for pylint --- .github/workflows/pylint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index f22c1b532..7005eb088 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -27,6 +27,7 @@ jobs: requests \ requests-cache \ ruamel.yaml \ + setuptools \ toml uv pip list --system - uses: wearerequired/lint-action@v2.3.0 From 46966ec725edd8c13c752b074dfb98bf63d6ee98 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:59:13 +0300 Subject: [PATCH 13/15] ci: use uv to install Mypy dependencies --- .github/workflows/mypy.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index d4ebc3786..dd60081f6 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -9,11 +9,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 - uses: actions/setup-python@v5 with: python-version: 3.x - run: | - pip install -U \ + uv pip install --system -U \ black \ git+https://github.com/akaihola/darkgraylib.git@main \ flynt \ From f29d7f6e7d9754411e10aa79155a0d22d55a3c77 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Wed, 16 Oct 2024 21:43:29 +0200 Subject: [PATCH 14/15] ci: use my forked lint-action with isort support --- .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 5124fd313..49fcf95a7 100644 --- a/.github/workflows/isort.yml +++ b/.github/workflows/isort.yml @@ -13,7 +13,7 @@ jobs: with: python-version: 3.x - run: pip install 'isort>=5.0.1' - - uses: wearerequired/lint-action@v2.3.0 + - uses: akaihola/lint-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} isort: true From ac51fd030669d28a18f9d3a60c6ef55c9be7650a Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:30:54 +0200 Subject: [PATCH 15/15] test: satisfy updated linters --- src/darker/black_diff.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/darker/black_diff.py b/src/darker/black_diff.py index b9c106648..a47db055e 100644 --- a/src/darker/black_diff.py +++ b/src/darker/black_diff.py @@ -32,10 +32,12 @@ based on whether reformats touch user-edited lines """ + +from __future__ import annotations + import inspect import logging -from pathlib import Path -from typing import Collection, Optional, Pattern, Set, Tuple, TypedDict, Union +from typing import TYPE_CHECKING, Collection, Pattern, TypedDict # `FileMode as Mode` required to satisfy mypy==0.782. Strange. from black import FileMode as Mode @@ -56,6 +58,9 @@ from darkgraylib.config import ConfigurationError from darkgraylib.utils import TextDocument +if TYPE_CHECKING: + from pathlib import Path + __all__ = ["BlackConfig", "Mode", "run_black"] logger = logging.getLogger(__name__) @@ -69,10 +74,10 @@ class BlackConfig(TypedDict, total=False): """Type definition for Black configuration dictionaries""" config: str - exclude: Pattern[str] - extend_exclude: Pattern[str] - force_exclude: Pattern[str] - target_version: Union[str, Set[str]] + exclude: Pattern[str] | None + extend_exclude: Pattern[str] | None + force_exclude: Pattern[str] | None + target_version: str | set[str] line_length: int skip_string_normalization: bool skip_magic_trailing_comma: bool @@ -82,7 +87,7 @@ class BlackConfig(TypedDict, total=False): class BlackModeAttributes(TypedDict, total=False): """Type definition for items accepted by ``black.Mode``""" - target_versions: Set[TargetVersion] + target_versions: set[TargetVersion] line_length: int string_normalization: bool is_pyi: bool @@ -90,7 +95,7 @@ class BlackModeAttributes(TypedDict, total=False): preview: bool -def read_black_config(src: Tuple[str, ...], value: Optional[str]) -> BlackConfig: +def read_black_config(src: tuple[str, ...], value: str | None) -> BlackConfig: """Read the black configuration from ``pyproject.toml`` :param src: The source code files and directories to be processed by Darker @@ -136,7 +141,7 @@ def filter_python_files( paths: Collection[Path], # pylint: disable=unsubscriptable-object root: Path, black_config: BlackConfig, -) -> Set[Path]: +) -> set[Path]: """Get Python files and explicitly listed files not excluded by Black's config :param paths: Relative file/directory paths from CWD to Python sources @@ -164,7 +169,7 @@ def filter_python_files( directories, root, include=DEFAULT_INCLUDE_RE, - exclude=black_config.get("exclude", DEFAULT_EXCLUDE_RE), + exclude=black_config.get("exclude") or DEFAULT_EXCLUDE_RE, extend_exclude=black_config.get("extend_exclude"), force_exclude=black_config.get("force_exclude"), report=Report(),