Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff instead of black, isort, and flake8 #141

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ jobs:
run: |
pip install .
pip install pandoc
pre-commit install
python tools/generate_opset.py
git diff --exit-code
21 changes: 5 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
repos:
- repo: https://github.com/Quantco/pre-commit-mirrors-black
rev: 23.12.1
- repo: https://github.com/Quantco/pre-commit-mirrors-ruff
rev: 0.2.2
hooks:
- id: black-conda
args:
- --safe
- --target-version=py38
- repo: https://github.com/Quantco/pre-commit-mirrors-flake8
rev: 6.1.0
hooks:
- id: flake8-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-isort
rev: 5.13.2
hooks:
- id: isort-conda
additional_dependencies: [-c, conda-forge, toml=0.10.2]
- id: ruff-conda
- id: ruff-format-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
rev: "1.8.0"
hooks:
Expand All @@ -27,7 +16,7 @@ repos:
args:
- --py38
- repo: https://github.com/Quantco/pre-commit-mirrors-prettier
rev: 3.1.1
rev: 3.2.4
hooks:
- id: prettier-conda
files: "\\.md$"
25 changes: 5 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,12 @@ package-dir = {"" = "src"}
where = ["src"]
namespaces = false

[tool.black]
target-version = ['py38']
exclude = '''
/(
\.eggs
| \.git
| \.venv
| build
| dist
)/
'''
[tool.ruff.lint]
# Enable the isort rules.
extend-select = ["I"]

[tool.isort]
profile = "black"
multi_line_output = 3
include_trailing_comma = true
ensure_newline_before_comments = true
line_length = 88
known_first_party = "spox"
skip_glob = '\.eggs/*,\.git/*,\.venv/*,build/*,dist/*'
default_section = 'THIRDPARTY'
[tool.ruff.lint.isort]
known-first-party = ["spox"]

[tool.mypy]
python_version = "3.8"
Expand Down
6 changes: 3 additions & 3 deletions src/spox/_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def propagate_values_onnx(self) -> Dict[str, PropValueType]:
output_feed = run(model, input_feed)

results = {
scope.var[str(name)]
._which_output: unwrap_feed(scope.var[str(name)].unwrap_type(), result)
.value
scope.var[str(name)]._which_output: unwrap_feed(
scope.var[str(name)].unwrap_type(), result
).value
for name, result in output_feed.items()
}
return {k: v for k, v in results.items() if k is not None}
Expand Down
2 changes: 1 addition & 1 deletion src/spox/_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __rxor__(self, other) -> "Var":


def result_type(
*types: Union[Var, numpy.generic, int, float]
*types: Union[Var, numpy.generic, int, float],
) -> typing.Type[numpy.generic]:
"""Promote type for all given element types/values using ``np.result_type``."""
return numpy.dtype(
Expand Down
29 changes: 7 additions & 22 deletions src/spox/opset/ai/onnx/ml/v3.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
# flake8: noqa
import typing # noqa: F401
import warnings # noqa: F401
# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import ( # noqa: F401
Any,
Callable,
from typing import (
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
from typing import cast as typing_cast # noqa: F401

import numpy as np # noqa: F401
import numpy.typing as npt # noqa: F401
import numpy as np

from spox._attributes import (
AttrDtype,
AttrFloat32,
AttrFloat32s,
AttrGraph,
AttrInt64,
AttrInt64s,
AttrString,
AttrStrings,
AttrTensor,
AttrType,
)
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs # noqa: F401
from spox._graph import Graph, subgraph # noqa: F401
from spox._internal_op import intro # noqa: F401
from spox._node import OpType # noqa: F401
from spox._standard import InferenceError, StandardNode # noqa: F401
from spox._type_system import Sequence as SpoxSequence # noqa: F401
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._node import OpType
from spox._standard import InferenceError, StandardNode
from spox._type_system import Tensor, Type
from spox._value_prop import PropValueType # noqa: F401
from spox._var import Var, result_type # noqa: F401
from spox._var import Var


class _ArrayFeatureExtractor(StandardNode):
Expand Down
33 changes: 7 additions & 26 deletions src/spox/opset/ai/onnx/ml/v4.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
# flake8: noqa
import typing # noqa: F401
import warnings # noqa: F401
# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import ( # noqa: F401
Any,
Callable,
Dict,
from typing import (
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
from typing import cast as typing_cast # noqa: F401

import numpy as np # noqa: F401
import numpy.typing as npt # noqa: F401
import numpy as np

from spox._attributes import (
AttrDtype,
AttrFloat32,
AttrFloat32s,
AttrGraph,
AttrInt64,
AttrInt64s,
AttrString,
AttrStrings,
AttrTensor,
AttrType,
)
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs # noqa: F401
from spox._graph import Graph, subgraph # noqa: F401
from spox._internal_op import intro # noqa: F401
from spox._node import OpType # noqa: F401
from spox._standard import InferenceError, StandardNode # noqa: F401
from spox._type_system import Sequence as SpoxSequence # noqa: F401
from spox._type_system import Tensor, Type
from spox._value_prop import PropValueType # noqa: F401
from spox._var import Var, result_type # noqa: F401
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._node import OpType
from spox._standard import StandardNode
from spox._var import Var
from spox.opset.ai.onnx.ml.v3 import (
_ArrayFeatureExtractor,
_Binarizer,
Expand Down
29 changes: 12 additions & 17 deletions src/spox/opset/ai/onnx/v17.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# flake8: noqa
import typing # noqa: F401
import warnings # noqa: F401
# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import ( # noqa: F401
Any,
from typing import (
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
from typing import cast as typing_cast # noqa: F401
from typing import cast as typing_cast

import numpy as np # noqa: F401
import numpy.typing as npt # noqa: F401
import numpy as np
import numpy.typing as npt

from spox._attributes import (
AttrDtype,
Expand All @@ -30,15 +26,14 @@
AttrTensor,
AttrType,
)
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs # noqa: F401
from spox._graph import Graph, subgraph # noqa: F401
from spox._internal_op import intro # noqa: F401
from spox._node import OpType # noqa: F401
from spox._standard import InferenceError, StandardNode # noqa: F401
from spox._type_system import Sequence as SpoxSequence # noqa: F401
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._graph import Graph, subgraph
from spox._node import OpType
from spox._standard import InferenceError, StandardNode
from spox._type_system import Sequence as SpoxSequence
from spox._type_system import Tensor, Type
from spox._value_prop import PropValueType # noqa: F401
from spox._var import Var, result_type # noqa: F401
from spox._value_prop import PropValueType
from spox._var import Var


class _Abs(StandardNode):
Expand Down
36 changes: 8 additions & 28 deletions src/spox/opset/ai/onnx/v18.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
# flake8: noqa
import typing # noqa: F401
import warnings # noqa: F401
# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import ( # noqa: F401
Any,
Callable,
Dict,
from typing import (
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
from typing import cast as typing_cast # noqa: F401

import numpy as np # noqa: F401
import numpy.typing as npt # noqa: F401
import numpy as np
import numpy.typing as npt

from spox._attributes import (
AttrDtype,
AttrFloat32,
AttrFloat32s,
AttrGraph,
AttrInt64,
AttrInt64s,
AttrString,
AttrStrings,
AttrTensor,
AttrType,
)
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs # noqa: F401
from spox._graph import Graph, subgraph # noqa: F401
from spox._internal_op import intro # noqa: F401
from spox._node import OpType # noqa: F401
from spox._standard import InferenceError, StandardNode # noqa: F401
from spox._type_system import Sequence as SpoxSequence # noqa: F401
from spox._type_system import Tensor, Type
from spox._value_prop import PropValueType # noqa: F401
from spox._var import Var, result_type # noqa: F401
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._node import OpType
from spox._standard import StandardNode
from spox._var import Var
from spox.opset.ai.onnx.v17 import (
_DFT,
_GRU,
Expand Down
30 changes: 11 additions & 19 deletions src/spox/opset/ai/onnx/v19.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# flake8: noqa
import typing # noqa: F401
import warnings # noqa: F401
# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import ( # noqa: F401
Any,
from typing import (
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
from typing import cast as typing_cast # noqa: F401
from typing import cast as typing_cast

import numpy as np # noqa: F401
import numpy.typing as npt # noqa: F401
import numpy as np
import numpy.typing as npt

from spox._attributes import (
AttrDtype,
Expand All @@ -28,17 +23,14 @@
AttrString,
AttrStrings,
AttrTensor,
AttrType,
)
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs # noqa: F401
from spox._graph import Graph, subgraph # noqa: F401
from spox._internal_op import intro # noqa: F401
from spox._node import OpType # noqa: F401
from spox._standard import InferenceError, StandardNode # noqa: F401
from spox._type_system import Sequence as SpoxSequence # noqa: F401
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._graph import Graph, subgraph
from spox._node import OpType
from spox._standard import StandardNode
from spox._type_system import Tensor, Type
from spox._value_prop import PropValueType # noqa: F401
from spox._var import Var, result_type # noqa: F401
from spox._value_prop import PropValueType
from spox._var import Var
from spox.opset.ai.onnx.v18 import (
_DFT,
_GRU,
Expand Down
Loading