Skip to content

Commit

Permalink
Update ruff and typing
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Dec 1, 2023
1 parent 73e9959 commit 488c306
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
12 changes: 6 additions & 6 deletions .github/actions/check-links/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check_links(ignore_glob: list[str], ignore_links: list[str], links_expire: s
ignored = []
for spec in ignore_glob:
cmd += f' --ignore-glob "{spec}"'
ignored.extend(glob(spec, recursive=True))
ignored.extend(glob(spec, recursive=True)) # noqa: PTH207

ignore_links = [
*list(ignore_links),
Expand All @@ -48,7 +48,7 @@ def check_links(ignore_glob: list[str], ignore_links: list[str], links_expire: s
# Gather all of the markdown, RST, and ipynb files
files: list[str] = []
for ext in [".md", ".rst", ".ipynb"]:
matched = glob(f"**/*{ext}", recursive=True)
matched = glob(f"**/*{ext}", recursive=True) # noqa: PTH207
files.extend(m for m in matched if m not in ignored and "node_modules" not in m)

separator = f"\n\n{'-' * 80}\n"
Expand All @@ -61,17 +61,17 @@ def check_links(ignore_glob: list[str], ignore_links: list[str], links_expire: s
file_cmd = shlex.split(file_cmd_str)
try:
log(f"{separator}{f}...")
subprocess.check_output(file_cmd, shell=False) # noqa S603
subprocess.check_output(file_cmd, shell=False) # noqa: S603
except Exception as e:
# Return code 5 means no tests were run (no links found)
if e.returncode != 5: # type:ignore[attr-defined] # noqa
if e.returncode != 5: # type:ignore[attr-defined]
try:
log(f"\n{f} (second attempt)...\n")
subprocess.check_output([*file_cmd, "--lf"], shell=False) # noqa S603
subprocess.check_output([*file_cmd, "--lf"], shell=False) # noqa: S603
except subprocess.CalledProcessError as e:
log(e.output.decode("utf-8"))
fails += 1
if fails == 3: # noqa
if fails == 3:
msg = "Found three failed links, bailing"
raise RuntimeError(msg) from e
if fails:
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/install-minimums/create_constraints_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from pathlib import Path
from zipfile import ZipFile

from packaging.requirements import Requirement
Expand Down Expand Up @@ -30,5 +31,5 @@
constraints_list = [f"{key}{value}\n" for (key, value) in constraints.items()]

# Write the constraints to to a pip constraints file.
with open(output_file, "w") as fid:
with Path(output_file).open("w") as fid:
fid.writelines(constraints_list)
10 changes: 5 additions & 5 deletions .github/actions/pr-script/pr_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def run(cmd: str, **kwargs: t.Any) -> str:
parts[0] = executable

try:
return str(check_output(parts, **kwargs).decode("utf-8").strip()) # noqa S603
return str(check_output(parts, **kwargs).decode("utf-8").strip()) # noqa: S603
except CalledProcessError as e:
print("output:", e.output.decode("utf-8").strip())
if e.stderr:
print("stderr:", e.stderr.decode("utf-8").strip())
raise e


def run_script() -> None: # noqa
def run_script() -> None:
"""Run a script on the target pull request URL"""
# e.g. https://github.com/foo/bar/pull/81

Expand All @@ -51,7 +51,7 @@ def run_script() -> None: # noqa
script = "[]"
try:
script_obj = json.loads(script)
except Exception: # noqa S110
except Exception: # noqa: S110
pass
if not isinstance(script_obj, list):
script_obj = [script_obj]
Expand Down Expand Up @@ -95,14 +95,14 @@ def run_script() -> None: # noqa
url = f"https://empty:{auth}@github.com/{user_name}/{repo}"
run(f"git clone {url} --filter=blob:none -b {branch} test")
if dry_run:
os.mkdir("./test")
Path("./test").mkdir()

os.chdir("test")
run("pip install -e '.[test]'")
for cmd in script:
try:
run(cmd)
except Exception: # noqa S110
except Exception: # noqa: S112
continue

# Use GitHub Actions bot user and email by default.
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.1
rev: 0.27.2
hooks:
- id: check-github-workflows

Expand All @@ -31,7 +31,7 @@ repos:
- id: mdformat

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
rev: "v3.1.0"
hooks:
- id: prettier
types_or: [yaml, html, json]
Expand All @@ -43,7 +43,7 @@ repos:
additional_dependencies: [black==23.7.0]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
rev: "v1.7.1"
hooks:
- id: mypy
stages: [manual]
Expand All @@ -64,7 +64,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
rev: v0.1.6
hooks:
- id: ruff
types_or: [python, jupyter]
Expand All @@ -73,7 +73,7 @@ repos:
types_or: [python, jupyter]

- repo: https://github.com/scientific-python/cookie
rev: "2023.10.27"
rev: "2023.11.17"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
1 change: 0 additions & 1 deletion foobar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

def test_no_op() -> None:
"""Single test to get pytest to pass."""
pass
43 changes: 27 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,41 @@ testpaths = ["foobar.py"]
files = "foobar.py"
python_version = "3.8"
strict = true
show_error_codes = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true

[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = [
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "N",
"PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP",
"W", "YTT",
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PTH", # flake8-use-pathlib
"PT", # flake8-pytest-style
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"PYI", # flake8-pyi
"S", # flake8-bandit
]
ignore = [
# Q000 Single quotes found but double quotes preferred
"Q000",
# FBT001 Boolean positional arg in function definition
"FBT001", "FBT002", "FBT003",
# E501 Line too long (158 > 100 characters)
"E501",
# SIM105 Use `contextlib.suppress(...)`
"SIM105",
# T201 `print` found
"T201",
"E501", # Line too long (158 > 100 characters)
"SIM105", # Use `contextlib.suppress(...)`
"T201", # `print` found
"PLR", # Design related pylint codes
]
unfixable = [
# Don't touch print statements
Expand All @@ -91,4 +102,4 @@ relative_files = true
source = ["foobar"]

[tool.repo-review]
ignore = ["PY004", "PY005", "PY007", "PP308", "GH102", "PC140", "RTD100"]
ignore = ["PY004", "GH102", "RTD100"]

0 comments on commit 488c306

Please sign in to comment.