Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
12 changes: 4 additions & 8 deletions src/hookman/hookman_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions src/hookman/hookman_utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/hookman/hooks.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 2 additions & 8 deletions src/hookman/plugin_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_hookman_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
9 changes: 3 additions & 6 deletions tests/test_hookman_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
4 changes: 1 addition & 3 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading