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

Clean up build.py #19156

Closed
wants to merge 23 commits into from

dotnet tool install --global protoc

64e8252
Select commit
Loading
Failed to load commit list.
Closed

Clean up build.py #19156

dotnet tool install --global protoc
64e8252
Select commit
Loading
Failed to load commit list.
GitHub Advanced Security / lintrunner failed May 21, 2024 in 4s

27 new alerts including 1 error

New alerts in code changed by this pull request

  • 1 error
  • 25 warnings
  • 1 note

See annotations below for details.

View all branch alerts.

Annotations

Check warning on line 23 in tools/ci_build/build.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/E402 Warning

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file

Check warning on line 47 in tools/ci_build/build.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/RUF100 Warning

Unused noqa directive (unused: E402).
See https://docs.astral.sh/ruff/rules/unused-noqa

Check warning on line 9 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.version\_to\_tuple imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 10 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.check\_python\_version imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 11 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.str\_to\_bool imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 12 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.is\_reduced\_ops\_build imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 13 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.resolve\_executable\_path imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 14 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.get\_config\_build\_dir imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 15 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.use\_dev\_mode imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 16 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.add\_default\_definition imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 17 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.normalize\_arg\_list imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 18 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.number\_of\_parallel\_jobs imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 19 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.number\_of\_nvcc\_threads imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 27 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.open\_vino\_utils.openvino\_verify\_device\_type imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check notice on line 1 in tools/python/util/build_helpers.py

See this annotation in the file changed.

Code scanning / lintrunner

BLACK-ISORT/command-failed Note

COMMAND (exit code 123)
/opt/hostedtoolcache/Python/3.10.14/x64/bin/python -mblack --stdin-filename /home/runner/work/onnxruntime/onnxruntime/tools/python/util/build_helpers.py - STDERR
error: cannot format /home/runner/work/onnxruntime/onnxruntime/tools/python/util/build_helpers.py: Cannot parse: 198:45: f" valid={cudnn_home_valid}",, Oh no! 💥 💔 💥
1 file failed to reformat. STDOUT // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. import contextlib
import os
import shutil
import sys from .build_errors import BuildError, UsageError
from .platform_helpers import is_macOS, is_windows def version_to_tuple(version: str) -> tuple:
v = []
for s in version.split("."):
with contextlib.suppress(ValueError):
v.append(int(s))
return tuple(v) def check_python_version():
required_minor_version = 8
if (sys.version_info.major, sys.version_info.minor) < (3, required_minor_version):
raise UsageError(
f"Invalid Python version. At least Python 3.{required_minor_version} is required. "
f"Actual Python version: {sys.version}"
) def str_to_bool(s):
"""Convert string to bool (in argparse context)."""
if s.lower() not in ["true", "false"]:
raise ValueError("Need bool; got %r" % s)
return {"true": True, "false": False}[s.lower()] def is_reduced_ops_build(args):
return args.include_ops_by_config is not None def resolve_executable_path(command_or_path):
"""Returns the absolute path of an executable."""
if command_or_path and command_or_path.strip():
executable_path = shutil.which(command_or_path)
if executable_path is None:
raise BuildError(f"Failed to resolve executable path for '{command_or_path}'.")
return os.path.abspath(executable_path)
else:
return None def get_config_build_dir(build_dir, config):
# build directory per configuration
return os.path.join(build_dir, config) def use_dev_mode(args):
if args.compile_no_warning_as_error:
return False
if args.use_acl:
return False
if args.use_armnn:
return False
if args.ios and is_macOS() or args.visionos:
return False
SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806
if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/":
return False
return True def add_default_definition(definition_list, key, default_value):
for x in definition_list:
if x.startswith(key + "="):
return
definition_list.append(key + "=" + default_value) def normalize_arg_list(nested_list):
return [i for j in nested_list for i in j] if nested_list else [] def number_of_parallel_jobs(args):
return os.cpu_count() if args.parallel == 0 else args.parallel def number_of_nvcc_threads(args):
if args.nvcc_threads >= 0:
return args.nvcc_threads
nvcc_threads = 1
try:
import psutil
available_memory = psutil.virtual_memory().available
if isinstance(available_memory, int) and available_memory > 0:
if available_memory > 60 * 1024 * 1024 * 1024:
# When available memory is large enough, chance of OOM is small.
nvcc_threads = 4
else:
# NVCC need a lot of memory to compile 8 flash attention cu files in Linux or 4 cutlass fmha cu files
# in Windows. Here we select number of threads to ensure each thread has enough memory (>= 4 GB). For
# example, Standard_NC4as_T4_v3 has 4 CPUs and 28 GB memory. When parallel=4 and nvcc_threads=2,
# total nvcc threads is 4 * 2, which is barely able to build in 28 GB memory so we will use
# nvcc_threads=1.
memory_per_thread = 4 * 1024 * 1024 * 1024
fmha_cu_files = 4 if is_windows() else 16
fmha_parallel_jobs = min(fmha_cu_files, number_of_parallel_jobs(args))
nvcc_thre

Check warning on line 20 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.setup\_cann\_vars imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 21 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.setup\_tensorrt\_vars imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 22 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.setup\_migraphx\_vars imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 23 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_helpers.setup\_cuda\_vars imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 26 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_errors.BaseError imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 26 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_errors.BuildError imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check warning on line 26 in tools/python/util/__init__.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/F401 Warning

.build\_errors.UsageError imported but unused; consider adding to \_\_all\_\_ or using a redundant alias.
See https://docs.astral.sh/ruff/rules/unused-import

Check failure on line 197 in tools/python/util/build_helpers.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/E999 Error

SyntaxError: Unexpected token ','.
See https://docs.astral.sh/ruff/rules/syntax-error

Check warning on line 53 in tools/python/util/open_vino_utils.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/PIE810 Warning

Call startswith once with a tuple.
See https://docs.astral.sh/ruff/rules/multiple-starts-ends-with

Check warning on line 82 in tools/python/util/open_vino_utils.py

See this annotation in the file changed.

Code scanning / lintrunner

RUFF/PIE810 Warning

Call startswith once with a tuple.
See https://docs.astral.sh/ruff/rules/multiple-starts-ends-with