Skip to content

Commit

Permalink
Merge pull request #756 from akaihola/ubuntu-24-build-wheel
Browse files Browse the repository at this point in the history
Use uv and/or non system Python in CI workflows
  • Loading branch information
akaihola authored Oct 17, 2024
2 parents f8f8d6c + ac51fd0 commit 7ef2fbd
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/help-in-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ 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
- uses: akaihola/lint-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
isort: true
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +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 \
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +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 \
Expand All @@ -23,8 +27,9 @@ jobs:
requests \
requests-cache \
ruamel.yaml \
setuptools \
toml
pip list
uv pip list --system
- uses: wearerequired/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/[email protected]
- 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/*
5 changes: 3 additions & 2 deletions .github/workflows/pyupgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/safety.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/test-bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
25 changes: 15 additions & 10 deletions src/darker/black_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)
Expand All @@ -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
Expand All @@ -82,15 +87,15 @@ 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
magic_trailing_comma: bool
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 7ef2fbd

Please sign in to comment.