Skip to content

Commit

Permalink
🏗️ Use entry point module instead of value to identify source
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Oct 25, 2023
1 parent 4510dd9 commit 9860ae0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions woke/cli/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,24 @@ def _load_plugins(
self._detector_collisions.clear()

detector_entry_points = entry_points().select(group="woke.plugins.detectors")
for entry_point in sorted(detector_entry_points, key=lambda e: e.value):
self._current_plugin = entry_point.value
for entry_point in sorted(detector_entry_points, key=lambda e: e.module):
self._current_plugin = entry_point.module

# unload target module and all its children
for m in [
k
for k in sys.modules.keys()
if k == entry_point.value or k.startswith(entry_point.value + ".")
if k == entry_point.module or k.startswith(entry_point.module + ".")
]:
sys.modules.pop(m)

try:
entry_point.load()
except Exception as e:
self._failed_plugin_entry_points.add((entry_point.value, e))
self._failed_plugin_entry_points.add((entry_point.module, e))
if not self._completion_mode:
logger.error(
f"Failed to load detectors from package '{entry_point.value}': {e}"
f"Failed to load detectors from plugin module '{entry_point.module}': {e}"
)

for path in [self._global_data_path / "global-detectors"] + sorted(
Expand Down Expand Up @@ -243,11 +243,11 @@ def add_command(self, cmd: click.Command, name: Optional[str] = None) -> None:
name = name or cmd.name
if name in self.loaded_from_plugins:
if isinstance(self.loaded_from_plugins[name], str):
prev = f"package '{self.loaded_from_plugins[name]}'"
prev = f"plugin module '{self.loaded_from_plugins[name]}'"
else:
prev = f"path '{self.loaded_from_plugins[name]}'"
if isinstance(self._current_plugin, str):
current = f"package '{self._current_plugin}'"
current = f"plugin module '{self._current_plugin}'"
else:
current = f"path '{self._current_plugin}'"

Expand Down
14 changes: 7 additions & 7 deletions woke/cli/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,24 @@ def _load_plugins(
self._printer_collisions.clear()

printer_entry_points = entry_points().select(group="woke.plugins.printers")
for entry_point in sorted(printer_entry_points, key=lambda e: e.value):
self._current_plugin = entry_point.value
for entry_point in sorted(printer_entry_points, key=lambda e: e.module):
self._current_plugin = entry_point.module

# unload target module and all its children
for m in [
k
for k in sys.modules.keys()
if k == entry_point.value or k.startswith(entry_point.value + ".")
if k == entry_point.module or k.startswith(entry_point.module + ".")
]:
sys.modules.pop(m)

try:
entry_point.load()
except Exception as e:
self._failed_plugin_entry_points.add((entry_point.value, e))
self._failed_plugin_entry_points.add((entry_point.module, e))
if not self._completion_mode:
logger.error(
f"Failed to load printers from package '{entry_point.value}': {e}"
f"Failed to load printers from plugin module '{entry_point.module}': {e}"
)

for path in [self._global_data_path / "global-printers"] + sorted(plugin_paths):
Expand Down Expand Up @@ -217,11 +217,11 @@ def add_command(self, cmd: click.Command, name: Optional[str] = None) -> None:
name = name or cmd.name
if name in self.loaded_from_plugins:
if isinstance(self.loaded_from_plugins[name], str):
prev = f"package '{self.loaded_from_plugins[name]}'"
prev = f"plugin module '{self.loaded_from_plugins[name]}'"
else:
prev = f"path '{self.loaded_from_plugins[name]}'"
if isinstance(self._current_plugin, str):
current = f"package '{self._current_plugin}'"
current = f"plugin module '{self._current_plugin}'"
else:
current = f"path '{self._current_plugin}'"

Expand Down
4 changes: 2 additions & 2 deletions woke/lsp/lsp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,11 @@ async def __run_detectors_wrapper(self) -> None:
run_detect.failed_plugin_entry_points # pyright: ignore reportGeneralTypeIssues
):
await self.__server.show_message(
f"Failed to load detectors from package {package}: {e}",
f"Failed to load detectors from plugin module {package}: {e}",
MessageType.ERROR,
)
await self.__server.log_message(
f"Failed to load detectors from package {package}: {e}",
f"Failed to load detectors from plugin module {package}: {e}",
MessageType.ERROR,
)
for (
Expand Down

0 comments on commit 9860ae0

Please sign in to comment.