Skip to content

Commit a71dc3e

Browse files
committed
ci(FCL-176): swap from black/isort to ruff for code formatting
1 parent c532b60 commit a71dc3e

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

.pre-commit-config.yaml

+7-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ repos:
1515
- id: no-commit-to-branch
1616
- id: trailing-whitespace
1717

18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: v0.5.0
20+
hooks:
21+
- id: ruff
22+
args: [--fix, --exit-non-zero-on-fix]
23+
- id: ruff-format
24+
1825
- repo: local
1926
hooks:
2027
- id: validate-schemas
@@ -25,20 +32,8 @@ repos:
2532
entry: python scripts/validate_schemas
2633
files: .xsd$
2734

28-
- repo: https://github.com/psf/black
29-
rev: 23.11.0
30-
hooks:
31-
- id: black
32-
3335
- repo: https://github.com/pre-commit/mirrors-prettier
3436
rev: v3.1.0
3537
hooks:
3638
- id: prettier
3739
types_or: [scss, yaml, markdown, javascript, xml]
38-
39-
- repo: https://github.com/astral-sh/ruff-pre-commit
40-
# Ruff version.
41-
rev: v0.1.6
42-
hooks:
43-
- id: ruff
44-
args: [--fix, --exit-non-zero-on-fix]

development_scripts/populate_top_judgments_and_neighbours.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333

3434

3535
def get_judgment_xml(url):
36-
print("Getting judgment: %s" % url)
36+
print(f"Getting judgment: {url}")
3737
response = requests.get(f"https://caselaw.nationalarchives.gov.uk/{url}/data.xml")
3838
response.raise_for_status()
3939
return response.content
4040

4141

4242
def save_judgment_xml(url, xml):
43-
print("Saving judgment: %s" % url)
43+
print(f"Saving judgment: {url}")
4444
ml_url = f"/{url}.xml"
4545
response = requests.put(
4646
f"http://admin:admin@localhost:8011/LATEST/documents?uri={ml_url}&collection=judgment",
@@ -49,7 +49,7 @@ def save_judgment_xml(url, xml):
4949
try:
5050
response.raise_for_status()
5151
except requests.exceptions.RequestException as e:
52-
print("Something went wrong saving the judgment: %s" % e)
52+
print(f"Something went wrong saving the judgment: {e}")
5353

5454

5555
def get_neighbours_for_judgment(xml):
@@ -59,18 +59,12 @@ def get_neighbours_for_judgment(xml):
5959
"./akn:judgment/akn:meta/akn:identification/akn:FRBRWork/akn:FRBRname",
6060
ns,
6161
).attrib["value"]
62-
print("Getting neighbours for judgment title: %s" % title)
63-
search_url = (
64-
"https://caselaw.nationalarchives.gov.uk/judgments/results?query="
65-
+ quote(title)
66-
)
62+
print(f"Getting neighbours for judgment title: {title}")
63+
search_url = "https://caselaw.nationalarchives.gov.uk/judgments/results?query=" + quote(title)
6764
search_results = requests.get(search_url)
6865
search_soup = BeautifulSoup(search_results.content, "html.parser")
69-
neighbours = list(
70-
re.sub(r"^\/", "", a["href"])
71-
for a in search_soup.select(".judgment-listing__title a")
72-
)
73-
print("... found %s" % len(neighbours))
66+
neighbours = list(re.sub(r"^\/", "", a["href"]) for a in search_soup.select(".judgment-listing__title a"))
67+
print(f"... found {len(neighbours)}")
7468
return neighbours
7569

7670

@@ -85,6 +79,6 @@ def get_neighbours_for_judgment(xml):
8579
save_judgment_xml(url2, xml2)
8680
found.add(url2)
8781
else:
88-
print("Skipping already imported judgment %s" % url2)
82+
print(f"Skipping already imported judgment {url2}")
8983
print(f"**** {url} and close title matches added to local Marklogic db ****")
90-
print("DONE. Imported %s judgments." % len(found))
84+
print(f"DONE. Imported {len(found)} judgments.")

pyproject.toml

+7-14
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ pytest = "^7.4.3"
1515
requires = ["poetry-core"]
1616
build-backend = "poetry.core.masonry.api"
1717

18-
1918
[tool.ruff]
19+
line-length = 120
20+
21+
[tool.ruff.lint]
2022
ignore = ["E501", "G004", "PLR2004", "RUF005", "RUF012", "UP040"] # long lines, fstrings in logs, magic values, consider not concat, mutable classbits, type instead of TypeAlias
2123
extend-select = ["W", "B", "Q", "C90", "I", "UP", "YTT", "ASYNC", "S", "BLE", "A", "COM", "C4", "DTZ", "T10", "DJ", "EM", "EXE", "FA",
2224
"ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "SLF", "SLOT", "SIM", "TID", "TCH", "INT", "PTH",
2325
"FIX", "PGH", "PL", "TRY", "FLY", "PERF", "RUF"]
2426
unfixable = ["ERA"]
2527

2628
# things skipped:
27-
# N: naming, possibly good
28-
# D: docstrings missing throughout
29+
# N: naming, possibly good
30+
# D: docstrings missing throughout
2931
# ANN: annotations missing throughout
3032
# FBT: not convinced boolean trap worth auto-banning.
3133
# CPY: copyright at top of each file
@@ -37,19 +39,10 @@ unfixable = ["ERA"]
3739
# PD, NPY, AIR: ignored, panda / numpy / airflow specific
3840
# FURB: not yet out of preview
3941

40-
41-
42-
[tool.ruff.extend-per-file-ignores]
42+
[tool.ruff.lint.extend-per-file-ignores]
4343
"*" = ["RET505", # disagree with if X: return Y else: return Z being wrong
4444
"T201", # print
4545
"S113", # requests no timeout : TODO
4646
]
4747
"tests/*" = ["S101"] # assert fine in tests
48-
"development_scripts/populate_top_judgments_and_neighbours.py" = ["S314", "C400"] # TODO
49-
50-
51-
52-
[tool.ruff.isort]
53-
known-first-party = ["ds-caselaw-editor-ui", "config"]
54-
55-
[tool.ruff.pycodestyle]
48+
"development_scripts/populate_top_judgments_and_neighbours.py" = ["S314", "C400"] # TODO

0 commit comments

Comments
 (0)