ansys-pre-commit-hooks 0.8.1__tar.gz → 0.8.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ansys_pre_commit_hooks-0.8.1/src/ansys_pre_commit_hooks.egg-info → ansys_pre_commit_hooks-0.8.2}/PKG-INFO +6 -5
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/README.rst +1 -1
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/pyproject.toml +5 -4
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/setup.py +5 -4
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/VERSION +1 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/add_license_headers.py +6 -1
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/pyansys_quality_report.py +34 -7
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/quality_rules/__init__.py +42 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/quality_rules/common.py +57 -16
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/dependabot.py +747 -0
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/documentation.py +838 -0
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/labels.py +607 -0
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/pre_commit.py +430 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/quality_rules/project_metadata.py +249 -0
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/security.py +283 -0
- ansys_pre_commit_hooks-0.8.2/src/ansys/pre_commit_hooks/quality_rules/vale.py +810 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2/src/ansys_pre_commit_hooks.egg-info}/PKG-INFO +6 -5
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys_pre_commit_hooks.egg-info/SOURCES.txt +13 -1
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys_pre_commit_hooks.egg-info/requires.txt +4 -3
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_add_license_headers.py +29 -0
- ansys_pre_commit_hooks-0.8.2/tests/test_dependabot_rules.py +514 -0
- ansys_pre_commit_hooks-0.8.2/tests/test_documentation_rules.py +510 -0
- ansys_pre_commit_hooks-0.8.2/tests/test_labels_rules.py +427 -0
- ansys_pre_commit_hooks-0.8.2/tests/test_pre_commit_rules.py +452 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_project_metadata_rules.py +136 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_pyansys_quality_report.py +16 -4
- ansys_pre_commit_hooks-0.8.2/tests/test_security_rules.py +188 -0
- ansys_pre_commit_hooks-0.8.2/tests/test_vale_rules.py +490 -0
- ansys_pre_commit_hooks-0.8.1/src/ansys/pre_commit_hooks/VERSION +0 -1
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/LICENSE +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/MANIFEST.in +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/setup.cfg +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/__init__.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/assets/.reuse/templates/ansys.jinja2 +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/assets/LICENSES/Apache-2.0.txt +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/assets/LICENSES/MIT.txt +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/assets/licenses.json +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/quality_rules/cicd.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/quality_rules/readme.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/tech_review.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/AUTHORS +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/CODE_OF_CONDUCT.md +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/CONTRIBUTING.md +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/CONTRIBUTORS.md +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/LICENSE +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/README.md +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/README.rst +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys/pre_commit_hooks/templates/dependabot.yml +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys_pre_commit_hooks.egg-info/dependency_links.txt +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys_pre_commit_hooks.egg-info/entry_points.txt +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/src/ansys_pre_commit_hooks.egg-info/top_level.txt +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_cicd_rules.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_metadata.py +0 -0
- {ansys_pre_commit_hooks-0.8.1 → ansys_pre_commit_hooks-0.8.2}/tests/test_tech_review.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ansys-pre-commit-hooks
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.2
|
|
4
4
|
Home-page: https://github.com/ansys/pre-commit-hooks
|
|
5
5
|
Author: Synopsys, Inc. and ANSYS, Inc.
|
|
6
6
|
Author-email: "Synopsys, Inc. and ANSYS, Inc." <pyansys-core@synopsys.com>
|
|
@@ -24,14 +24,15 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
24
24
|
Requires-Python: >=3.10,<4
|
|
25
25
|
Description-Content-Type: text/x-rst
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Requires-Dist: click==8.5.
|
|
27
|
+
Requires-Dist: click==8.5.1
|
|
28
28
|
Requires-Dist: GitPython==3.2.1
|
|
29
29
|
Requires-Dist: importlib-metadata==9.0.1
|
|
30
30
|
Requires-Dist: Jinja2==3.1.6
|
|
31
31
|
Requires-Dist: packaging==26.3
|
|
32
|
+
Requires-Dist: PyYAML==6.0.3
|
|
32
33
|
Requires-Dist: reuse==6.3.0
|
|
33
34
|
Requires-Dist: requests==2.34.2
|
|
34
|
-
Requires-Dist: semver==3.1.
|
|
35
|
+
Requires-Dist: semver==3.1.1
|
|
35
36
|
Requires-Dist: toml==0.10.2
|
|
36
37
|
Provides-Extra: doc
|
|
37
38
|
Requires-Dist: ansys-sphinx-theme[autoapi]==1.9.0; extra == "doc"
|
|
@@ -40,7 +41,7 @@ Requires-Dist: sphinx==8.2.3; extra == "doc"
|
|
|
40
41
|
Requires-Dist: sphinx-autodoc-typehints==3.1.0; extra == "doc"
|
|
41
42
|
Requires-Dist: sphinx-copybutton==0.5.2; extra == "doc"
|
|
42
43
|
Provides-Extra: tests
|
|
43
|
-
Requires-Dist: pytest==9.
|
|
44
|
+
Requires-Dist: pytest==9.2.0; extra == "tests"
|
|
44
45
|
Requires-Dist: pytest-cov==7.1.0; extra == "tests"
|
|
45
46
|
Dynamic: author
|
|
46
47
|
Dynamic: classifier
|
|
@@ -97,7 +98,7 @@ Configure the quality report in the ``.pre-commit-config.yaml`` file:
|
|
|
97
98
|
.. code:: yaml
|
|
98
99
|
|
|
99
100
|
- repo: https://github.com/ansys/pre-commit-hooks
|
|
100
|
-
rev: v0.8.
|
|
101
|
+
rev: v0.8.2
|
|
101
102
|
hooks:
|
|
102
103
|
- id: pyansys-quality-report
|
|
103
104
|
args: [--show-all]
|
|
@@ -5,7 +5,7 @@ requires = [
|
|
|
5
5
|
"Jinja2==3.1.6",
|
|
6
6
|
"reuse==6.3.0",
|
|
7
7
|
"requests==2.34.2",
|
|
8
|
-
"semver==3.1.
|
|
8
|
+
"semver==3.1.1",
|
|
9
9
|
"toml==0.10.2",
|
|
10
10
|
"wheel",
|
|
11
11
|
]
|
|
@@ -20,14 +20,15 @@ license-files = ["LICENSE"]
|
|
|
20
20
|
authors = [{ name = "Synopsys, Inc. and ANSYS, Inc.", email = "pyansys-core@synopsys.com" }]
|
|
21
21
|
maintainers = [{ name = "Synopsys, Inc. and ANSYS, Inc.", email = "pyansys-core@synopsys.com" }]
|
|
22
22
|
dependencies = [
|
|
23
|
-
"click==8.5.
|
|
23
|
+
"click==8.5.1",
|
|
24
24
|
"GitPython==3.2.1",
|
|
25
25
|
"importlib-metadata==9.0.1",
|
|
26
26
|
"Jinja2==3.1.6",
|
|
27
27
|
"packaging==26.3",
|
|
28
|
+
"PyYAML==6.0.3",
|
|
28
29
|
"reuse==6.3.0",
|
|
29
30
|
"requests==2.34.2",
|
|
30
|
-
"semver==3.1.
|
|
31
|
+
"semver==3.1.1",
|
|
31
32
|
"toml==0.10.2",
|
|
32
33
|
]
|
|
33
34
|
|
|
@@ -56,7 +57,7 @@ doc = [
|
|
|
56
57
|
"sphinx-copybutton==0.5.2",
|
|
57
58
|
]
|
|
58
59
|
tests = [
|
|
59
|
-
"pytest==9.
|
|
60
|
+
"pytest==9.2.0",
|
|
60
61
|
"pytest-cov==7.1.0",
|
|
61
62
|
]
|
|
62
63
|
|
|
@@ -39,13 +39,14 @@ setup(
|
|
|
39
39
|
url="https://github.com/ansys/pre-commit-hooks",
|
|
40
40
|
python_requires=">=3.10,<4",
|
|
41
41
|
install_requires=[
|
|
42
|
-
"click==8.5.
|
|
42
|
+
"click==8.5.1",
|
|
43
43
|
"GitPython==3.2.1",
|
|
44
44
|
"importlib-metadata==9.0.1",
|
|
45
45
|
"Jinja2==3.1.6",
|
|
46
|
-
"
|
|
46
|
+
"PyYAML==6.0.3",
|
|
47
|
+
"reuse==6.3.0",
|
|
47
48
|
"requests==2.34.2",
|
|
48
|
-
"semver==3.1.
|
|
49
|
+
"semver==3.1.1",
|
|
49
50
|
"toml==0.10.2",
|
|
50
51
|
],
|
|
51
52
|
extras_require={
|
|
@@ -58,7 +59,7 @@ setup(
|
|
|
58
59
|
"sphinx_design==0.6.1",
|
|
59
60
|
],
|
|
60
61
|
"tests": [
|
|
61
|
-
"pytest==9.
|
|
62
|
+
"pytest==9.2.0",
|
|
62
63
|
"pytest-cov==7.1.0",
|
|
63
64
|
],
|
|
64
65
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.8.2
|
|
@@ -989,8 +989,13 @@ def cleanup(assets: dict, os_git_root: str) -> None:
|
|
|
989
989
|
"""
|
|
990
990
|
# Remove default assets (.reuse/templates/ansys.jinja2 and LICENSES/MIT.txt)
|
|
991
991
|
for key, value in assets.items():
|
|
992
|
-
|
|
992
|
+
# Do not delete custom license files, only MIT or Apache-2.0
|
|
993
|
+
if value["path"] == "LICENSES" and (
|
|
994
|
+
Path(value["default_file"]).stem not in ["MIT", "Apache-2.0"]
|
|
995
|
+
):
|
|
996
|
+
continue
|
|
993
997
|
# If the default asset files exist, unlink and remove directory
|
|
998
|
+
dest = Path(os_git_root) / value["path"] / value["default_file"]
|
|
994
999
|
if dest.exists():
|
|
995
1000
|
dest.unlink()
|
|
996
1001
|
if not Path(value["path"]).iterdir():
|
|
@@ -47,6 +47,7 @@ from ansys.pre_commit_hooks.quality_rules import (
|
|
|
47
47
|
from ansys.pre_commit_hooks.quality_rules.common import (
|
|
48
48
|
ERROR,
|
|
49
49
|
PASSED,
|
|
50
|
+
RECOMMENDATION,
|
|
50
51
|
WARNING,
|
|
51
52
|
RuleStatus,
|
|
52
53
|
_first_doc_line,
|
|
@@ -63,6 +64,7 @@ _ANSI_BOLD: Final = "\033[1m"
|
|
|
63
64
|
_STATUS_COLORS: Final[dict[RuleStatus, str]] = {
|
|
64
65
|
PASSED: "\033[32m",
|
|
65
66
|
WARNING: "\033[33m",
|
|
67
|
+
RECOMMENDATION: "\033[36m",
|
|
66
68
|
ERROR: "\033[31m",
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -85,9 +87,22 @@ class _RuleResult(TypedDict):
|
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
class _StatusTally(TypedDict):
|
|
88
|
-
"""Counts for each public quality-report status.
|
|
90
|
+
"""Counts for each public quality-report status.
|
|
91
|
+
|
|
92
|
+
Attributes
|
|
93
|
+
----------
|
|
94
|
+
PASSED : int
|
|
95
|
+
Number of passed rules.
|
|
96
|
+
RECOMMENDATION : int
|
|
97
|
+
Number of rules that suggest an optional improvement.
|
|
98
|
+
WARNING : int
|
|
99
|
+
Number of rules that reported a warning.
|
|
100
|
+
ERROR : int
|
|
101
|
+
Number of rules that failed.
|
|
102
|
+
"""
|
|
89
103
|
|
|
90
104
|
PASSED: int
|
|
105
|
+
RECOMMENDATION: int
|
|
91
106
|
WARNING: int
|
|
92
107
|
ERROR: int
|
|
93
108
|
|
|
@@ -196,7 +211,8 @@ def _overall_status(quality_report: _QualityReport) -> RuleStatus:
|
|
|
196
211
|
-------
|
|
197
212
|
RuleStatus
|
|
198
213
|
``ERROR`` when errors are present, otherwise ``WARNING`` when warnings
|
|
199
|
-
are present, and ``PASSED`` otherwise.
|
|
214
|
+
are present, and ``PASSED`` otherwise. Recommendations do not change
|
|
215
|
+
the overall status.
|
|
200
216
|
"""
|
|
201
217
|
status_tally = quality_report["tally"]
|
|
202
218
|
if status_tally[ERROR]:
|
|
@@ -310,7 +326,9 @@ def _run_checks(
|
|
|
310
326
|
Returns
|
|
311
327
|
-------
|
|
312
328
|
_QualityReport
|
|
313
|
-
Rule results, status counts, and the resulting score.
|
|
329
|
+
Rule results, status counts, and the resulting score. The score is the
|
|
330
|
+
percentage of passed rules among passed and failed rules; recommendations
|
|
331
|
+
and warnings are excluded.
|
|
314
332
|
"""
|
|
315
333
|
registered_rules = repo_review_checks(_families_to_run(selected_families))
|
|
316
334
|
normalized_selected_ids = {rule_id.upper() for rule_id in selected_rule_ids or set()}
|
|
@@ -330,6 +348,9 @@ def _run_checks(
|
|
|
330
348
|
|
|
331
349
|
passed_count = sum(rule_result["status"] == PASSED for rule_result in rule_results)
|
|
332
350
|
warning_count = sum(rule_result["status"] == WARNING for rule_result in rule_results)
|
|
351
|
+
recommendation_count = sum(
|
|
352
|
+
rule_result["status"] == RECOMMENDATION for rule_result in rule_results
|
|
353
|
+
)
|
|
333
354
|
error_count = sum(rule_result["status"] == ERROR for rule_result in rule_results)
|
|
334
355
|
scored_rule_count = passed_count + error_count
|
|
335
356
|
return {
|
|
@@ -337,6 +358,7 @@ def _run_checks(
|
|
|
337
358
|
"tally": {
|
|
338
359
|
PASSED: passed_count,
|
|
339
360
|
WARNING: warning_count,
|
|
361
|
+
RECOMMENDATION: recommendation_count,
|
|
340
362
|
ERROR: error_count,
|
|
341
363
|
},
|
|
342
364
|
"score": (round(passed_count / scored_rule_count * 100) if scored_rule_count else 0),
|
|
@@ -407,7 +429,9 @@ def _print_report(
|
|
|
407
429
|
status_tally = quality_report["tally"]
|
|
408
430
|
autoflush_print()
|
|
409
431
|
autoflush_print(_styled("Status summary", _ANSI_BOLD, colors_enabled=colors_enabled))
|
|
410
|
-
for status in (PASSED, WARNING, ERROR):
|
|
432
|
+
for status in (PASSED, RECOMMENDATION, WARNING, ERROR):
|
|
433
|
+
if status is RECOMMENDATION and not status_tally[status]:
|
|
434
|
+
continue
|
|
411
435
|
autoflush_print(
|
|
412
436
|
f" {_status_text(status, colors_enabled=colors_enabled)} {status_tally[status]:>3}"
|
|
413
437
|
)
|
|
@@ -427,7 +451,7 @@ def _print_report(
|
|
|
427
451
|
result_detail = rule_result["detail"]
|
|
428
452
|
display_headline = (
|
|
429
453
|
result_detail
|
|
430
|
-
if rule_result["status"] in {WARNING, ERROR} and result_detail
|
|
454
|
+
if rule_result["status"] in {RECOMMENDATION, WARNING, ERROR} and result_detail
|
|
431
455
|
else rule_result["label"]
|
|
432
456
|
)
|
|
433
457
|
autoflush_print(
|
|
@@ -436,7 +460,7 @@ def _print_report(
|
|
|
436
460
|
)
|
|
437
461
|
if (
|
|
438
462
|
result_detail
|
|
439
|
-
and rule_result["status"] not in {WARNING, ERROR}
|
|
463
|
+
and rule_result["status"] not in {RECOMMENDATION, WARNING, ERROR}
|
|
440
464
|
and result_detail != display_headline
|
|
441
465
|
):
|
|
442
466
|
autoflush_print(f" {result_detail}")
|
|
@@ -530,7 +554,10 @@ def _pyproject_ignored_rule_ids(repository_root: Path) -> set[str]:
|
|
|
530
554
|
@click.option(
|
|
531
555
|
"--family",
|
|
532
556
|
multiple=True,
|
|
533
|
-
help=
|
|
557
|
+
help=(
|
|
558
|
+
"Select rule family (readme, project_metadata, cicd, pre_commit, documentation, "
|
|
559
|
+
"security, labels, vale, dependabot)."
|
|
560
|
+
),
|
|
534
561
|
)
|
|
535
562
|
@click.option("--ignore", multiple=True, help="Ignore rule IDs (also read from pyproject.toml).")
|
|
536
563
|
@click.option("--show-all", is_flag=True, help="Include passing checks.")
|
|
@@ -26,8 +26,14 @@ from collections.abc import Iterable
|
|
|
26
26
|
|
|
27
27
|
from ansys.pre_commit_hooks.quality_rules.cicd import CICD
|
|
28
28
|
from ansys.pre_commit_hooks.quality_rules.common import _QualityRule
|
|
29
|
+
from ansys.pre_commit_hooks.quality_rules.dependabot import Dependabot
|
|
30
|
+
from ansys.pre_commit_hooks.quality_rules.documentation import Documentation
|
|
31
|
+
from ansys.pre_commit_hooks.quality_rules.labels import Labels
|
|
32
|
+
from ansys.pre_commit_hooks.quality_rules.pre_commit import PreCommit
|
|
29
33
|
from ansys.pre_commit_hooks.quality_rules.project_metadata import ProjectMetadata
|
|
30
34
|
from ansys.pre_commit_hooks.quality_rules.readme import README
|
|
35
|
+
from ansys.pre_commit_hooks.quality_rules.security import Security
|
|
36
|
+
from ansys.pre_commit_hooks.quality_rules.vale import Vale
|
|
31
37
|
|
|
32
38
|
README_QUALITY_RULES: tuple[type[README], ...] = tuple(
|
|
33
39
|
sorted(README.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
@@ -38,12 +44,36 @@ PROJECT_METADATA_QUALITY_RULES: tuple[type[ProjectMetadata], ...] = tuple(
|
|
|
38
44
|
CICD_QUALITY_RULES: tuple[type[CICD], ...] = tuple(
|
|
39
45
|
sorted(CICD.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
40
46
|
)
|
|
47
|
+
PRE_COMMIT_QUALITY_RULES: tuple[type[PreCommit], ...] = tuple(
|
|
48
|
+
sorted(PreCommit.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
49
|
+
)
|
|
50
|
+
DOCUMENTATION_QUALITY_RULES: tuple[type[Documentation], ...] = tuple(
|
|
51
|
+
sorted(Documentation.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
52
|
+
)
|
|
53
|
+
LABELS_QUALITY_RULES: tuple[type[Labels], ...] = tuple(
|
|
54
|
+
sorted(Labels.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
55
|
+
)
|
|
56
|
+
VALE_QUALITY_RULES: tuple[type[Vale], ...] = tuple(
|
|
57
|
+
sorted(Vale.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
58
|
+
)
|
|
59
|
+
DEPENDABOT_QUALITY_RULES: tuple[type[Dependabot], ...] = tuple(
|
|
60
|
+
sorted(Dependabot.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
61
|
+
)
|
|
62
|
+
SECURITY_QUALITY_RULES: tuple[type[Security], ...] = tuple(
|
|
63
|
+
sorted(Security.__subclasses__(), key=lambda rule_class: rule_class.__name__)
|
|
64
|
+
)
|
|
41
65
|
|
|
42
66
|
# Maps each rule family name to its rule classes.
|
|
43
67
|
RULE_FAMILIES: dict[str, tuple[type[_QualityRule], ...]] = {
|
|
44
68
|
README.family: README_QUALITY_RULES,
|
|
45
69
|
ProjectMetadata.family: PROJECT_METADATA_QUALITY_RULES,
|
|
46
70
|
CICD.family: CICD_QUALITY_RULES,
|
|
71
|
+
PreCommit.family: PRE_COMMIT_QUALITY_RULES,
|
|
72
|
+
Documentation.family: DOCUMENTATION_QUALITY_RULES,
|
|
73
|
+
Labels.family: LABELS_QUALITY_RULES,
|
|
74
|
+
Vale.family: VALE_QUALITY_RULES,
|
|
75
|
+
Dependabot.family: DEPENDABOT_QUALITY_RULES,
|
|
76
|
+
Security.family: SECURITY_QUALITY_RULES,
|
|
47
77
|
}
|
|
48
78
|
# Families evaluated when no ``--family`` is requested.
|
|
49
79
|
DEFAULT_RULE_FAMILIES: tuple[str, ...] = tuple(RULE_FAMILIES)
|
|
@@ -61,11 +91,23 @@ __all__ = [
|
|
|
61
91
|
"CICD",
|
|
62
92
|
"CICD_QUALITY_RULES",
|
|
63
93
|
"DEFAULT_RULE_FAMILIES",
|
|
94
|
+
"DOCUMENTATION_QUALITY_RULES",
|
|
95
|
+
"Documentation",
|
|
96
|
+
"LABELS_QUALITY_RULES",
|
|
97
|
+
"DEPENDABOT_QUALITY_RULES",
|
|
98
|
+
"Dependabot",
|
|
99
|
+
"PRE_COMMIT_QUALITY_RULES",
|
|
64
100
|
"PROJECT_METADATA_QUALITY_RULES",
|
|
65
101
|
"README",
|
|
66
102
|
"README_QUALITY_RULES",
|
|
67
103
|
"RULE_FAMILIES",
|
|
104
|
+
"SECURITY_QUALITY_RULES",
|
|
105
|
+
"Security",
|
|
106
|
+
"Labels",
|
|
68
107
|
"ProjectMetadata",
|
|
108
|
+
"PreCommit",
|
|
109
|
+
"VALE_QUALITY_RULES",
|
|
110
|
+
"Vale",
|
|
69
111
|
"repo_review_checks",
|
|
70
112
|
]
|
|
71
113
|
__all__.extend(
|
|
@@ -37,18 +37,34 @@ __all__ = [
|
|
|
37
37
|
"normalize_check_result",
|
|
38
38
|
"PASSED",
|
|
39
39
|
"readme_path",
|
|
40
|
+
"RECOMMENDATION",
|
|
40
41
|
"RuleCheckResult",
|
|
41
42
|
"RuleStatus",
|
|
42
43
|
"WARNING",
|
|
44
|
+
"workflow_contents",
|
|
43
45
|
]
|
|
44
46
|
|
|
45
47
|
RuleCheckResult: TypeAlias = bool | str
|
|
46
48
|
|
|
47
49
|
|
|
48
50
|
class RuleStatus(str, Enum):
|
|
49
|
-
"""Public status of a quality rule.
|
|
51
|
+
"""Public status of a quality rule.
|
|
52
|
+
|
|
53
|
+
Attributes
|
|
54
|
+
----------
|
|
55
|
+
PASSED
|
|
56
|
+
The rule is satisfied.
|
|
57
|
+
RECOMMENDATION
|
|
58
|
+
An optional improvement is suggested. It never fails the report and is
|
|
59
|
+
excluded from the score.
|
|
60
|
+
WARNING
|
|
61
|
+
The rule found an issue that does not fail the report.
|
|
62
|
+
ERROR
|
|
63
|
+
The rule failed. Any error produces a non-zero exit code.
|
|
64
|
+
"""
|
|
50
65
|
|
|
51
66
|
PASSED = "PASSED"
|
|
67
|
+
RECOMMENDATION = "RECOMMENDATION"
|
|
52
68
|
WARNING = "WARNING"
|
|
53
69
|
ERROR = "ERROR"
|
|
54
70
|
|
|
@@ -59,6 +75,7 @@ class RuleStatus(str, Enum):
|
|
|
59
75
|
|
|
60
76
|
|
|
61
77
|
PASSED: Final[RuleStatus] = RuleStatus.PASSED
|
|
78
|
+
RECOMMENDATION: Final[RuleStatus] = RuleStatus.RECOMMENDATION
|
|
62
79
|
WARNING: Final[RuleStatus] = RuleStatus.WARNING
|
|
63
80
|
ERROR: Final[RuleStatus] = RuleStatus.ERROR
|
|
64
81
|
|
|
@@ -161,8 +178,8 @@ def file_content(repository_root: Path, relative_path: str) -> str | None:
|
|
|
161
178
|
return None
|
|
162
179
|
|
|
163
180
|
|
|
164
|
-
def
|
|
165
|
-
"""Return the
|
|
181
|
+
def workflow_contents(repository_root: Path) -> dict[str, str]:
|
|
182
|
+
"""Return the text of each GitHub Actions workflow file.
|
|
166
183
|
|
|
167
184
|
Parameters
|
|
168
185
|
----------
|
|
@@ -171,14 +188,14 @@ def all_workflows_content(repository_root: Path) -> str | None:
|
|
|
171
188
|
|
|
172
189
|
Returns
|
|
173
190
|
-------
|
|
174
|
-
str
|
|
175
|
-
Contents of every readable ``.yml`` and ``.yaml`` file under
|
|
176
|
-
``.github/workflows``,
|
|
177
|
-
|
|
191
|
+
dict[str, str]
|
|
192
|
+
Contents of every readable ``.yml`` and ``.yaml`` file directly under
|
|
193
|
+
``.github/workflows``, keyed by repository-relative path and sorted by
|
|
194
|
+
file name. The mapping is empty when no such file can be read.
|
|
178
195
|
"""
|
|
179
196
|
workflows_directory = _repository_file(repository_root, ".github/workflows")
|
|
180
197
|
if workflows_directory is None:
|
|
181
|
-
return
|
|
198
|
+
return {}
|
|
182
199
|
try:
|
|
183
200
|
workflow_files = sorted(
|
|
184
201
|
path
|
|
@@ -186,14 +203,33 @@ def all_workflows_content(repository_root: Path) -> str | None:
|
|
|
186
203
|
if path.suffix in {".yml", ".yaml"} and path.is_file()
|
|
187
204
|
)
|
|
188
205
|
except OSError:
|
|
189
|
-
return
|
|
206
|
+
return {}
|
|
190
207
|
|
|
191
|
-
contents =
|
|
208
|
+
contents = {}
|
|
192
209
|
for workflow_file in workflow_files:
|
|
193
|
-
|
|
210
|
+
relative_path = f".github/workflows/{workflow_file.name}"
|
|
211
|
+
text = file_content(repository_root, relative_path)
|
|
194
212
|
if text is not None:
|
|
195
|
-
contents
|
|
196
|
-
return
|
|
213
|
+
contents[relative_path] = text
|
|
214
|
+
return contents
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def all_workflows_content(repository_root: Path) -> str | None:
|
|
218
|
+
"""Return the merged text of the GitHub Actions workflow files.
|
|
219
|
+
|
|
220
|
+
Parameters
|
|
221
|
+
----------
|
|
222
|
+
repository_root : pathlib.Path
|
|
223
|
+
Root directory that contains ``.github/workflows``.
|
|
224
|
+
|
|
225
|
+
Returns
|
|
226
|
+
-------
|
|
227
|
+
str or None
|
|
228
|
+
Contents of every readable ``.yml`` and ``.yaml`` file under
|
|
229
|
+
``.github/workflows``, joined by newlines, or ``None`` when no such
|
|
230
|
+
content exists.
|
|
231
|
+
"""
|
|
232
|
+
return "\n".join(workflow_contents(repository_root).values()) or None
|
|
197
233
|
|
|
198
234
|
|
|
199
235
|
def readme_path(repository_root: Path) -> str | None:
|
|
@@ -243,21 +279,26 @@ def normalize_check_result(raw_result: object, rule: _QualityRule) -> tuple[Rule
|
|
|
243
279
|
Parameters
|
|
244
280
|
----------
|
|
245
281
|
raw_result : object
|
|
246
|
-
Value returned by a rule check.
|
|
282
|
+
Value returned by a rule check. ``True`` is ``PASSED`` and ``False`` is
|
|
283
|
+
``ERROR`` described by the first line of the rule docstring. A string
|
|
284
|
+
must start with ``"ERROR: "``, ``"RECOMMENDATION: "``, or
|
|
285
|
+
``"WARNING: "``, which select the matching status.
|
|
247
286
|
rule : _QualityRule
|
|
248
287
|
Rule that produced ``raw_result``.
|
|
249
288
|
|
|
250
289
|
Returns
|
|
251
290
|
-------
|
|
252
291
|
tuple[RuleStatus, str]
|
|
253
|
-
Public status and its display detail
|
|
254
|
-
converted to ``ERROR``.
|
|
292
|
+
Public status and its display detail with any prefix removed. Invalid
|
|
293
|
+
return values are converted to ``ERROR``.
|
|
255
294
|
"""
|
|
256
295
|
if raw_result is True:
|
|
257
296
|
return PASSED, ""
|
|
258
297
|
if isinstance(raw_result, str):
|
|
259
298
|
if raw_result.startswith("ERROR: "):
|
|
260
299
|
return ERROR, raw_result.removeprefix("ERROR: ")
|
|
300
|
+
if raw_result.startswith("RECOMMENDATION: "):
|
|
301
|
+
return RECOMMENDATION, raw_result.removeprefix("RECOMMENDATION: ")
|
|
261
302
|
if raw_result.startswith("WARNING: "):
|
|
262
303
|
return WARNING, raw_result.removeprefix("WARNING: ")
|
|
263
304
|
return ERROR, f"Invalid check result: {raw_result!r}"
|