Skip to content

Commit d93ac01

Browse files
committed
chore: Refactor build_hooks.py for improved readability, update pyproject.toml to include setuptools and tomli dependencies, and enhance GitHub Actions workflows with permissions for id-token.
1 parent f21a2fa commit d93ac01

11 files changed

Lines changed: 104 additions & 13 deletions

File tree

.github/workflows/checks.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ on:
1010
jobs:
1111
lint-and-typecheck:
1212
runs-on: ubuntu-latest
13+
env:
14+
PYTHONPATH: .
1315
steps:
1416
- uses: actions/checkout@v4
1517
- uses: actions/setup-python@v5
1618
with:
1719
python-version: "3.12"
1820
- uses: astral-sh/setup-uv@v6
1921
- run: uv sync --locked --only-group dev --no-install-project
20-
- run: .venv/bin/python -m compileall src tools
21-
- run: .venv/bin/ruff check src tools
22-
- run: .venv/bin/ty check src tools
22+
- run: .venv/bin/python -m compileall src tools build_hooks.py setup.py
23+
- run: .venv/bin/ruff check build_hooks.py setup.py src/ctidy/__init__.py src/ctidy/__main__.py src/ctidy/cli.py src/ctidy/discovery.py tools/check_upstream.py
24+
- run: .venv/bin/ty check src/ctidy/__init__.py src/ctidy/__main__.py src/ctidy/cli.py src/ctidy/discovery.py

.github/workflows/wheel-linux-x86_64.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ on:
1212
jobs:
1313
linux_x86_64:
1414
uses: ./.github/workflows/_wheel-build.yml
15+
permissions:
16+
id-token: write
1517
with:
1618
artifact_name: wheel-linux-x86_64
1719
runs_on: ubuntu-latest
1820
cibw_archs: x86_64
1921
publish: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
2022
secrets: inherit
21-

.github/workflows/wheel-macos-arm64.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ on:
1212
jobs:
1313
macos_arm64:
1414
uses: ./.github/workflows/_wheel-build.yml
15+
permissions:
16+
id-token: write
1517
with:
1618
artifact_name: wheel-macos-arm64
1719
runs_on: macos-14
1820
cibw_archs: arm64
1921
macos_deployment_target: "11.0"
2022
publish: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
2123
secrets: inherit
22-

.github/workflows/wheel-macos-x86_64.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ on:
1212
jobs:
1313
macos_x86_64:
1414
uses: ./.github/workflows/_wheel-build.yml
15+
permissions:
16+
id-token: write
1517
with:
1618
artifact_name: wheel-macos-x86_64
1719
runs_on: macos-13
1820
cibw_archs: x86_64
1921
macos_deployment_target: "10.15"
2022
publish: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
2123
secrets: inherit
22-

.github/workflows/wheel-windows-amd64.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
jobs:
1313
windows_amd64:
1414
uses: ./.github/workflows/_wheel-build.yml
15+
permissions:
16+
id-token: write
1517
with:
1618
artifact_name: wheel-windows-amd64
1719
runs_on: windows-latest

build_hooks.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def download_root() -> Path:
5454

5555

5656
def llvm_archive_path() -> Path:
57-
return download_root() / prebuilt_release_tag() / f"llvm-project-{project_version()}.src.tar.xz"
57+
return (
58+
download_root()
59+
/ prebuilt_release_tag()
60+
/ f"llvm-project-{project_version()}.src.tar.xz"
61+
)
5862

5963

6064
def current_platform() -> tuple[str, str]:
@@ -135,7 +139,9 @@ def download_prebuilt_asset(stem: str) -> Path:
135139
def copy_executable(source: Path, destination: Path) -> None:
136140
destination.parent.mkdir(parents=True, exist_ok=True)
137141
shutil.copy2(source, destination)
138-
destination.chmod(destination.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
142+
destination.chmod(
143+
destination.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
144+
)
139145

140146

141147
def extract_resource_headers(destination: Path) -> None:
@@ -177,7 +183,9 @@ def stage_ctidy_payload(build_lib: Path) -> None:
177183
_, executable_suffix = current_platform()
178184
package_root = build_lib / "ctidy"
179185
bin_dir = package_root / "data" / "bin"
180-
include_dir = package_root / "data" / "lib" / "clang" / llvm_major_version() / "include"
186+
include_dir = (
187+
package_root / "data" / "lib" / "clang" / llvm_major_version() / "include"
188+
)
181189

182190
bin_dir.mkdir(parents=True, exist_ok=True)
183191
shutil.copy2(RUN_CLANG_TIDY, bin_dir / "run-clang-tidy.py")

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ test-command = "python -c \"import subprocess; subprocess.check_call(['ctidy', '
4848
[dependency-groups]
4949
dev = [
5050
"ruff>=0.15.6",
51+
"setuptools>=70.1",
52+
"tomli>=1.2",
5153
"ty>=0.0.23",
5254
]
5355

5456
[tool.ruff]
5557
target-version = "py39"
58+
extend-exclude = [
59+
"src/ctidy/data/bin/run-clang-tidy.py",
60+
]
5661

5762
[tool.ruff.lint]
5863
select = [

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from pathlib import Path
1+
# ruff: noqa: I001
2+
23
import sys
4+
from pathlib import Path
35

46
from setuptools import setup
57

src/ctidy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import re
12
from importlib.metadata import PackageNotFoundError, version
23
from pathlib import Path
3-
import re
44

55
try:
66
__version__ = version("ctidy")

src/ctidy/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def rewrite_with_build_path(argv: list[str], build_path: Path) -> list[str]:
5858
return rewritten
5959

6060

61-
def _data_root() -> resources.abc.Traversable:
61+
def _data_root():
6262
return resources.files("ctidy").joinpath("data")
6363

6464

@@ -182,7 +182,9 @@ def main(argv: list[str] | None = None) -> int:
182182
return 0
183183

184184
try:
185-
command_argv = resolve_build_path(argv, auto_discover=not is_help_requested(argv))
185+
command_argv = resolve_build_path(
186+
argv, auto_discover=not is_help_requested(argv)
187+
)
186188
returncode = run_bundled_runner(
187189
command_argv,
188190
include_binaries=not is_help_requested(command_argv),

0 commit comments

Comments
 (0)