Skip to content

Commit

Permalink
fix load plugin from script type
Browse files Browse the repository at this point in the history
  • Loading branch information
ischaojie committed Dec 5, 2022
1 parent c71b406 commit 11b2edc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
6 changes: 2 additions & 4 deletions backend/src/hatchling/plugin/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import pluggy

from hatchling.types import PluginInterface


class PluginManager:
def __init__(self) -> None:
Expand Down Expand Up @@ -68,7 +66,7 @@ def collect(self, *, include_third_party: bool = True) -> dict:
if include_third_party and not self.third_party_plugins.loaded:
self.third_party_plugins.load()

classes: dict[str, PluginInterface] = {}
classes: dict[str, type] = {}

for registered_classes in self.registration_method():
if not isinstance(registered_classes, list):
Expand All @@ -88,7 +86,7 @@ def collect(self, *, include_third_party: bool = True) -> dict:

return classes

def get(self, name: str) -> type[PluginInterface] | None:
def get(self, name: str) -> type | None:
if not self.third_party_plugins.loaded:
classes = self.collect(include_third_party=False)
if name in classes:
Expand Down
12 changes: 8 additions & 4 deletions backend/src/hatchling/plugin/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import annotations

from hatchling.types import PluginInterface
from typing import TypeVar

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.builders.plugin.interface import BuilderInterface
from hatchling.metadata.plugin.interface import MetadataHookInterface

def load_plugin_from_script(
path: str, script_name: str, plugin_class: type[PluginInterface], plugin_id: str
) -> type[PluginInterface]:
T = TypeVar('T', BuilderInterface, BuildHookInterface, MetadataHookInterface)


def load_plugin_from_script(path: str, script_name: str, plugin_class: type[T], plugin_id: str) -> type[T]:
import importlib

spec = importlib.util.spec_from_file_location(script_name, path) # type: ignore
Expand Down
19 changes: 0 additions & 19 deletions backend/src/hatchling/types.py

This file was deleted.

1 change: 0 additions & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies = [
"pytest-rerunfailures",
"pytest-xdist",
"trustme",
"typing-extensions",
]
post-install-commands = [
"python -m pip install --disable-pip-version-check {verbosity:flag:-1} -e ./backend",
Expand Down

0 comments on commit 11b2edc

Please sign in to comment.