Skip to content

Commit ff44b37

Browse files
committed
feat: support fragments
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 50efc03 commit ff44b37

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

docs/dev-guide.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ An example of the plugin structure needed for this system is shown below:
154154
"schemas": [my_extra_schema],
155155
}
156156
157+
Fragments for schemas are also supported with this system; use ``#`` to split
158+
the tool name and fragment path in the dictionary key.
159+
157160
.. _entry-point: https://setuptools.pypa.io/en/stable/userguide/entry_point.html#entry-points
158161
.. _JSON Schema: https://json-schema.org/
159162
.. _Python package: https://packaging.python.org/

src/validate_pyproject/plugins/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __repr__(self) -> str:
6666

6767
class StoredPlugin:
6868
def __init__(self, tool: str, schema: Schema):
69-
self._tool = tool
69+
self._tool, _, self._fragment = tool.partition("#")
7070
self._schema = schema
7171

7272
@property
@@ -83,14 +83,17 @@ def schema(self) -> Schema:
8383

8484
@property
8585
def fragment(self) -> str:
86-
return ""
86+
return self._fragment
8787

8888
@property
8989
def help_text(self) -> str:
9090
return self.schema.get("description", "")
9191

9292
def __repr__(self) -> str:
93-
return f"{self.__class__.__name__}({self.tool!r}, <schema: {self.id}>)"
93+
args = [repr(self.tool), self.id]
94+
if self.fragment:
95+
args.append(f"fragment={self.fragment!r}")
96+
return f"{self.__class__.__name__}({', '.join(args)}, <schema: {self.id}>)"
9497

9598

9699
if typing.TYPE_CHECKING:

src/validate_pyproject/repo_review.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def repo_review_checks() -> Dict[str, VPP001]:
2828

2929
def repo_review_families(pyproject: Dict[str, Any]) -> Dict[str, Dict[str, str]]:
3030
has_distutils = "distutils" in pyproject.get("tool", {})
31-
plugin_names = plugins.list_from_entry_points(
31+
plugin_list = plugins.list_from_entry_points(
3232
lambda e: e.name != "distutils" or has_distutils
3333
)
34-
plugin_list = (f"`[tool.{n}]`" for n in plugin_names)
35-
descr = f"Checks `[build-system]`, `[project]`, {', '.join(plugin_list)}"
34+
plugin_names = (f"`[tool.{n.tool}]`" for n in plugin_list if n.tool)
35+
descr = f"Checks `[build-system]`, `[project]`, {', '.join(plugin_names)}"
3636
return {"validate-pyproject": {"name": "Validate-PyProject", "description": descr}}

tests/test_plugins.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_multi_plugins(monkeypatch):
9191
s3 = {"id": "example3"}
9292
sys.modules["test_module"] = ModuleType("test_module")
9393
sys.modules["test_module"].f = lambda: {
94-
"tools": {"example": s1},
94+
"tools": {"example#frag": s1},
9595
"schemas": [s2, s3],
9696
} # type: ignore[attr-defined]
9797
monkeypatch.setattr(
@@ -101,3 +101,8 @@ def test_multi_plugins(monkeypatch):
101101
lst = plugins.list_from_entry_points()
102102
assert len(lst) == 3
103103
assert all(e.id.startswith("example") for e in lst)
104+
105+
(fragmented,) = (e for e in lst if e.tool)
106+
assert fragmented.tool == "example"
107+
assert fragmented.fragment == "frag"
108+
assert fragmented.schema == s1

0 commit comments

Comments
 (0)