Skip to content

Commit

Permalink
add sphinx-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aciek committed Feb 15, 2025
1 parent 37d10bd commit 3e3087a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
15 changes: 11 additions & 4 deletions generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# "sphinx",
# "python-docs-theme",
# "dacite",
# "sphinx-lint",
# ]
# ///
import concurrent.futures
Expand All @@ -27,6 +28,7 @@
from urllib3 import request

import build_warnings
import sphinx_lint
from completion import branches_from_devguide
from generate import LanguageProjectData
from repositories import Language
Expand All @@ -36,7 +38,7 @@

def get_projects_metadata(
completion_progress: Sequence[LanguageProjectData],
) -> Iterator[int]:
) -> Iterator[tuple[int, int]]:
with TemporaryDirectory() as clones_dir:
Repo.clone_from(
'https://github.com/python/devguide.git',
Expand Down Expand Up @@ -68,13 +70,18 @@ def get_metadata(
branch: str | None,
completion: float,
clones_dir: str,
) -> int:
) -> tuple[int, int]:
if repo:
clone_path = Path(clones_dir, repo)
git.Repo.clone_from(f'https://github.com/{repo}.git', clone_path, branch=branch)
return (
repo and completion and build_warnings.number(clones_dir, repo, language.code)
) or 0
repo
and completion
and (
build_warnings.number(clones_dir, repo, language.code),
sum(sphinx_lint.errors(clones_dir, repo)),
)
) or (0, 0)


def get_language_repo_branch_and_completion(
Expand Down
3 changes: 2 additions & 1 deletion metadata.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<td data-label="language">{{ project.language.name }} ({{ project.language.code }})</td>
<td data-label="branch">{{ project.branch }}</td>
<td data-label="warnings">
{% if project.completion %}<a href="warnings-{{ project.language.code }}.txt">{{ metadata }}</a>{% else %}{{ metadata }}{% endif %}
{% if project.completion %}<a href="warnings-{{ project.language.code }}.txt">{{ metadata[0] }}</a>{% else %}{{ metadata[0] }}{% endif %}
</td>
<td data-label="lint">{{ metadata[1] }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
14 changes: 14 additions & 0 deletions sphinx_lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from collections.abc import Iterator
from pathlib import Path

from sphinxlint import check_file, checkers


def errors(clones_dir: str, repo: str) -> Iterator[int]:
for path in Path(clones_dir, repo).rglob('*.po'):
yield len(
check_file(
path.as_posix(),
[c for c in checkers.all_checkers.values() if c.enabled],
)
)

0 comments on commit 3e3087a

Please sign in to comment.