Skip to content

Commit

Permalink
refactor: use attribute instead of entry point name
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jan 3, 2024
1 parent 7f44532 commit fbffdbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/validate_pyproject/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def load_from_entry_point(entry_point: EntryPoint) -> PluginWrapper:
"""Carefully load the plugin, raising a meaningful message in case of errors"""
try:
fn = entry_point.load()
name, _, fragment = entry_point.name.partition("#")
return PluginWrapper(name, fn, fragment=fragment)
fragment = getattr(fn, "fragment", "")
return PluginWrapper(entry_point.name, fn, fragment=fragment)
except Exception as ex:
raise ErrorLoadingPlugin(entry_point=entry_point) from ex

Expand Down
13 changes: 9 additions & 4 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest

import validate_pyproject.api
from validate_pyproject import plugins
from validate_pyproject.plugins import ENTRYPOINT_GROUP, ErrorLoadingPlugin

Expand All @@ -31,11 +32,15 @@ def test_load_from_entry_point__error():
plugins.load_from_entry_point(fake)


def test_load_from_entry_point_fragment():
entry = "validate_pyproject.api:load_builtin_plugin"
real = EntryPoint(
"cibuildwheel#/properties/tool/properties", entry, ENTRYPOINT_GROUP
def test_load_from_entry_point_fragment(monkeypatch):
monkeypatch.setattr(
validate_pyproject.api.load_builtin_plugin,
"fragment",
"/properties/tool/properties",
raising=False,
)
entry = "validate_pyproject.api:load_builtin_plugin"
real = EntryPoint("cibuildwheel", entry, ENTRYPOINT_GROUP)
p = plugins.load_from_entry_point(real)
assert p.fragment == "/properties/tool/properties"
assert p.tool == "cibuildwheel"
Expand Down

0 comments on commit fbffdbd

Please sign in to comment.