diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 744201d..585b4d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: 'test_hookman_generator/.*' repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.21 + rev: v0.16.0 hooks: - id: ruff-check args: ["--fix"] diff --git a/docs/source/conf.py b/docs/source/conf.py index 6567041..97fece0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # diff --git a/setup.py b/setup.py index ae13b93..8698b14 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup with open("README.rst") as readme_file: readme = readme_file.read() diff --git a/src/hookman/hookman_generator.py b/src/hookman/hookman_generator.py index 1d00134..ada9e5a 100644 --- a/src/hookman/hookman_generator.py +++ b/src/hookman/hookman_generator.py @@ -5,16 +5,12 @@ from collections.abc import Mapping from pathlib import Path from textwrap import dedent -from typing import Any -from typing import NamedTuple +from typing import Any, NamedTuple from zipfile import ZipFile -from hookman.exceptions import ArtifactsDirNotFoundError -from hookman.exceptions import AssetsDirNotFoundError -from hookman.exceptions import HookmanError +from hookman.exceptions import ArtifactsDirNotFoundError, AssetsDirNotFoundError, HookmanError from hookman.hooks import HookSpecs -from hookman.plugin_config import PLUGIN_CONFIG_SCHEMA -from hookman.plugin_config import PluginInfo +from hookman.plugin_config import PLUGIN_CONFIG_SCHEMA, PluginInfo class Hook(NamedTuple): @@ -87,7 +83,7 @@ def _import_hook_specs_from_module(self, hook_spec_file_path: Path) -> HookSpecs assert module is not None, f"Could not find module for {hook_spec_file_path}" spec.loader.exec_module(module) try: - specs = getattr(module, "specs") + specs = module.specs except AttributeError: raise RuntimeError(f"Invalid module {module}, 'specs' variable not defined.") else: diff --git a/src/hookman/hookman_utils.py b/src/hookman/hookman_utils.py index b5f6cc6..5f978c6 100644 --- a/src/hookman/hookman_utils.py +++ b/src/hookman/hookman_utils.py @@ -1,8 +1,7 @@ import ctypes import os import sys -from collections.abc import Iterator -from collections.abc import Sequence +from collections.abc import Iterator, Sequence from contextlib import contextmanager from pathlib import Path @@ -108,12 +107,11 @@ def load_shared_lib(shared_lib_path: str) -> Iterator[ctypes.CDLL]: If the shared library exists but fails to load, e.g. because of an incompatible or missing dependency DLL. """ - with change_path_env(shared_lib_path): - with suppress_dll_error_dialog(): - try: - plugin_dll = ctypes.cdll.LoadLibrary(shared_lib_path) - except OSError as error: - raise SharedLibraryLoadError(Path(shared_lib_path), str(error)) from error + with change_path_env(shared_lib_path), suppress_dll_error_dialog(): + try: + plugin_dll = ctypes.cdll.LoadLibrary(shared_lib_path) + except OSError as error: + raise SharedLibraryLoadError(Path(shared_lib_path), str(error)) from error try: yield plugin_dll diff --git a/src/hookman/hooks.py b/src/hookman/hooks.py index bfc3f92..ac7854d 100644 --- a/src/hookman/hooks.py +++ b/src/hookman/hooks.py @@ -1,8 +1,7 @@ import inspect import logging import shutil -from collections.abc import Callable -from collections.abc import Sequence +from collections.abc import Callable, Sequence from dataclasses import dataclass from pathlib import Path from zipfile import ZipFile @@ -11,10 +10,12 @@ from pluggy import HookCaller from hookman import hookman_utils -from hookman.exceptions import InvalidDestinationPathError -from hookman.exceptions import PluginAlreadyInstalledError -from hookman.exceptions import SharedLibraryLoadError -from hookman.exceptions import SharedLibraryNotFoundError +from hookman.exceptions import ( + InvalidDestinationPathError, + PluginAlreadyInstalledError, + SharedLibraryLoadError, + SharedLibraryNotFoundError, +) from hookman.hookman_utils import change_path_env from hookman.plugin_config import PluginInfo @@ -212,9 +213,12 @@ def remove_plugin(self, caption: str, version: Version | None = None) -> None: root_dir = plugin_dir.parent remove_plugin = False - if version is None and caption in plugin_dir.name: - remove_plugin = True - elif plugin.id == caption and version == plugin.version: + if ( + version is None + and caption in plugin_dir.name + or plugin.id == caption + and version == plugin.version + ): remove_plugin = True if remove_plugin: diff --git a/src/hookman/plugin_config.py b/src/hookman/plugin_config.py index 912ff3a..76e2d59 100644 --- a/src/hookman/plugin_config.py +++ b/src/hookman/plugin_config.py @@ -1,18 +1,12 @@ import ctypes import sys from collections.abc import Sequence -from dataclasses import dataclass -from dataclasses import field +from dataclasses import dataclass, field from pathlib import Path from zipfile import ZipFile from packaging.version import Version -from strictyaml import Map -from strictyaml import MapPattern -from strictyaml import Optional -from strictyaml import Str -from strictyaml import YAML -from strictyaml import YAMLValidationError +from strictyaml import YAML, Map, MapPattern, Optional, Str, YAMLValidationError from hookman.exceptions import SharedLibraryNotFoundError from hookman.hookman_utils import load_shared_lib diff --git a/tests/test_hookman_generator.py b/tests/test_hookman_generator.py index 2a0faf9..8d9868a 100644 --- a/tests/test_hookman_generator.py +++ b/tests/test_hookman_generator.py @@ -301,9 +301,10 @@ def test_generate_plugin_package( def test_generate_plugin_package_with_missing_folders(acme_hook_specs_file, tmpdir, mocker) -> None: import sys from textwrap import dedent + from hookman.exceptions import ( - AssetsDirNotFoundError, ArtifactsDirNotFoundError, + AssetsDirNotFoundError, SharedLibraryNotFoundError, ) diff --git a/tests/test_hookman_utils.py b/tests/test_hookman_utils.py index eb6f36a..b69bad7 100644 --- a/tests/test_hookman_utils.py +++ b/tests/test_hookman_utils.py @@ -5,9 +5,7 @@ import pytest from hookman.exceptions import SharedLibraryLoadError -from hookman.hookman_utils import change_path_env -from hookman.hookman_utils import find_config_files -from hookman.hookman_utils import load_shared_lib +from hookman.hookman_utils import change_path_env, find_config_files, load_shared_lib def test_find_config_files(datadir) -> None: @@ -56,9 +54,8 @@ def test_load_shared_lib_raises_shared_library_load_error_for_corrupt_file(tmp_p corrupt_lib = tmp_path / lib_name corrupt_lib.write_text("not a real shared library") - with pytest.raises(SharedLibraryLoadError) as exc_info: - with load_shared_lib(str(corrupt_lib)): - pass # pragma: no cover + with pytest.raises(SharedLibraryLoadError) as exc_info, load_shared_lib(str(corrupt_lib)): + pass # pragma: no cover assert exc_info.value.shared_lib_path == corrupt_lib assert exc_info.value.reason # Non-empty OS-dependent error description. diff --git a/tests/test_hooks.py b/tests/test_hooks.py index fb09743..5b401ea 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -6,9 +6,7 @@ import pytest from packaging.version import Version -from hookman.hooks import HookMan -from hookman.hooks import HookSpecs -from hookman.hooks import PluginInfo +from hookman.hooks import HookMan, HookSpecs, PluginInfo def _get_plugin_id_set(plugin_info_list):