From e5a0bc3ecd4d9c46ead3b8217584eaa916a3afa4 Mon Sep 17 00:00:00 2001 From: Benjamin Klimczak Date: Thu, 24 Aug 2023 16:38:47 +0100 Subject: MLIA-961 Update tox dependencies - Update version dependencies in the tox.ini - Fix linter issues Change-Id: I04c3a841ee2646a865dab037701d66c28792f2a4 Signed-off-by: Benjamin Klimczak --- src/mlia/backend/corstone/install.py | 2 +- src/mlia/backend/install.py | 8 ++++---- src/mlia/backend/repo.py | 12 ++++++------ src/mlia/backend/vela/compiler.py | 8 +++++--- src/mlia/backend/vela/performance.py | 4 +++- 5 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/mlia/backend') diff --git a/src/mlia/backend/corstone/install.py b/src/mlia/backend/corstone/install.py index 35976cf..d6101cf 100644 --- a/src/mlia/backend/corstone/install.py +++ b/src/mlia/backend/corstone/install.py @@ -51,7 +51,7 @@ class Corstone300Installer: # this instance subprocess.check_call(fvp_install_cmd) # nosec except subprocess.CalledProcessError as err: - raise Exception( + raise RuntimeError( "Error occurred during Corstone-300 installation" ) from err diff --git a/src/mlia/backend/install.py b/src/mlia/backend/install.py index 4745f19..721b660 100644 --- a/src/mlia/backend/install.py +++ b/src/mlia/backend/install.py @@ -145,7 +145,7 @@ class BackendInstallation(Installation): assert backend_info is not None, "Unable to resolve backend path" self._install_from(backend_info) else: - raise Exception(f"Unable to install {install_type}") + raise RuntimeError(f"Unable to install {install_type}.") def _install_from(self, backend_info: BackendInfo) -> None: """Install backend from the directory.""" @@ -173,7 +173,7 @@ class BackendInstallation(Installation): try: downloaded_to = download_artifact.download_to(tmpdir) except Exception as err: - raise Exception("Unable to download backend artifact") from err + raise RuntimeError("Unable to download backend artifact.") from err with working_directory(tmpdir / "dist", create_dir=True) as dist_dir: with tarfile.open(downloaded_to) as archive: @@ -184,7 +184,7 @@ class BackendInstallation(Installation): backend_path = self.backend_installer(eula_agrement, dist_dir) if self.path_checker(backend_path) is None: - raise Exception("Downloaded artifact has invalid structure") + raise ValueError("Downloaded artifact has invalid structure.") self.install(InstallFromPath(backend_path)) @@ -311,7 +311,7 @@ class PyPackageBackendInstallation(Installation): def install(self, install_type: InstallationType) -> None: """Install the backend.""" if not self.supports(install_type): - raise Exception(f"Unsupported installation type {install_type}") + raise ValueError(f"Unsupported installation type {install_type}.") self.package_manager.install(self._packages_to_install) diff --git a/src/mlia/backend/repo.py b/src/mlia/backend/repo.py index 3dd2e57..b64a46a 100644 --- a/src/mlia/backend/repo.py +++ b/src/mlia/backend/repo.py @@ -109,7 +109,7 @@ class BackendRepository: repo_backend_path = self._get_backend_path(backend_dir_name) if repo_backend_path.exists(): - raise Exception(f"Unable to copy backend files for {backend_name}.") + raise RuntimeError(f"Unable to copy backend files for {backend_name}.") copy_all(backend_path, dest=repo_backend_path) @@ -126,7 +126,7 @@ class BackendRepository: ) -> None: """Add backend to repository.""" if self.is_backend_installed(backend_name): - raise Exception(f"Backend {backend_name} already installed.") + raise RuntimeError(f"Backend {backend_name} already installed.") settings = settings or {} settings["backend_path"] = backend_path.absolute().as_posix() @@ -138,7 +138,7 @@ class BackendRepository: settings = self.config_file.get_backend_settings(backend_name) if not settings: - raise Exception(f"Backend {backend_name} is not installed.") + raise RuntimeError(f"Backend {backend_name} is not installed.") if "backend_dir" in settings: repo_backend_path = self._get_backend_path(settings["backend_dir"]) @@ -155,7 +155,7 @@ class BackendRepository: settings = self.config_file.get_backend_settings(backend_name) if not settings: - raise Exception(f"Backend {backend_name} is not installed.") + raise RuntimeError(f"Backend {backend_name} is not installed.") if backend_dir := settings.get("backend_dir", None): return self._get_backend_path(backend_dir), settings @@ -163,7 +163,7 @@ class BackendRepository: if backend_path := settings.get("backend_path", None): return Path(backend_path), settings - raise Exception(f"Unable to resolve path of the backend {backend_name}.") + raise RuntimeError(f"Unable to resolve path of the backend {backend_name}.") def _get_backend_path(self, backend_dir_name: str) -> Path: """Return path to backend.""" @@ -173,7 +173,7 @@ class BackendRepository: """Init repository.""" if self.repository.exists(): if not self.config_file.exists(): - raise Exception( + raise RuntimeError( f"Directory {self.repository} could not be used as MLIA repository." ) else: diff --git a/src/mlia/backend/vela/compiler.py b/src/mlia/backend/vela/compiler.py index afad05b..78f97b2 100644 --- a/src/mlia/backend/vela/compiler.py +++ b/src/mlia/backend/vela/compiler.py @@ -129,7 +129,7 @@ class VelaCompiler: # pylint: disable=too-many-instance-attributes nng, network_type = model.nng, NetworkType.TFLite if not nng: - raise Exception("Unable to read model") + raise ValueError("Unable to read model: model.nng is not available") output_basename = f"{self.output_dir}/{nng.name}" @@ -152,7 +152,9 @@ class VelaCompiler: # pylint: disable=too-many-instance-attributes return OptimizedModel(nng, arch, compiler_options, scheduler_options) except (SystemExit, Exception) as err: - raise Exception("Model could not be optimized with Vela compiler") from err + raise RuntimeError( + "Model could not be optimized with Vela compiler." + ) from err def get_config(self) -> dict[str, Any]: """Get compiler configuration.""" @@ -200,7 +202,7 @@ class VelaCompiler: # pylint: disable=too-many-instance-attributes ): return read_model(model_path, ModelReaderOptions()) # type: ignore except (SystemExit, Exception) as err: - raise Exception(f"Unable to read model {model_path}") from err + raise RuntimeError(f"Unable to read model {model_path}.") from err def _architecture_features(self) -> ArchitectureFeatures: """Return ArchitectureFeatures instance.""" diff --git a/src/mlia/backend/vela/performance.py b/src/mlia/backend/vela/performance.py index e545b85..a548b26 100644 --- a/src/mlia/backend/vela/performance.py +++ b/src/mlia/backend/vela/performance.py @@ -56,7 +56,9 @@ def estimate_performance( initial_model = vela_compiler.read_model(model_path) if initial_model.optimized: - raise Exception("Unable to estimate performance for the given optimized model") + raise ValueError( + "Unable to estimate performance for the given optimized model." + ) optimized_model = vela_compiler.compile_model(initial_model) -- cgit v1.2.1