Skip to content

Commit f8913d0

Browse files
Merge pull request #291 from centre-for-humanities-computing/ci--Update-ruff-and-cruft-template
Ci: Update ruff and cruft template
2 parents 57fcb61 + d9e8a08 commit f8913d0

File tree

26 files changed

+146
-126
lines changed

26 files changed

+146
-126
lines changed

.cruft.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/KennethEnevoldsen/swift-python-cookiecutter",
3-
"commit": "e02068889310225ea4f65ea0b203c2949e1597a9",
3+
"commit": "85413085032f305896da8bad287a83d53fb0b196",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {

.github/workflows/static_type_checks.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# THIS ACTION WILL:
2+
# 1. Install dependencies
3+
# 2. Run static type checker
4+
5+
# SETUP:
6+
# None required except for the Makefile
7+
18
name: static_type_checks
29

310
on:

.github/workflows/tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# This workflow will:
2-
# 1) install Python dependencies
3-
# 2) run make test
1+
# THIS ACTION WILL:
2+
# 1) install Python dependencies
3+
# 2) run make test
44

5+
# SETUP:
6+
# None required except for the Makefile
57

6-
name: Tests
8+
name: test
79
on:
810
push:
911
branches: [main]
1012
pull_request:
1113
branches: [main]
1214

1315
jobs:
14-
pytest:
16+
test:
1517
runs-on: ${{ matrix.os }}
1618
permissions:
1719
contents: read

docs/evaluation/datasets.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
import random
2-
from typing import Any, Dict, List
4+
from typing import Any
35

46
import augmenty
57
import catalogue
@@ -15,7 +17,7 @@
1517

1618

1719
@datasets.register("dane")
18-
def dane() -> Dict[str, List[Example]]:
20+
def dane() -> dict[str, list[Example]]:
1921
from dacy.datasets import dane as _dane
2022

2123
train, dev, test = _dane(splits=["train", "dev", "test"]) # type: ignore
@@ -34,7 +36,7 @@ def augment_dataset(
3436
augmenters: dict,
3537
n_rep: int = 20,
3638
split: str = "test",
37-
) -> List[Example]:
39+
) -> list[Example]:
3840
# ensure seed
3941
random.seed(42)
4042
np.random.seed(42)
@@ -63,25 +65,25 @@ def augment_dataset(
6365

6466

6567
@datasets.register("gender_bias_dane")
66-
def dane_gender_bias() -> Dict[str, List[Example]]:
68+
def dane_gender_bias() -> dict[str, list[Example]]:
6769
return {"test": augment_dataset("dane", augmenters=get_gender_bias_augmenters())}
6870

6971

7072
@datasets.register("robustness_dane")
71-
def dane_robustness() -> Dict[str, List[Example]]:
73+
def dane_robustness() -> dict[str, list[Example]]:
7274
return {"test": augment_dataset("dane", augmenters=get_robustness_augmenters())}
7375

7476

7577
@datasets.register("dansk")
76-
def dansk(**kwargs: Any) -> Dict[str, List[Example]]:
78+
def dansk(**kwargs: Any) -> dict[str, list[Example]]:
7779
splits = ["train", "dev", "test"]
7880

7981
if not Doc.has_extension("meta"):
8082
Doc.set_extension("meta", default={}, force=True)
8183

8284
nlp = spacy.blank("da")
8385

84-
def convert_to_doc(example: Dict) -> Doc:
86+
def convert_to_doc(example: dict) -> Doc:
8587
doc = Doc(nlp.vocab).from_json(example)
8688
# set metadata
8789
for k in ["dagw_source", "dagw_domain", "dagw_source_full"]:

docs/evaluation/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import random
33
from pathlib import Path
4-
from typing import Any, Callable, Dict, List, Optional
4+
from typing import Any, Callable, Optional
55

66
import numpy as np
77
import pandas as pd
@@ -15,11 +15,11 @@
1515

1616

1717
def bootstrap(
18-
examples: List[Example],
18+
examples: list[Example],
1919
n_rep: int = 100,
2020
n_samples: Optional[int] = None,
2121
getter: Optional[Callable] = None,
22-
) -> List[Dict[str, Any]]:
22+
) -> list[dict[str, Any]]:
2323
random.seed(42)
2424
scorer = Scorer()
2525
scores = []
@@ -35,7 +35,7 @@ def bootstrap(
3535
return scores
3636

3737

38-
def compute_mean_and_ci(scores: List[Dict[str, Any]]) -> Dict[str, Any]:
38+
def compute_mean_and_ci(scores: list[dict[str, Any]]) -> dict[str, Any]:
3939
ent_f = [score["ents_f"] for score in scores]
4040
# filter out None
4141
ent_f = [x for x in ent_f if x is not None]
@@ -116,7 +116,7 @@ def doc_from_json(json_obj: dict, nlp: Language) -> Doc:
116116

117117
def predictions_to_disk(
118118
save_path: Path,
119-
examples: List[Example],
119+
examples: list[Example],
120120
mdl_name: str,
121121
time_in_seconds: float,
122122
) -> dict:
@@ -199,7 +199,7 @@ def apply_models(
199199

200200

201201
def create_dataframe(
202-
examples: List[Example],
202+
examples: list[Example],
203203
mdl_name: str,
204204
decimals: int = 1,
205205
n_rep: int = 100,
@@ -212,7 +212,7 @@ def create_dataframe(
212212
"Models": mdl_name,
213213
}
214214

215-
def score_to_string(score: Dict[str, Any], decimals: int = 1) -> str:
215+
def score_to_string(score: dict[str, Any], decimals: int = 1) -> str:
216216
if score["mean"] == 0:
217217
return " "
218218
return f"{100*score['mean']:.{decimals}f} ({100*score['ci'][0]:.{decimals}f}, {100*score['ci'][1]:.{decimals}f})"

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ static-type-check:
99
lint:
1010
@echo "--- 🧹 Running linters ---"
1111
ruff format . # running ruff formatting
12-
ruff src/ --fix # running ruff linting
13-
ruff tests/ --fix
14-
ruff docs/conf.py --fix
12+
ruff check src/ --fix # running ruff linting
13+
ruff check tests/ --fix
14+
ruff check docs/conf.py --fix
1515

1616
test:
1717
@echo "--- 🧪 Running tests ---"

papers/DaCy-A-Unified-Framework-for-Danish-NLP/apply_fns/apply_fn_daluke.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### pip install daluke==0.0.5
2-
from typing import Iterable, List
2+
from typing import Iterable
33

44
from daluke import AutoNERDaLUKE, predict_ner
55
from spacy.lang.da import Danish
@@ -18,7 +18,7 @@ def apply_daluke(
1818
examples: Iterable[Example],
1919
use_spacy: bool = True,
2020
batch_size: int = 16,
21-
) -> List[Example]:
21+
) -> list[Example]:
2222
docs_y, sentences = list(), list()
2323
for example in examples:
2424
# Tokenization using spacy or nltk

papers/DaCy-A-Unified-Framework-for-Danish-NLP/apply_fns/apply_fn_nerda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# to download the danlp and nerda you will have to set up a certificate:
22
import ssl
3-
from typing import Iterable, List
3+
from typing import Iterable, list
44

55
from NERDA.precooked import DA_BERT_ML
66
from spacy.lang.da import Danish
@@ -17,7 +17,7 @@
1717
nlp_da = Danish()
1818

1919

20-
def apply_nerda(examples: Iterable[Example], use_spacy: bool = True) -> List[Example]:
20+
def apply_nerda(examples: Iterable[Example], use_spacy: bool = True) -> list[Example]:
2121
sentences = []
2222
docs_y = []
2323
for example in examples:

papers/DaCy-A-Unified-Framework-for-Danish-NLP/apply_fns/apply_fn_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Iterable, List
1+
from typing import Callable, Iterable
22

33
from spacy.tokens import Doc, Span
44
from spacy.training import Example
@@ -12,12 +12,12 @@ def no_misc_getter(doc, attr):
1212
yield span
1313

1414

15-
def add_iob(doc: Doc, iob: List[str]) -> Doc:
15+
def add_iob(doc: Doc, iob: list[str]) -> Doc:
1616
"""Add iob tags to Doc.
1717
1818
Args:
1919
doc (Doc): A SpaCy doc
20-
iob (List[str]): a list of tokens on the IOB format
20+
iob (list[str]): a list of tokens on the IOB format
2121
2222
Returns:
2323
Doc: A doc with the spans to the new IOB

pyproject.toml

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ repository = "https://github.com/centre-for-humanities-computing/DaCy"
4848
file = "LICENSE"
4949
name = "Apache License 2.0"
5050
[project.optional-dependencies]
51-
dev = [
52-
"cruft>=2.0.0",
53-
"pyright>=1.1.339",
54-
"ruff>=0.0.270",
55-
]
51+
dev = ["cruft>=2.0.0", "pyright>=1.1.339", "ruff==0.7.1"]
5652
tests = ["pytest>=7.1.2", "pytest-cov>=3.0.0", "pytest-instafail>=0.4.2"]
5753
docs = [
5854
"sphinx==5.3.0",
@@ -110,6 +106,40 @@ pythonPlatform = "Darwin"
110106

111107
[tool.ruff]
112108
# extend-include = ["*.ipynb"]
109+
110+
# Exclude a variety of commonly ignored directories.
111+
exclude = [
112+
".bzr",
113+
".direnv",
114+
".eggs",
115+
".git",
116+
".hg",
117+
".nox",
118+
".pants.d",
119+
".pytype",
120+
".ruff_cache",
121+
".svn",
122+
".tox",
123+
".venv",
124+
"__pypackages__",
125+
"_build",
126+
"buck-out",
127+
"build",
128+
"dist",
129+
"node_modules",
130+
"venv",
131+
"__init__.py",
132+
".env",
133+
"__pycache__",
134+
"dev/**",
135+
"training/main/**",
136+
"training/ner_fine_grained/**",
137+
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
138+
"docs/performance_testing_utils/**",
139+
]
140+
target-version = "py39"
141+
142+
[tool.ruff.lint]
113143
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
114144
select = [
115145
"A",
@@ -150,54 +180,23 @@ ignore = [
150180
"ANN202",
151181
"COM812",
152182
]
153-
ignore-init-module-imports = true
154183
# Allow autofix for all enabled rules (when `--fix`) is provided.
155184
unfixable = ["ERA"]
156-
# Exclude a variety of commonly ignored directories.
157-
exclude = [
158-
".bzr",
159-
".direnv",
160-
".eggs",
161-
".git",
162-
".hg",
163-
".nox",
164-
".pants.d",
165-
".pytype",
166-
".ruff_cache",
167-
".svn",
168-
".tox",
169-
".venv",
170-
"__pypackages__",
171-
"_build",
172-
"buck-out",
173-
"build",
174-
"dist",
175-
"node_modules",
176-
"venv",
177-
"__init__.py",
178-
".venv",
179-
".env",
180-
".git",
181-
"__pycache__",
182-
"dev/**",
183-
"training/main/**",
184-
"training/ner_fine_grained/**",
185-
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
186-
"docs/performance_testing_utils/**",
187-
]
185+
186+
188187
# Allow unused variables when underscore-prefixed.
189188
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
190-
target-version = "py38"
189+
191190

192191
[tool.ruff.lint.pydocstyle]
193192
convention = "google"
194193

195-
[tool.ruff.flake8-annotations]
194+
[tool.ruff.lint.flake8-annotations]
196195
mypy-init-return = true
197196
suppress-none-returning = true
198197

199198

200-
[tool.ruff.mccabe]
199+
[tool.ruff.lint.mccabe]
201200
# Unlike Flake8, default to a complexity level of 10.
202201
max-complexity = 10
203202

0 commit comments

Comments
 (0)