Skip to content

Commit

Permalink
Fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagoel4512 committed Oct 14, 2024
1 parent 202579b commit 3b766ca
Show file tree
Hide file tree
Showing 79 changed files with 1,150 additions and 504 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04 ]
os: [ubuntu-20.04]

steps:
- uses: actions/checkout@v4
Expand Down
70 changes: 50 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
exclude: ^(\.copier-answers\.yml)|.pixi$
repos:
- repo: https://github.com/Quantco/pre-commit-mirrors-ruff
rev: 0.6.9
- repo: local
hooks:
- id: ruff-conda
- id: ruff-format-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
rev: "1.10.1"
hooks:
- id: mypy-conda
additional_dependencies: [-c, conda-forge, types-setuptools]
- repo: https://github.com/Quantco/pre-commit-mirrors-pyupgrade
rev: 3.15.2
hooks:
- id: pyupgrade-conda
args:
- --py38
- repo: https://github.com/Quantco/pre-commit-mirrors-prettier
rev: 3.2.5
hooks:
- id: prettier-conda
files: "\\.md$"
# ensure pixi environments are up to date
# workaround for https://github.com/prefix-dev/pixi/issues/1482
- id: pixi-install
name: pixi-install
entry: pixi install -e default -e lint
language: system
always_run: true
require_serial: true
pass_filenames: false
# insert-license
- id: insert-license
name: insert-license
entry: >-
pixi run -e lint
insert-license
--license-base64 Q29weXJpZ2h0IChjKSBRdWFudENvIDIwMjMtMjAyNApTUERYLUxpY2Vuc2UtSWRlbnRpZmllcjogQlNELTMtQ2xhdXNlCg==
--dynamic-years
--comment-style "#"
language: system
types: [python]
# ruff
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
# mypy
- id: mypy
name: mypy
entry: pixi run -e default mypy
language: system
types: [python]
require_serial: true
exclude: ^(tests|api-coverage-tests)/
# prettier
- id: prettier
name: prettier
entry: pixi run -e lint prettier --write --list-different --ignore-unknown
language: system
types: [text]
files: \.(md|yml|yaml)$
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand Down
29 changes: 0 additions & 29 deletions environment.yml

This file was deleted.

1,303 changes: 861 additions & 442 deletions pixi.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ setuptools-scm = "*"
[feature.lint.dependencies]
pre-commit = "*"
insert-license-header = "*"
mypy = "*"
prettier = "*"

[feature.lint.tasks]
pre-commit-install = "pre-commit install"
Expand All @@ -45,7 +47,6 @@ pandoc = "*"
jinja2 = "*"
python = "3.9.*"
onnx = "*"
pre-commit = "*"

[feature.opset-generation.tasks]
generate-opset = "./tools/generate_opset.sh"
Expand Down Expand Up @@ -83,4 +84,4 @@ weekly = ["weekly", "py312", "test"]
docs = ["docs"]
build = ["build"]
lint = ["lint"]
opset-generation = ["opset-generation"]
opset-generation = ["opset-generation", "lint"]
3 changes: 3 additions & 0 deletions src/spox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import importlib.metadata

from spox._public import argument, build, inline
Expand Down
5 changes: 4 additions & 1 deletion src/spox/_adapt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import warnings
from typing import Dict, List, Optional

Expand Down Expand Up @@ -41,7 +44,7 @@ def adapt_node(
for key, var in node.outputs.get_vars().items()
]
initializers = [
from_array(var._value, name)
from_array(var._value, name) # type: ignore
for name, var in node.inputs.get_vars().items()
if isinstance(var._value, np.ndarray)
]
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_attributes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import abc
from abc import ABC
from typing import Any, Generic, Iterable, Optional, Tuple, Type, TypeVar, Union
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import itertools
from dataclasses import dataclass
from typing import (
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import sys
from contextlib import contextmanager

Expand Down
3 changes: 3 additions & 0 deletions src/spox/_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import onnx.shape_inference

InferenceError = onnx.shape_inference.InferenceError
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import dataclasses
import enum
from dataclasses import dataclass
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_function.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import inspect
import itertools
from dataclasses import dataclass, make_dataclass
Expand Down
5 changes: 4 additions & 1 deletion src/spox/_future.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""Module containing experimental Spox features that may be standard in the future."""

from contextlib import contextmanager
Expand Down Expand Up @@ -82,7 +85,7 @@ def _promote(
creating constants and/or casting.
"""
targets: List[Union[np.dtype, np.generic, int, float]] = [
x.type.dtype if isinstance(x, Var) and isinstance(x.type, Tensor) else x
x.type.dtype if isinstance(x, Var) and isinstance(x.type, Tensor) else x # type: ignore
for x in args
]
if self.type_promotion:
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""Internal module implementing the low-level Graph object and functions for creating arguments and Graphs."""

import dataclasses
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_inline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import itertools
from dataclasses import dataclass
from typing import Callable, Dict, List, Optional, Sequence, Set, Tuple
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_internal_op.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""
Module for Spox operators that implement special internal behaviour that does not fit into the ONNX IR.
They behave like a normal Node, but their inference, building and translation behaviour may be overriden.
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import dataclasses
import enum
import itertools
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_public.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""Module implementing the main public interface functions in Spox."""

import contextlib
Expand Down
11 changes: 7 additions & 4 deletions src/spox/_schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""Exposes information related to reference ONNX operator schemas, used by StandardOpNode."""

import itertools
Expand Down Expand Up @@ -50,11 +53,11 @@ def _current_schema(

def _get_schemas_versioned(
all_schemas: List[OpSchema],
) -> Dict[str, Dict[str, OpSchema]]:
) -> Dict[str, Dict[str, List[OpSchema]]]:
"""Get a map into a list of schemas for all domain/names."""
return {
domain: {
name: sorted(op_group, key=lambda s: s.since_version)
name: sorted(op_group, key=lambda s: s.since_version) # type: ignore
for name, op_group in _key_groups(domain_group, lambda s: s.name)
}
for domain, domain_group in _key_groups(all_schemas, lambda s: s.domain)
Expand All @@ -69,7 +72,7 @@ def _get_schemas_map(
return {
domain: {
version: {
name: _current_schema(this_schemas, version)
name: _current_schema(this_schemas, version) # type: ignore
for name, this_schemas in domain_schemas.items()
if _current_schema(this_schemas, version)
}
Expand All @@ -81,7 +84,7 @@ def _get_schemas_map(
}


ALL_SCHEMAS: List[OpSchema] = get_all_schemas_with_history()
ALL_SCHEMAS: List[OpSchema] = get_all_schemas_with_history() # type: ignore

DOMAINS: Set[str] = {s.domain for s in ALL_SCHEMAS}

Expand Down
3 changes: 3 additions & 0 deletions src/spox/_scope.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

from typing import Dict, Generic, Hashable, Optional, Set, TypeVar, Union, overload

from ._node import Node
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_shape.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""
Data representation for Tensor shapes. Largely attempts to mimic semantics of ONNX shapes.
Shapes have 3 representations:
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_standard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

"""Module implementing a base for standard ONNX operators, which use the functionality of ONNX node-level inference."""

from typing import TYPE_CHECKING, Callable, Dict, Tuple
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_traverse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

from typing import Callable, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar

V = TypeVar("V")
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_type_system.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import typing
from dataclasses import dataclass
from typing import TypeVar
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

from typing import Optional

import numpy as np
Expand Down
10 changes: 8 additions & 2 deletions src/spox/_value_prop.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import enum
import logging
import warnings
from dataclasses import dataclass
from typing import Dict, List, Union
from typing import Callable, Dict, List, Union

import numpy as np
import numpy.typing as npt
import onnx
import onnx.reference

Expand Down Expand Up @@ -147,7 +151,7 @@ def to_ort_value(self) -> ORTValue:
if self.value is None: # Optional, Nothing
return None
elif isinstance(self.value, PropValue): # Optional, Some
return self.value.to_ref_value()
return self.value.to_ref_value() # type: ignore
elif isinstance(self.value, list): # Sequence
return [elem.to_ref_value() for elem in self.value]
else: # Tensor
Expand Down Expand Up @@ -192,6 +196,8 @@ def _run_onnxruntime(


def get_backend_calls():
run: Callable[..., Dict[str, npt.ArrayLike]]
unwrap_feed: Callable[..., PropValue]
if _VALUE_PROP_BACKEND == ValuePropBackend.REFERENCE:
wrap_feed = PropValue.to_ref_value
run = _run_reference_implementation
Expand Down
3 changes: 3 additions & 0 deletions src/spox/_var.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

import typing
from typing import Any, Callable, ClassVar, Optional, TypeVar, Union

Expand Down
3 changes: 3 additions & 0 deletions src/spox/opset/ai/onnx/ml/v3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import (
Expand Down
3 changes: 3 additions & 0 deletions src/spox/opset/ai/onnx/ml/v4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) QuantCo 2023-2024
# SPDX-License-Identifier: BSD-3-Clause

# ruff: noqa: E741 -- Allow ambiguous variable name
from dataclasses import dataclass
from typing import (
Expand Down
Loading

0 comments on commit 3b766ca

Please sign in to comment.