Skip to content
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

Parallelise main loop with ThreadPoolExecutor #50

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# "docutils",
# ]
# ///
import concurrent.futures
import itertools
import logging
import subprocess
from collections.abc import Iterator
Expand Down Expand Up @@ -46,30 +48,44 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
languages_built = dict(build_status.get_languages(http := PoolManager()))
for language, repo in get_languages_and_repos(devguide_dir):
built = language.code in languages_built
if repo:
completion, translators_data = get_completion(clones_dir, repo)
visitors_num = (
get_number_of_visitors(language.code, http) if built else 0
)
else:
completion = 0.0
translators_data = TranslatorsData(0, False)
visitors_num = 0
yield LanguageProjectData(
language,
repo,
completion,
translators_data,
visitors_num,
built,
in_switcher=languages_built.get(language.code),
uses_platform=language.code in contribute.pulling_from_transifex,
contribution_link=contribute.get_contrib_link(language.code, repo),
with concurrent.futures.ThreadPoolExecutor() as executor:
return executor.map(
get_project_data,
*zip(*get_languages_and_repos(devguide_dir)),
itertools.repeat(languages_built),
itertools.repeat(clones_dir),
itertools.repeat(http),
)


def get_project_data(
language: Language,
repo: str,
languages_built: dict[str, bool],
clones_dir: str,
http: PoolManager,
) -> 'LanguageProjectData':
built = language.code in languages_built
if repo:
completion, translators_data = get_completion(clones_dir, repo)
visitors_num = get_number_of_visitors(language.code, http) if built else 0
else:
completion = 0.0
translators_data = TranslatorsData(0, False)
visitors_num = 0
return LanguageProjectData(
language,
repo,
completion,
translators_data,
visitors_num,
built,
in_switcher=languages_built.get(language.code),
uses_platform=language.code in contribute.pulling_from_transifex,
contribution_link=contribute.get_contrib_link(language.code, repo),
)


@dataclass(frozen=True)
class LanguageProjectData:
language: Language
Expand Down
Loading