Skip to content

Commit 2179174

Browse files
add ruff
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent a6b8956 commit 2179174

39 files changed

+1277
-1172
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ repos:
1313
- id: debug-statements
1414
- id: detect-private-key
1515

16+
# Ruff version.
17+
- repo: https://github.com/charliermarsh/ruff-pre-commit
18+
rev: "v0.6.2"
19+
hooks:
20+
# Run the linter.
21+
- id: ruff
22+
args: ["--fix"]
23+
# Run the formatter
24+
- id: ruff-format
25+
1626
- repo: https://github.com/pre-commit/mirrors-prettier
1727
rev: v4.0.0-alpha.8
1828
hooks:

examples/python/asynchronous_api/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22
"""
3-
Copyright (C) 2018-2022 Intel Corporation
3+
Copyright (C) 2018-2022 Intel Corporation
44
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1616
"""
1717

1818
import sys

examples/python/serving_api/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22
"""
3-
Copyright (C) 2018-2022 Intel Corporation
3+
Copyright (C) 2018-2022 Intel Corporation
44
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1616
"""
1717

1818
import sys

examples/python/synchronous_api/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22
"""
3-
Copyright (C) 2018-2022 Intel Corporation
3+
Copyright (C) 2018-2022 Intel Corporation
44
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1616
"""
1717

1818
import sys

examples/python/visual_prompting/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22
"""
3-
Copyright (C) 2024 Intel Corporation
3+
Copyright (C) 2024 Intel Corporation
44
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1616
"""
1717

1818
import argparse

examples/python/zsl_visual_prompting/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22
"""
3-
Copyright (C) 2024 Intel Corporation
3+
Copyright (C) 2024 Intel Corporation
44
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1616
"""
1717

1818
import argparse

model_api/python/model_api/adapters/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
"""
2-
Copyright (C) 2021-2024 Intel Corporation
1+
"""Copyright (C) 2021-2024 Intel Corporation
32
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
76
8-
http://www.apache.org/licenses/LICENSE-2.0
7+
http://www.apache.org/licenses/LICENSE-2.0
98
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
1514
"""
1615

1716
from .onnx_adapter import ONNXRuntimeAdapter
Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,58 @@
1-
"""
2-
Copyright (c) 2021-2024 Intel Corporation
1+
"""Copyright (c) 2021-2024 Intel Corporation
32
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
76
8-
http://www.apache.org/licenses/LICENSE-2.0
7+
http://www.apache.org/licenses/LICENSE-2.0
98
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
1514
"""
1615

1716
import abc
1817
from dataclasses import dataclass, field
19-
from typing import Dict, List, Set, Tuple
2018

2119

2220
@dataclass
2321
class Metadata:
24-
names: Set[str] = field(default_factory=set)
25-
shape: List[int] = field(default_factory=list)
22+
names: set[str] = field(default_factory=set)
23+
shape: list[int] = field(default_factory=list)
2624
layout: str = ""
2725
precision: str = ""
2826
type: str = ""
29-
meta: Dict = field(default_factory=dict)
27+
meta: dict = field(default_factory=dict)
3028

3129

32-
class InferenceAdapter(metaclass=abc.ABCMeta):
33-
"""
34-
An abstract Model Adapter with the following interface:
35-
36-
- Reading the model from disk or other place
37-
- Loading the model to the device
38-
- Accessing the information about inputs/outputs
39-
- The model reshaping
40-
- Synchronous model inference
41-
- Asynchronous model inference
30+
class InferenceAdapter(abc.ABC):
31+
"""An abstract Model Adapter with the following interface:
32+
33+
- Reading the model from disk or other place
34+
- Loading the model to the device
35+
- Accessing the information about inputs/outputs
36+
- The model reshaping
37+
- Synchronous model inference
38+
- Asynchronous model inference
4239
"""
4340

4441
precisions = ("FP32", "I32", "FP16", "I16", "I8", "U8")
4542

4643
@abc.abstractmethod
4744
def __init__(self):
48-
"""
49-
An abstract Model Adapter constructor.
45+
"""An abstract Model Adapter constructor.
5046
Reads the model from disk or other place.
5147
"""
5248

5349
@abc.abstractmethod
5450
def load_model(self):
55-
"""
56-
Loads the model on the device.
57-
"""
51+
"""Loads the model on the device."""
5852

5953
@abc.abstractmethod
6054
def get_input_layers(self):
61-
"""
62-
Gets the names of model inputs and for each one creates the Metadata structure,
55+
"""Gets the names of model inputs and for each one creates the Metadata structure,
6356
which contains the information about the input shape, layout, precision
6457
in OpenVINO format, meta (optional)
6558
@@ -69,8 +62,7 @@ def get_input_layers(self):
6962

7063
@abc.abstractmethod
7164
def get_output_layers(self):
72-
"""
73-
Gets the names of model outputs and for each one creates the Metadata structure,
65+
"""Gets the names of model outputs and for each one creates the Metadata structure,
7466
which contains the information about the output shape, layout, precision
7567
in OpenVINO format, meta (optional)
7668
@@ -80,8 +72,7 @@ def get_output_layers(self):
8072

8173
@abc.abstractmethod
8274
def reshape_model(self, new_shape):
83-
"""
84-
Reshapes the model inputs to fit the new input shape.
75+
"""Reshapes the model inputs to fit the new input shape.
8576
8677
Args:
8778
- new_shape (dict): the dictionary with inputs names as keys and
@@ -95,8 +86,7 @@ def reshape_model(self, new_shape):
9586

9687
@abc.abstractmethod
9788
def infer_sync(self, dict_data):
98-
"""
99-
Performs the synchronous model inference. The infer is a blocking method.
89+
"""Performs the synchronous model inference. The infer is a blocking method.
10090
10191
Args:
10292
- dict_data: it's submitted to the model for inference and has the following format:
@@ -117,8 +107,7 @@ def infer_sync(self, dict_data):
117107

118108
@abc.abstractmethod
119109
def infer_async(self, dict_data, callback_fn, callback_data):
120-
"""
121-
Performs the asynchronous model inference and sets
110+
"""Performs the asynchronous model inference and sets
122111
the callback for inference completion. Also, it should
123112
define get_raw_result() function, which handles the result
124113
of inference from the model.
@@ -136,8 +125,7 @@ def infer_async(self, dict_data, callback_fn, callback_data):
136125

137126
@abc.abstractmethod
138127
def is_ready(self):
139-
"""
140-
In case of asynchronous execution checks if one can submit input data
128+
"""In case of asynchronous execution checks if one can submit input data
141129
to the model for inference, or all infer requests are busy.
142130
143131
Returns:
@@ -147,38 +135,32 @@ def is_ready(self):
147135

148136
@abc.abstractmethod
149137
def await_all(self):
150-
"""
151-
In case of asynchronous execution waits the completion of all
138+
"""In case of asynchronous execution waits the completion of all
152139
busy infer requests.
153140
"""
154141

155142
@abc.abstractmethod
156143
def await_any(self):
157-
"""
158-
In case of asynchronous execution waits the completion of any
144+
"""In case of asynchronous execution waits the completion of any
159145
busy infer request until it becomes available for the data submission.
160146
"""
161147

162148
@abc.abstractmethod
163149
def get_rt_info(self, path):
164-
"""
165-
Forwards to openvino.Model.get_rt_info(path)
166-
"""
150+
"""Forwards to openvino.Model.get_rt_info(path)"""
167151

168152
@abc.abstractmethod
169153
def embed_preprocessing(
170154
self,
171155
layout,
172156
resize_mode: str,
173157
interpolation_mode,
174-
target_shape: Tuple[int],
158+
target_shape: tuple[int],
175159
pad_value,
176160
dtype: type = int,
177161
brg2rgb=False,
178162
mean=None,
179163
scale=None,
180164
input_idx=0,
181165
):
182-
"""
183-
Embeds preprocessing into the model using OpenVINO preprocessing API
184-
"""
166+
"""Embeds preprocessing into the model using OpenVINO preprocessing API"""

0 commit comments

Comments
 (0)