diff options
-rw-r--r-- | .pre-commit-config.yaml | 6 | ||||
-rw-r--r-- | src/mlia/backend/application.py | 4 | ||||
-rw-r--r-- | src/mlia/backend/execution.py | 6 | ||||
-rw-r--r-- | src/mlia/backend/proc.py | 2 | ||||
-rw-r--r-- | src/mlia/cli/config.py | 8 | ||||
-rw-r--r-- | src/mlia/cli/logging.py | 4 | ||||
-rw-r--r-- | src/mlia/core/events.py | 2 | ||||
-rw-r--r-- | src/mlia/devices/ethosu/reporters.py | 2 | ||||
-rw-r--r-- | src/mlia/tools/metadata/common.py | 4 | ||||
-rw-r--r-- | src/mlia/utils/filesystem.py | 4 | ||||
-rw-r--r-- | tests/test_backend_output_consumer.py | 4 |
11 files changed, 25 insertions, 21 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2d4e450..2d87aa6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,12 @@ repos: - id: reorder-python-imports args: ["--application-directories", ".:src"] +- repo: https://github.com/asottile/pyupgrade + rev: v2.38.0 + hooks: + - id: pyupgrade + args: ["--py38-plus"] + - repo: https://github.com/psf/black rev: 22.3.0 hooks: diff --git a/src/mlia/backend/application.py b/src/mlia/backend/application.py index a093afe..a5d99f7 100644 --- a/src/mlia/backend/application.py +++ b/src/mlia/backend/application.py @@ -88,11 +88,11 @@ def remove_application(directory_name: str) -> None: def get_unique_application_names(system_name: str | None = None) -> list[str]: """Extract a list of unique application names of all application available.""" return list( - set( + { application.name for application in get_available_applications() if not system_name or application.can_run_on(system_name) - ) + } ) diff --git a/src/mlia/backend/execution.py b/src/mlia/backend/execution.py index f3fe401..5c8e53f 100644 --- a/src/mlia/backend/execution.py +++ b/src/mlia/backend/execution.py @@ -143,10 +143,8 @@ class ParamResolver: if not param_value: raise ConfigurationException( - ( - "No value for parameter with index or " - f"alias {index_or_alias} of command {cmd_name}." - ) + "No value for parameter with index or " + f"alias {index_or_alias} of command {cmd_name}." ) return param_value diff --git a/src/mlia/backend/proc.py b/src/mlia/backend/proc.py index 7b3e92a..4838e47 100644 --- a/src/mlia/backend/proc.py +++ b/src/mlia/backend/proc.py @@ -66,7 +66,7 @@ class ShellCommand: out, err = _out, _err if not _out and not _err: - out, err = [str(item) for item in self.get_stdout_stderr_paths(cmd)] + out, err = (str(item) for item in self.get_stdout_stderr_paths(cmd)) return command(_out=out, _err=err, _tee=_tee, _bg=_bg, _bg_exc=False) diff --git a/src/mlia/cli/config.py b/src/mlia/cli/config.py index dc28fa2..30373e4 100644 --- a/src/mlia/cli/config.py +++ b/src/mlia/cli/config.py @@ -29,11 +29,9 @@ def get_available_backends() -> list[str]: # Add backends using backend manager manager = get_installation_manager() available_backends.extend( - ( - backend - for backend in backend_manager.supported_backends() - if manager.backend_installed(backend) - ) + backend + for backend in backend_manager.supported_backends() + if manager.backend_installed(backend) ) return available_backends diff --git a/src/mlia/cli/logging.py b/src/mlia/cli/logging.py index 40f47d3..e786394 100644 --- a/src/mlia/cli/logging.py +++ b/src/mlia/cli/logging.py @@ -31,10 +31,10 @@ def setup_logging( :param verbose: enable extended logging for the tools loggers :param log_filename: name of the log file in the logs directory """ - mlia_logger, *tools_loggers = [ + mlia_logger, *tools_loggers = ( logging.getLogger(logger_name) for logger_name in ["mlia", "tensorflow", "py.warnings"] - ] + ) # enable debug output, actual message filtering depends on # the provided parameters and being done on the handlers level diff --git a/src/mlia/core/events.py b/src/mlia/core/events.py index 71c86e2..e328cc1 100644 --- a/src/mlia/core/events.py +++ b/src/mlia/core/events.py @@ -284,7 +284,7 @@ class EventDispatcherMetaclass(type): event_handler_methods = ( (item_name, item) for item_name in dir(new_class) - if callable((item := getattr(new_class, item_name))) + if callable(item := getattr(new_class, item_name)) and item_name.startswith(event_handler_method_prefix) ) diff --git a/src/mlia/devices/ethosu/reporters.py b/src/mlia/devices/ethosu/reporters.py index f11430c..9181043 100644 --- a/src/mlia/devices/ethosu/reporters.py +++ b/src/mlia/devices/ethosu/reporters.py @@ -41,7 +41,7 @@ def report_operators_stat(operators: Operators) -> Report: operators.npu_supported_number, Cell( operators.npu_unsupported_ratio * 100, - fmt=Format(str_fmt="{0:.0f}%".format), + fmt=Format(str_fmt="{:.0f}%".format), ), ) ] diff --git a/src/mlia/tools/metadata/common.py b/src/mlia/tools/metadata/common.py index 32da4a4..dd4571a 100644 --- a/src/mlia/tools/metadata/common.py +++ b/src/mlia/tools/metadata/common.py @@ -199,7 +199,7 @@ class DefaultInstallationManager(InstallationManager, InstallationFiltersMixin): return None if len(installs) != 1: - names = ",".join((install.name for install in installs)) + names = ",".join(install.name for install in installs) logger.info( "Unable to correctly detect type of the installed FVP." "The following FVPs are detected %s. Installation skipped.", @@ -241,7 +241,7 @@ class DefaultInstallationManager(InstallationManager, InstallationFiltersMixin): logger.info("No backends available for the installation.") return - names = ",".join((installation.name for installation in installations)) + names = ",".join(installation.name for installation in installations) logger.info("Following backends are available for downloading: %s", names) for installation in installations: diff --git a/src/mlia/utils/filesystem.py b/src/mlia/utils/filesystem.py index 25619c5..fcd09b5 100644 --- a/src/mlia/utils/filesystem.py +++ b/src/mlia/utils/filesystem.py @@ -97,7 +97,9 @@ def file_chunks( yield data -def hexdigest(filepath: str | Path, hash_obj: "hashlib._Hash") -> str: +def hexdigest( + filepath: str | Path, hash_obj: hashlib._Hash # pylint: disable=no-member +) -> str: """Return hex digest of the file.""" for chunk in file_chunks(filepath): hash_obj.update(chunk) diff --git a/tests/test_backend_output_consumer.py b/tests/test_backend_output_consumer.py index 2ecb07f..2a46787 100644 --- a/tests/test_backend_output_consumer.py +++ b/tests/test_backend_output_consumer.py @@ -79,9 +79,9 @@ def test_base64_output_consumer(expected_metrics: dict) -> None: json_b64 = base64.b64encode(json_str.encode("utf-8")) return ( OUTPUT_MATCH_ALL # Should not be matched by the Base64OutputConsumer - + f"<{Base64OutputConsumer.TAG_NAME}>".encode("utf-8") + + f"<{Base64OutputConsumer.TAG_NAME}>".encode() + bytearray(json_b64) - + f"</{Base64OutputConsumer.TAG_NAME}>".encode("utf-8") + + f"</{Base64OutputConsumer.TAG_NAME}>".encode() + OUTPUT_NO_MATCH # Just to add some difficulty... ) |