Skip to content

Commit 47fee72

Browse files
authored
chore: replace black with ruff-format (#246)
* chore: use ruff format * ci: add typos * move config in pyproject * use ruff during build * pin xsdata for now * pin xsdata * skip imaris tests * rm x
1 parent 35d2891 commit 47fee72

File tree

10 files changed

+81
-79
lines changed

10 files changed

+81
-79
lines changed

.github/workflows/test_dependents.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ jobs:
4747

4848
- name: Install ome-types
4949
run: pip install .
50+
5051
working-directory: ome-types
51-
5252
- name: Run Tests
5353
run: |
54-
pytest --color=yes -k "not test_known_errors_without_cleaning and not bad" \
54+
pytest --color=yes -k \
55+
"not test_known_errors_without_cleaning and not bad and not Imaris" \
5556
aicsimageio/tests/readers/test_ome_tiff_reader.py \
5657
aicsimageio/tests/writers/test_ome_tiff_writer.py \
5758
aicsimageio/tests/readers/extra_readers/test_bioformats_reader.py \
58-
aicsimageio/tests/readers/extra_readers/test_ome_zarr_reader.py
59+
aicsimageio/tests/readers/extra_readers/test_ome_zarr_reader.py
5960
6061
test-paquo:
6162
name: test paquo

.pre-commit-config.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ ci:
44
autoupdate_commit_msg: "ci(pre-commit.ci): autoupdate"
55

66
repos:
7-
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.5.0
7+
- repo: https://github.com/abravalheri/validate-pyproject
8+
rev: v0.16
99
hooks:
10-
- id: trailing-whitespace
11-
exclude: ^tests|^docs|.xsd
12-
- id: end-of-file-fixer
13-
exclude: ^tests|^docs
10+
- id: validate-pyproject
1411

15-
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.2.0
12+
- repo: https://github.com/crate-ci/typos
13+
rev: v1.19.0
1714
hooks:
18-
- id: ruff
19-
args: [--fix]
15+
- id: typos
2016

21-
- repo: https://github.com/psf/black
22-
rev: 24.1.1
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.3.0
2319
hooks:
24-
- id: black
25-
exclude: ^docs
20+
- id: ruff
21+
args: [--fix, --unsafe-fixes]
22+
- id: ruff-format
2623

2724
- repo: https://github.com/pre-commit/mirrors-mypy
2825
rev: v1.8.0

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@
470470

471471
**Merged pull requests:**
472472

473-
- intial setup config [\#1](https://github.com/tlambert03/ome-types/pull/1) ([tlambert03](https://github.com/tlambert03))
473+
- initial setup config [\#1](https://github.com/tlambert03/ome-types/pull/1) ([tlambert03](https://github.com/tlambert03))
474474

475475

476476

docs/scripts/write_v2_changes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<details>
2121
2222
<summary>List of plural name changes</summary>
23-
23+
2424
These fields appear in many different classes:
2525
2626
- `annotation_ref` -> `annotation_refs`

pyproject.toml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dynamic = ["version"]
3131
dependencies = [
3232
"pydantic >=1.9.0",
3333
"pydantic-compat >=0.1.0",
34-
"xsdata >=23.6, <25",
34+
"xsdata >=23.6, <24.3",
3535
]
3636

3737
[project.urls]
@@ -50,7 +50,6 @@ lxml = ["lxml >=4.8.0"]
5050
dev = ["pre-commit", "types-lxml; python_version >= '3.8'"]
5151
docs = ["mkdocs-material", "mkdocstrings-python"]
5252
test = [
53-
"black",
5453
"lxml",
5554
"mypy",
5655
"numpy",
@@ -70,7 +69,7 @@ test-qt = ["qtpy", "pytest-qt"]
7069
# requirements to run the autogen script in hatch_build.py
7170
require-runtime-dependencies = true
7271
# pin ruff for builds because it changes often
73-
dependencies = ["black", "ruff ==0.1.5", "xsdata[cli]>=23.6"]
72+
dependencies = ["ruff ==0.3.0", "xsdata[cli]==24.2.1"]
7473

7574

7675
# https://hatch.pypa.io/latest/config/metadata/
@@ -92,51 +91,50 @@ exclude = ["src/ome_types/_autogenerated"]
9291
line-length = 88
9392
src = ["src", "tests"]
9493
target-version = "py38"
94+
exclude = ['src/_ome_autogen.py', 'src/ome_types/_vendor']
95+
96+
[tool.ruff.lint]
97+
pydocstyle = { convention = "numpy" }
9598
select = [
96-
"E", # style errors
97-
"F", # flakes
98-
"D", # pydocstyle
99-
"I", # isort
100-
"UP", # pyupgrade
101-
"S", # bandit
102-
"C4", # flake8-comprehensions
103-
"B", # flake8-bugbear
104-
"A001", # flake8-builtins
105-
"TID", # tidy
106-
"TCH", # typechecking
107-
"RUF", # ruff-specific rules
99+
"E", # style errors
100+
"W", # style warnings
101+
"F", # flakes
102+
"D", # pydocstyle
103+
"D417", # Missing argument descriptions in Docstrings
104+
"I", # isort
105+
"UP", # pyupgrade
106+
"S", # bandit
107+
"C4", # flake8-comprehensions
108+
"B", # flake8-bugbear
109+
"A001", # flake8-builtins
110+
"RUF", # ruff-specific rules
111+
"SIM105", # contextlib.suppress
112+
"TID", # tidy imports
113+
"TCH", # flake8-type-checking
108114
]
109115
ignore = [
110-
"D100", # Missing docstring in public module
111-
"D101", # Missing docstring in public class
112-
"D104", # Missing docstring in public package
113-
"D106", # Missing docstring in public nested class
114-
"D107", # Missing docstring in __init__
115-
"D203", # 1 blank line required before class docstring
116-
"D205", # 1 blank line required between summary line and description
117-
"D212", # Multi-line docstring summary should start at the first line
118-
"D213", # Multi-line docstring summary should start at the second line
119-
"D400", # First line should end with a period
120-
"D404", # First word of the docstring should not be This
121-
"D413", # Missing blank line after last section
122-
"D416", # Section name should end with a colon
123-
"C901", # Function is too complex
124-
"RUF009", # Do not perform function calls in default arguments
125-
"S3", # xml security
116+
"D104", # Missing docstring in public package
117+
"D401", # First line should be in imperative mood
118+
"D401", # First line should be in imperative mood
119+
"D100", # Missing docstring in public module
120+
"S3", # Using `xml` to parse untrusted data is known to be vulnerable to XML attacks
126121
]
127-
exclude = ['src/_ome_autogen.py', 'src/ome_types/_vendor']
128122

129-
[tool.ruff.flake8-tidy-imports]
123+
[tool.ruff.lint.flake8-tidy-imports]
130124
ban-relative-imports = "all" # Disallow all relative imports.
131125

132-
[tool.ruff.per-file-ignores]
126+
[tool.ruff.lint.per-file-ignores]
133127
"tests/*.py" = ["D", "S"]
134128
"src/ome_autogen.py" = ["D10", "E501"]
135129
".github/*.py" = ["D"]
136130
"setup.py" = ["D"]
137131
"docs/**/*.py" = ["D"]
138132
"src/xsdata_pydantic_basemodel/**/*.py" = ["D"]
139133

134+
# https://docs.astral.sh/ruff/formatter/
135+
[tool.ruff.format]
136+
docstring-code-format = true
137+
140138
[tool.check-manifest]
141139
ignore = [
142140
"coverage.yml",
@@ -149,10 +147,6 @@ ignore = [
149147
"typesafety/**/*",
150148
]
151149

152-
153-
[tool.black]
154-
target-version = ['py38']
155-
156150
# https://docs.pytest.org/en/6.2.x/customize.html
157151
[tool.pytest.ini_options]
158152
minversion = "6.0"
@@ -218,6 +212,12 @@ omit = [
218212
"src/ome_types/widget.py",
219213
]
220214

215+
[tool.typos.default]
216+
extend-ignore-identifiers-re = ["nd2?.*", "ND2?.*", ".*ser_schema"]
217+
218+
[tool.typos.files]
219+
extend-exclude = ["*.xsd", "*.xml", "*.xsl", "*.json"]
220+
221221
# Entry points -- REMOVE ONCE XSDATA-PYDANTIC-BASEMODEL IS SEPARATE
222222
[project.entry-points."xsdata.plugins.class_types"]
223223
xsdata_pydantic_basemodel = "xsdata_pydantic_basemodel.hooks.class_type"

src/ome_autogen/_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def render_module(
120120
mod = super().render_module(resolver, classes)
121121

122122
# xsdata renames classes like "FillRule" (which appears as a SimpleType
123-
# inside of the Shape ComlexType) as "Shape_FillRule".
123+
# inside of the Shape ComplexType) as "Shape_FillRule".
124124
# We want to make them available as "FillRule" in the corresponding
125125
# module, (i.e. the "Shape" module in this case).
126126
# That is, we want "Shape = Shape_FillRule" included in the module.

src/ome_autogen/main.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from ome_autogen._config import PYDANTIC_SUPPORT, get_config
1313
from ome_autogen._transformer import OMETransformer
1414

15-
BLACK_LINE_LENGTH = 88
16-
BLACK_TARGET_VERSION = "py38"
17-
BLACK_SKIP_TRAILING_COMMA = False # use trailing commas as a reason to split lines?
15+
RUFF_LINE_LENGTH = 88
16+
RUFF_TARGET_VERSION = "py38"
17+
1818
OUTPUT_PACKAGE = "ome_types._autogenerated.ome_2016_06"
1919
DO_MYPY = os.environ.get("OME_AUTOGEN_MYPY", "0") == "1" or "--mypy" in sys.argv
2020
SRC_PATH = Path(__file__).parent.parent
@@ -62,22 +62,22 @@ def build_model(
6262

6363

6464
def _fix_formatting(package_dir: str, ruff_ignore: list[str] = RUFF_IGNORE) -> None:
65-
_print_gray("Running black and ruff ...")
65+
_print_gray("Running ruff check...")
6666

67-
ruff = ["ruff", "-q", "--fix", "--unsafe-fixes", package_dir]
68-
ruff.extend(f"--ignore={ignore}" for ignore in ruff_ignore)
69-
subprocess.check_call(ruff) # noqa S
67+
ruff_chk = ["ruff", "check", "-q", "--fix", "--unsafe-fixes", package_dir]
68+
ruff_chk.extend(f"--ignore={ignore}" for ignore in ruff_ignore)
69+
subprocess.check_call(ruff_chk) # noqa S
7070

71-
black = [
72-
"black",
71+
_print_gray("Running ruff format...")
72+
ruff_fmt = [
73+
"ruff",
74+
"format",
7375
"-q",
74-
f"--line-length={BLACK_LINE_LENGTH}",
75-
f"--target-version={BLACK_TARGET_VERSION}",
76+
f"--line-length={RUFF_LINE_LENGTH}",
77+
f"--target-version={RUFF_TARGET_VERSION}",
7678
]
77-
if BLACK_SKIP_TRAILING_COMMA: # pragma: no cover
78-
black.append("--skip-magic-trailing-comma")
79-
black.extend([str(x) for x in Path(package_dir).rglob("*.py")])
80-
subprocess.check_call(black) # noqa S
79+
ruff_fmt.extend([str(x) for x in Path(package_dir).rglob("*.py")])
80+
subprocess.check_call(ruff_fmt) # noqa S
8181

8282

8383
def _check_mypy(package_dir: str) -> None:
@@ -149,13 +149,13 @@ def _disp_type(obj: Any) -> str:
149149
if "ForwardRef" in x:
150150
# replace "List[ForwardRef('Map.M')]" with "List[Map.M]"
151151
x = re.sub(r"ForwardRef\('([a-zA-Z_.]*)'\)", r"\1", x)
152-
x = re.sub("ome_types\._autogenerated\.ome_2016_06.[^.]+.", "", x)
152+
x = re.sub(r"ome_types\._autogenerated\.ome_2016_06.[^.]+.", "", x)
153153
return x
154154

155155
# add TypedDicts for all models
156156
module = KWARGS_MODULE
157157
SUFFIX = "Dict"
158-
CLASS = "class {name}(TypedDict, total=False):\n\t{fields}\n\n"
158+
CLASS = "class {name}(TypedDict, total=False):\n {fields}\n\n"
159159
for cls_name, m in sorted(ome_models.items()):
160160
if cls_name.endswith("Ref"):
161161
module += f"{cls_name}: TypeAlias = RefDict\n"
@@ -166,11 +166,11 @@ def _disp_type(obj: Any) -> str:
166166
]
167167
if _fields:
168168
module += CLASS.format(
169-
name=f"{m.__name__}{SUFFIX}", fields="\n\t".join(_fields)
169+
name=f"{m.__name__}{SUFFIX}", fields="\n ".join(_fields)
170170
)
171171
else:
172172
module += (
173-
f"class {m.__name__}{SUFFIX}(TypedDict, total=False):\n\tpass\n\n"
173+
f"class {m.__name__}{SUFFIX}(TypedDict, total=False):\n pass\n\n"
174174
)
175175

176176
# fix name spaces

src/ome_types/_mixins/_kinded.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class KindMixin(BaseModel):
12-
"""This mixin adds a `kind` field to the dict output.
12+
"""Mixin to a `kind` field to the dict output.
1313
1414
This helps for casting a dict to a specific subclass, when the fields are
1515
otherwise identical.

src/ome_types/model/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232

3333
class OME2016Loader(Loader):
34+
"""Loader to redirect imports from ome_types.model to ome_types._autogenerated."""
35+
3436
def __init__(self, fullname: str) -> None:
3537
submodule = fullname.split(".", 2)[-1]
3638
file_2016 = (_OME_2016 / submodule.replace(".", "/")).with_suffix(".py")
@@ -61,6 +63,8 @@ def exec_module(self, module: ModuleType) -> None:
6163
# add a sys.meta_path hook to allow import of any modules in
6264
# ome_types._autogenerated.ome_2016_06
6365
class OMEMetaPathFinder(MetaPathFinder):
66+
"""Finder to redirect imports from ome_types.model to ome_types._autogenerated."""
67+
6468
def find_spec(
6569
self,
6670
fullname: str,

src/ome_types/model/simple_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module is only here for backwards compatibility with v<0.4.0 of ome-types.
1+
"""Module is only here for backwards compatibility with v<0.4.0 of ome-types.
22
33
Most of the types defined here are also exported from `ome_types.model`. But for
44
now, you can also import them from here.

0 commit comments

Comments
 (0)