forked from abravalheri/validate-pyproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_review.py
36 lines (25 loc) · 1.08 KB
/
repo_review.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import Any, Dict
import fastjsonschema
from . import api, plugins
__all__ = ["VPP001", "repo_review_checks", "repo_review_families"]
class VPP001:
"""Validate pyproject.toml"""
family = "validate-pyproject"
@staticmethod
def check(pyproject: Dict[str, Any]) -> str:
validator = api.Validator()
try:
validator(pyproject)
return ""
except fastjsonschema.JsonSchemaValueException as e:
return f"Invalid pyproject.toml! Error: {e}"
def repo_review_checks() -> Dict[str, VPP001]:
return {"VPP001": VPP001()}
def repo_review_families(pyproject: Dict[str, Any]) -> Dict[str, Dict[str, str]]:
has_distutils = "distutils" in pyproject.get("tool", {})
plugin_names = (ep.tool for ep in plugins.list_plugins_from_entry_points())
plugin_list = (
f"`[tool.{n}]`" for n in plugin_names if n != "distutils" or has_distutils
)
descr = f"Checks `[build-system]`, `[project]`, {', '.join(plugin_list)}"
return {"validate-pyproject": {"name": "Validate-PyProject", "description": descr}}