Skip to content

Commit 3557420

Browse files
Bump ruff from 0.11.13 to 0.12.2, clang-format from 19.1.7 to 20.1.7 (microsoft#25301)
1 parent 73e0a4b commit 3557420

File tree

187 files changed

+1092
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+1092
-984
lines changed

.vscode/settings.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88
],
99
"[python]": {
1010
"editor.tabSize": 4,
11-
// Auto sort imports
12-
"editor.formatOnSave": true,
13-
"editor.codeActionsOnSave": {
14-
"source.organizeImports": "explicit"
15-
},
16-
"editor.defaultFormatter": "ms-python.black-formatter"
1711
},
18-
// Enable Python linting and Pylance type checking
19-
"python.analysis.typeCheckingMode": "basic",
2012
"cpplint.lineLength": 120,
2113
"cpplint.filters": [
2214
"-build/include_subdir",

csharp/tools/MauiModelTester/create_test_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def parse_args():
8484

8585

8686
def create_existing_data_map(pb_files: list[Path]):
87-
import onnx_test_data_utils as data_utils
87+
import onnx_test_data_utils as data_utils # noqa: PLC0415
8888

8989
data_map = {}
9090
for file in pb_files:
@@ -101,7 +101,7 @@ def add_model_and_test_data_to_app(
101101
input_map: dict[str, np.ndarray] | None = None,
102102
output_map: dict[str, np.ndarray] | None = None,
103103
):
104-
import ort_test_dir_utils as utils
104+
import ort_test_dir_utils as utils # noqa: PLC0415
105105

106106
output_path = SOLUTION_DIR / "Resources" / "Raw"
107107
test_name = "test_data"

docs/python/_common/onnx_sphinx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def get_template():
2525
try:
26-
from jinja2 import Template
26+
from jinja2 import Template # noqa: PLC0415
2727
except ImportError: # pragma no cover
2828

2929
class Template:
@@ -251,7 +251,7 @@ def _clean_unicode(text):
251251

252252

253253
def _populate__get_all_schemas_with_history():
254-
import onnxruntime.capi.onnxruntime_pybind11_state as rtpy
254+
import onnxruntime.capi.onnxruntime_pybind11_state as rtpy # noqa: PLC0415
255255

256256
get_schemas = rtpy.get_all_operator_schema or rtpy.get_all_opkernel_def
257257

@@ -885,7 +885,7 @@ def setup(app):
885885
Sphinx extension `onnx_sphinx` displays documentation
886886
of all ONNX Operators.
887887
"""
888-
import sphinx
888+
import sphinx # noqa: PLC0415
889889

890890
app.add_config_value("onnx_doc_folder", "operators", "env")
891891
app.add_config_value("max_opsets", {}, "env")

docs/python/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def setup(app):
119119
this = os.path.abspath(os.path.dirname(__file__))
120120
dest = os.path.join(this, "model.onnx")
121121
if not os.path.exists(dest):
122-
import urllib.request
122+
import urllib.request # noqa: PLC0415
123123

124124
url = "https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_sigmoid/model.onnx"
125125
urllib.request.urlretrieve(url, dest)

onnxruntime/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696

9797
def _get_package_version(package_name: str):
98-
from importlib.metadata import PackageNotFoundError, version
98+
from importlib.metadata import PackageNotFoundError, version # noqa: PLC0415
9999

100100
try:
101101
package_version = version(package_name)
@@ -105,7 +105,7 @@ def _get_package_version(package_name: str):
105105

106106

107107
def _get_package_root(package_name: str, directory_name: str | None = None):
108-
from importlib.metadata import PackageNotFoundError, distribution
108+
from importlib.metadata import PackageNotFoundError, distribution # noqa: PLC0415
109109

110110
root_directory_name = directory_name or package_name
111111
try:
@@ -167,10 +167,10 @@ def _get_nvidia_dll_paths(is_windows: bool, cuda: bool = True, cudnn: bool = Tru
167167

168168
def print_debug_info():
169169
"""Print information to help debugging."""
170-
import importlib.util
171-
import os
172-
import platform
173-
from importlib.metadata import distributions
170+
import importlib.util # noqa: PLC0415
171+
import os # noqa: PLC0415
172+
import platform # noqa: PLC0415
173+
from importlib.metadata import distributions # noqa: PLC0415
174174

175175
print(f"{package_name} version: {__version__}")
176176
if cuda_version:
@@ -227,7 +227,7 @@ def is_target_dll(path: str):
227227
target_keywords = ["cufft", "cublas", "cudart", "nvrtc", "curand", "cudnn", *target_keywords]
228228
return any(keyword in path for keyword in target_keywords)
229229

230-
import psutil
230+
import psutil # noqa: PLC0415
231231

232232
p = psutil.Process(os.getpid())
233233

@@ -238,7 +238,7 @@ def is_target_dll(path: str):
238238

239239
if cuda_version:
240240
if importlib.util.find_spec("cpuinfo") and importlib.util.find_spec("py3nvml"):
241-
from .transformers.machine_info import get_device_info
241+
from .transformers.machine_info import get_device_info # noqa: PLC0415
242242

243243
print("\nDevice information:")
244244
print(get_device_info())
@@ -265,10 +265,10 @@ def preload_dlls(cuda: bool = True, cudnn: bool = True, msvc: bool = True, direc
265265
If directory is empty string (""), the search order: nvidia site packages, default DLL loading paths.
266266
If directory is a path, the search order: the directory, default DLL loading paths.
267267
"""
268-
import ctypes
269-
import os
270-
import platform
271-
import sys
268+
import ctypes # noqa: PLC0415
269+
import os # noqa: PLC0415
270+
import platform # noqa: PLC0415
271+
import sys # noqa: PLC0415
272272

273273
if platform.system() not in ["Windows", "Linux"]:
274274
return

onnxruntime/contrib_ops/cuda/bert/attention_softmax.cu

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ namespace onnxruntime {
2929
namespace contrib {
3030
namespace attention_softmax_cuda {
3131

32-
#define DISPATCH_BIAS(attn_bias, HAS_BIAS, ...) \
33-
[&] { \
34-
const dim3 grid(num_heads* sequence_length, batch_size, 1); \
35-
if (attn_bias != nullptr) { \
36-
constexpr static bool HAS_BIAS = true; \
37-
return __VA_ARGS__(); \
38-
} else { \
39-
constexpr static bool HAS_BIAS = false; \
40-
return __VA_ARGS__(); \
41-
} \
32+
#define DISPATCH_BIAS(attn_bias, HAS_BIAS, ...) \
33+
[&] { \
34+
const dim3 grid(num_heads * sequence_length, batch_size, 1); \
35+
if (attn_bias != nullptr) { \
36+
constexpr static bool HAS_BIAS = true; \
37+
return __VA_ARGS__(); \
38+
} else { \
39+
constexpr static bool HAS_BIAS = false; \
40+
return __VA_ARGS__(); \
41+
} \
4242
}()
4343

4444
// Macro to declare variables:

onnxruntime/core/providers/coreml/mlprogram_test_scripts/div_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def nn_scale():
7676
mode="MULTIPLY",
7777
)
7878

79-
from coremltools.models.utils import save_spec
79+
from coremltools.models.utils import save_spec # noqa: PLC0415
8080

8181
save_spec(builder.spec, "network.mlmodel")
8282
m = ct.models.MLModel("network.mlmodel")

onnxruntime/core/providers/webgpu/program.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,18 @@ class ProgramWrapper : public ProgramBase {
401401
#define ORT_WEBGPU_REGISTER_DERIVED_PROGRAM_CLASS_TYPE_CHECK(identifier, element_type) \
402402
private: \
403403
template <typename U> \
404-
static auto test_has_##identifier(int)->decltype(U::identifier, std::true_type{}); /* checks if member exists */ \
404+
static auto test_has_##identifier(int) -> decltype(U::identifier, std::true_type{}); /* checks if member exists */ \
405405
template <typename...> \
406-
static auto test_has_##identifier(...)->std::false_type; \
406+
static auto test_has_##identifier(...) -> std::false_type; \
407407
\
408408
template <typename U, /* The following type check uses SFINAE */ \
409409
typename = std::enable_if_t< /* to ensure the specific member: */ \
410410
is_const_std_array<decltype(U::identifier)>::value && /* - is a const std::array */ \
411411
std::is_const_v<decltype(U::identifier)> && /* - has "const" modifier */ \
412412
!std::is_member_pointer_v<decltype(&U::identifier)>>> /* - is static */ \
413-
static auto test_has_##identifier##_with_correct_type(int)->std::true_type; \
413+
static auto test_has_##identifier##_with_correct_type(int) -> std::true_type; \
414414
template <typename...> \
415-
static auto test_has_##identifier##_with_correct_type(...)->std::false_type; \
415+
static auto test_has_##identifier##_with_correct_type(...) -> std::false_type; \
416416
\
417417
public: \
418418
static constexpr bool has_##identifier = decltype(test_has_##identifier<T>(0))::value; \

onnxruntime/python/onnxruntime_validation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def check_distro_info():
5757
f"Unsupported macOS version ({__my_distro_ver__}). ONNX Runtime supports macOS 11.0 or later."
5858
)
5959
elif __my_system__ == "aix":
60-
import subprocess
60+
import subprocess # noqa: PLC0415
6161

6262
returned_output = subprocess.check_output("oslevel")
6363
__my_distro_ver__str = returned_output.decode("utf-8")
@@ -74,11 +74,11 @@ def get_package_name_and_version_info():
7474
cuda_version = ""
7575

7676
try:
77-
from .build_and_package_info import __version__ as version
78-
from .build_and_package_info import package_name
77+
from .build_and_package_info import __version__ as version # noqa: PLC0415
78+
from .build_and_package_info import package_name # noqa: PLC0415
7979

8080
try: # noqa: SIM105
81-
from .build_and_package_info import cuda_version
81+
from .build_and_package_info import cuda_version # noqa: PLC0415
8282
except ImportError:
8383
# cuda_version is optional. For example, cpu only package does not have the attribute.
8484
pass
@@ -94,7 +94,7 @@ def check_training_module():
9494

9595
has_ortmodule = False
9696
try:
97-
from onnxruntime.training.ortmodule import ORTModule # noqa: F401
97+
from onnxruntime.training.ortmodule import ORTModule # noqa: F401, PLC0415
9898

9999
has_ortmodule = True
100100
except ImportError:
@@ -105,7 +105,7 @@ def check_training_module():
105105
# for any exception other than not having ortmodule, we want to continue
106106
# device version validation and raise the exception after.
107107
try:
108-
from onnxruntime.training.ortmodule._fallback import ORTModuleInitException
108+
from onnxruntime.training.ortmodule._fallback import ORTModuleInitException # noqa: PLC0415
109109

110110
if isinstance(e, ORTModuleInitException):
111111
# ORTModule is present but not ready to run yet
@@ -125,7 +125,7 @@ def check_training_module():
125125
# collect cuda library build info. the library info may not be available
126126
# when the build environment has none or multiple libraries installed
127127
try:
128-
from .build_and_package_info import cudart_version
128+
from .build_and_package_info import cudart_version # noqa: PLC0415
129129
except ImportError:
130130
warnings.warn("WARNING: failed to get cudart_version from onnxruntime build info.")
131131
cudart_version = None
@@ -137,7 +137,7 @@ def print_build_package_info():
137137
warnings.warn(f"onnxruntime build info: cudart_version: {cudart_version}")
138138

139139
# collection cuda library info from current environment.
140-
from onnxruntime.capi.onnxruntime_collect_build_info import find_cudart_versions
140+
from onnxruntime.capi.onnxruntime_collect_build_info import find_cudart_versions # noqa: PLC0415
141141

142142
local_cudart_versions = find_cudart_versions(build_env=False, build_cuda_version=cuda_version)
143143
if cudart_version and local_cudart_versions and cudart_version not in local_cudart_versions:

onnxruntime/python/tools/pytorch_export_contrib_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def unregister():
121121
# The symbolic_registry module was removed in PyTorch 1.13.
122122
# We are importing it here for backwards compatibility
123123
# because unregister_custom_op_symbolic is not available before PyTorch 1.12
124-
from torch.onnx import symbolic_registry
124+
from torch.onnx import symbolic_registry # noqa: PLC0415
125125

126126
namespace, kind = name.split("::")
127127
for version in symbolic_helper._onnx_stable_opsets:

0 commit comments

Comments
 (0)