-
Notifications
You must be signed in to change notification settings - Fork 5
Metadata #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Metadata #58
Changes from 60 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
3616224
Track number of Sphinx build warnings
m-aciek 882def2
Rename Sphinx outputdir, build is used to copy files for GH pages copy
m-aciek 52fd33b
Copy over only PO files to avoid warnings on extra files
m-aciek 9e6b104
Use locale format for Sphinx
m-aciek 4527d02
Don't override language builds
m-aciek ee7e27a
Drop fresh-env flag from Sphinx build
m-aciek eefb6b5
Run update on main once an hour
m-aciek f1fc976
Parallelize the main loop
m-aciek 38e7812
Rename issues to warnings
m-aciek b65a05e
Ignore generated warnings files
m-aciek 2a1996d
Rename issues to warnings in style.css
m-aciek b3e3336
Switch to ProcessPoolExecutor
m-aciek 487927d
Use HTML base tag in head to specify default anchors target
m-aciek 0a943c4
Link to warnings if build triggered
m-aciek e1f34aa
Separate pool managers for processes
m-aciek c495918
Separate pool managers for processes
m-aciek 8ca8b8f
Fix warnings link
m-aciek 657039a
Count warnings by keywords, not by lines
m-aciek c82d6d7
Add metadata.html
m-aciek b0798be
If index.json is not available, support HTTP URL
m-aciek 9b372e3
Add second part of deployment for metadata
m-aciek 153bb39
Add rudimentary navigation
m-aciek 6ef5782
Revert changes in the index
m-aciek 191b270
clone language in the new script
m-aciek 61f3312
Update completion.py: check also for branch main
m-aciek 4496462
reformat
m-aciek d56d22c
zero out branch variable when cloning failed
m-aciek 5768ae6
wrap navigation in nav tag
m-aciek 3f491ac
add metadata.html to gitignore
m-aciek ce85802
revert changes in the main script
m-aciek 5705367
remove superfluous dependencies
m-aciek efdf18d
add branch column in metadata
m-aciek fc435b8
don't require full table width
m-aciek 9aa8fe7
add potodo back (used in completion module)
m-aciek 87cebd5
add sphinx-lint
m-aciek db4d621
add missing lint table header
m-aciek eed321c
store lint failures in files
m-aciek 844359b
Put nav in right corner
StanFromIreland 76a65e4
Add changes to meta table
StanFromIreland 9d14b9c
Fix & make pre-commit happy
StanFromIreland d2abf53
Suggestion from Maciek
StanFromIreland 4a58af5
Remove extra tag
StanFromIreland f4275cb
Minor improvement
StanFromIreland d24a598
increase pixels
StanFromIreland 134b651
Apply suggestions from code review
StanFromIreland 99a7d03
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c2e012f
fixes after rebase
m-aciek fd33e03
handle no 30 days commit
m-aciek 8015f37
Persist clones directories
m-aciek 6bc1d2a
Clone translations to a common directory
m-aciek 39b29ac
Get rid of cloning in generate_metadata.py
m-aciek d10ae4b
Simplify CI -- use local index.json
m-aciek 46b3f73
Update CI comments
m-aciek aaf6c36
Remove change column, it's presented in the main view
m-aciek ea15b77
Checkout latest commit
m-aciek 6ce72c8
Run sphinx-lint against latest sources (merged)
m-aciek a52681e
Check for existence of the checkout directory
m-aciek b5441cc
Use empty string as no branch
m-aciek 8d8956d
Spaces in CSS
m-aciek bd60d23
Align branch to left
m-aciek 9e12412
Track last commit date
StanFromIreland 1ab509a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] faea261
Fix typing and template typo
StanFromIreland dd39c9f
Merge branch 'main' into build-warnings-new-tab
StanFromIreland f68040f
Revert "Fix typing and template typo"
m-aciek 0847dd8
Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"
m-aciek 33f4757
Revert "Track last commit date"
m-aciek 38f8c46
Track last commit date in metadata script
m-aciek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| index.html | ||
| metadata.html | ||
| warnings-*.txt | ||
| clones |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from pathlib import Path | ||
| from re import findall | ||
| from shutil import copyfile | ||
|
|
||
| import sphinx.cmd.build | ||
|
|
||
|
|
||
| def number(clones_dir: str, repo: str, language_code: str) -> int: | ||
| language_part, *locale = language_code.split('-') | ||
| if locale: | ||
| lang_with_locale = f'{language_part}_{locale[0].upper()}' | ||
| else: | ||
| lang_with_locale = language_part | ||
| locale_dir = Path(clones_dir, f'cpython/Doc/locales/{lang_with_locale}/LC_MESSAGES') | ||
| locale_dir.mkdir(parents=True, exist_ok=True) | ||
| for po_file in (repo_dir := Path(clones_dir, 'translations', repo)).rglob('*.po'): | ||
| relative_path = po_file.relative_to(repo_dir) | ||
| target_file = locale_dir / relative_path | ||
| target_file.parent.mkdir(parents=True, exist_ok=True) | ||
| copyfile(po_file, target_file) | ||
| sphinx.cmd.build.main( | ||
| ( | ||
| '--builder', | ||
| 'html', | ||
| '--jobs', | ||
| 'auto', | ||
| '--define', | ||
| f'language={language_code}', | ||
| '--verbose', | ||
| '--warning-file', | ||
| warning_file := f'{clones_dir}/warnings-{language_code}.txt', | ||
| f'{clones_dir}/cpython/Doc', # sourcedir | ||
| f'./sphinxbuild/{language_code}', # outputdir | ||
| ) | ||
| ) | ||
| copyfile(warning_file, f'warnings-{language_code}.txt') | ||
| return len(findall('ERROR|WARNING', Path(warning_file).read_text())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # /// script | ||
| # requires-python = ">=3.11" | ||
| # dependencies = [ | ||
| # "gitpython", | ||
| # "potodo", | ||
| # "jinja2", | ||
| # "sphinx", | ||
| # "python-docs-theme", | ||
| # "dacite", | ||
| # "sphinx-lint", | ||
| # ] | ||
| # /// | ||
| import concurrent.futures | ||
| import itertools | ||
| import logging | ||
| from collections.abc import Iterator, Sequence | ||
| from datetime import datetime, timezone | ||
| from json import loads | ||
| from pathlib import Path | ||
| from sys import argv | ||
|
|
||
| import dacite | ||
| from git import Repo | ||
| from jinja2 import Template | ||
| from urllib3 import request | ||
|
|
||
| import build_warnings | ||
| import sphinx_lint | ||
| from generate import LanguageProjectData | ||
| from repositories import Language | ||
|
|
||
| generation_time = datetime.now(timezone.utc) | ||
|
|
||
|
|
||
| def get_projects_metadata( | ||
| completion_progress: Sequence[LanguageProjectData], | ||
| ) -> Iterator[tuple[int, int]]: | ||
| with concurrent.futures.ProcessPoolExecutor() as executor: | ||
| return executor.map( | ||
| get_metadata, | ||
| *zip(*map(get_language_repo_and_completion, completion_progress)), | ||
| itertools.repeat(Path('clones')), | ||
| ) | ||
|
|
||
|
|
||
| def get_metadata( | ||
| language: Language, repo: str | None, completion: float, clones_dir: str | ||
| ) -> tuple[int, int]: | ||
| if repo and (repo_path := Path(clones_dir, 'translations', repo)).exists(): | ||
| Repo(repo_path).git.checkout() | ||
| return ( | ||
| repo | ||
| and completion | ||
| and ( | ||
| build_warnings.number(clones_dir, repo, language.code), | ||
| sphinx_lint.store_and_count_failures(clones_dir, repo, language.code), | ||
| ) | ||
| ) or (0, 0) | ||
|
|
||
|
|
||
| def get_language_repo_and_completion( | ||
| project: LanguageProjectData, | ||
| ) -> tuple[Language, str | None, float]: | ||
| return project.language, project.repository, project.completion | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| logging.basicConfig(level=logging.INFO) | ||
| logging.info(f'starting at {generation_time}') | ||
| template = Template(Path('metadata.html.jinja').read_text()) | ||
| if (index_path := Path('index.json')).exists(): | ||
| index_json = loads(Path('index.json').read_text()) | ||
| else: | ||
| index_json = request('GET', argv[1]).json() | ||
|
|
||
| completion_progress = [ | ||
| dacite.from_dict(LanguageProjectData, project) for project in index_json | ||
| ] | ||
|
|
||
| output = template.render( | ||
| metadata=zip(completion_progress, get_projects_metadata(completion_progress)), | ||
| generation_time=generation_time, | ||
| duration=(datetime.now(timezone.utc) - generation_time).seconds, | ||
| ) | ||
|
|
||
| Path('metadata.html').write_text(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <html lang="en"> | ||
| <head> | ||
| <title>Python Docs Translation Dashboard</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <meta charset="UTF-8"> | ||
| <base target="_blank"> | ||
| </head> | ||
| <body> | ||
| <h1>Python Docs Translation Dashboard</h1> | ||
| <nav class="switchpages"> | ||
| <a href="index.html" target="_self">main</a> | meta | ||
| </nav> | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>language</th> | ||
| <th>branch</th> | ||
| <th>build warnings*</th> | ||
| <th>lint failures</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for project, metadata in metadata | sort(attribute='0.completion,0.translators.number') | reverse %} | ||
| <tr> | ||
| <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[0] }}</a>{% else %}{{ metadata[0] }}{% endif %} | ||
| </td> | ||
| <td data-label="lint"> | ||
| {% if project.completion %}<a href="warnings-lint-{{ project.language.code }}.txt">{{ metadata[1] }}</a>{% else %}{{ metadata[1] }}{% endif %} | ||
| </td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| <p>* number of Sphinx build process warnings</p> | ||
| <p>For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.</p> | ||
| <p>Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).</p> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.