chore: add pathlib check

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2025-02-28 16:38:15 -05:00
committed by Henry Schreiner
parent 3e37148923
commit 783be9bc2f
6 changed files with 20 additions and 19 deletions
+1 -2
View File
@@ -7,7 +7,6 @@
from __future__ import annotations from __future__ import annotations
import glob
import os import os
import subprocess import subprocess
import sys import sys
@@ -86,7 +85,7 @@ def bump_version() -> None:
actions = [] actions = []
for path_pattern, version_pattern in config: for path_pattern, version_pattern in config:
paths = [Path(p) for p in glob.glob(path_pattern)] paths = list(Path().glob(path_pattern))
if not paths: if not paths:
print(f"error: Pattern {path_pattern} didn't match any files") print(f"error: Pattern {path_pattern} didn't match any files")
+1 -1
View File
@@ -56,7 +56,7 @@ def main() -> None:
f""" f"""
Update the versions of our dependencies. Update the versions of our dependencies.
PR generated by `{os.path.basename(__file__)}`. PR generated by `{Path(__file__).name}`.
""" """
) )
subprocess.run( subprocess.run(
+10 -12
View File
@@ -9,12 +9,13 @@ import sys
import textwrap import textwrap
import time import time
import typing import typing
from glob import glob
from pathlib import Path from pathlib import Path
from urllib.parse import quote from urllib.parse import quote
import click import click
DIR = Path(__file__).parent.resolve()
def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]: def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]:
return subprocess.run([cmd], shell=True, check=check, **kwargs) # type: ignore[call-overload, no-any-return] return subprocess.run([cmd], shell=True, check=check, **kwargs) # type: ignore[call-overload, no-any-return]
@@ -79,9 +80,8 @@ services = [
] ]
def ci_service_for_config_file(config_file: str) -> CIService: def ci_service_for_config_file(config_file: Path) -> CIService:
filename = Path(config_file).name filename = config_file.name
try: try:
return next(s for s in services if filename.startswith(s.name)) return next(s for s in services if filename.startswith(s.name))
except StopIteration: except StopIteration:
@@ -98,16 +98,16 @@ def run_example_ci_configs(config_files=None):
""" """
if len(config_files) == 0: if len(config_files) == 0:
config_files = glob("examples/*-minimal.yml") config_files = Path("examples").glob("*-minimal.yml")
# check each CI service has at most 1 config file # check each CI service has at most 1 config file
configs_by_service = {} configs_by_service = set()
for config_file in config_files: for config_file in config_files:
service = ci_service_for_config_file(config_file) service = ci_service_for_config_file(config_file)
if service.name in configs_by_service: if service.name in configs_by_service:
msg = "You cannot specify more than one config per CI service" msg = "You cannot specify more than one config per CI service"
raise Exception(msg) raise Exception(msg)
configs_by_service[service.name] = config_file configs_by_service.add(service.name)
if git_repo_has_changes(): if git_repo_has_changes():
print("Your git repo has uncommitted changes. Commit or stash before continuing.") print("Your git repo has uncommitted changes. Commit or stash before continuing.")
@@ -128,18 +128,17 @@ def run_example_ci_configs(config_files=None):
for config_file in config_files: for config_file in config_files:
service = ci_service_for_config_file(config_file) service = ci_service_for_config_file(config_file)
src_config_file = Path(config_file)
dst_config_file = example_project / service.dst_config_path dst_config_file = example_project / service.dst_config_path
dst_config_file.parent.mkdir(parents=True, exist_ok=True) dst_config_file.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(src_config_file, dst_config_file) shutil.copyfile(config_file, dst_config_file)
subprocess.run(["git", "add", example_project], check=True) subprocess.run(["git", "add", example_project], check=True)
message = textwrap.dedent( message = textwrap.dedent(
f"""\ f"""\
Test example minimal configs Test example minimal configs
Testing files: {config_files} Testing files: {[str(f) for f in config_files]}
Generated from branch: {previous_branch} Generated from branch: {previous_branch}
Time: {timestamp} Time: {timestamp}
""" """
@@ -174,6 +173,5 @@ def run_example_ci_configs(config_files=None):
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.dirname(__file__)) os.chdir(DIR)
os.chdir("..")
run_example_ci_configs(standalone_mode=True) run_example_ci_configs(standalone_mode=True)
+1 -1
View File
@@ -292,7 +292,7 @@ def build(options: Options, tmp_path: Path) -> None:
# directory. # directory.
oldmounts = "" oldmounts = ""
extra_mounts = [str(identifier_tmp_dir)] extra_mounts = [str(identifier_tmp_dir)]
if str(Path.cwd()).startswith("/tmp"): if Path.cwd().is_relative_to("/tmp"):
extra_mounts.append(str(Path.cwd())) extra_mounts.append(str(Path.cwd()))
if "_PYODIDE_EXTRA_MOUNTS" in env: if "_PYODIDE_EXTRA_MOUNTS" in env:
+4 -1
View File
@@ -190,6 +190,7 @@ extend-select = [
"PIE", # flake8-pie "PIE", # flake8-pie
"PL", # pylint "PL", # pylint
"PT", # flake8-pytest-style "PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return "RET", # flake8-return
"RUF", # Ruff-specific "RUF", # Ruff-specific
"SIM", # flake8-simplify "SIM", # flake8-simplify
@@ -206,6 +207,7 @@ ignore = [
"PYI025", # Set as AbstractSet "PYI025", # Set as AbstractSet
"ISC001", # Conflicts with formatter "ISC001", # Conflicts with formatter
"EXE003", # Ruff doesn't like uv? "EXE003", # Ruff doesn't like uv?
"PTH123", # open -> Path.open
] ]
flake8-unused-arguments.ignore-variadic-names = true flake8-unused-arguments.ignore-variadic-names = true
@@ -219,9 +221,10 @@ flake8-unused-arguments.ignore-variadic-names = true
[tool.ruff.lint.per-file-ignores] [tool.ruff.lint.per-file-ignores]
"unit_test/*" = ["PLC1901"] "unit_test/*" = ["PLC1901"]
"bin/*" = ["TID251"] "bin/*" = ["TID251"]
"cibuildwheel/resources/install_certifi.py" = ["PTH"]
[tool.repo-review] [tool.repo-review]
ignore = ["PC170", "PP303"] ignore = ["PC170", "PP303"]
[tool.check-wheel-contents] [tool.check-wheel-contents]
ignore = ["W002"] # requirements-*.txt are allowed to be duplicates of one another ignore = ["W002"] # constraints-*.txt are allowed to be duplicates of one another
+3 -2
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import os import os
import subprocess import subprocess
import textwrap import textwrap
from pathlib import Path
import pytest import pytest
@@ -16,8 +17,8 @@ def skip_if_no_msvc(arm64: bool = False) -> None:
if not programfiles: if not programfiles:
pytest.skip("Requires %PROGRAMFILES(X86)% variable to be set") pytest.skip("Requires %PROGRAMFILES(X86)% variable to be set")
vswhere = os.path.join(programfiles, "Microsoft Visual Studio", "Installer", "vswhere.exe") vswhere = Path(programfiles, "Microsoft Visual Studio", "Installer", "vswhere.exe")
if not os.path.isfile(vswhere): if not vswhere.is_file():
pytest.skip("Requires Visual Studio installation") pytest.skip("Requires Visual Studio installation")
require = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" require = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"