8000 Add more helper properties in the ``Language`` class by AA-Turner · Pull Request #293 · python/docsbuild-scripts · GitHub
[go: up one dir, main page]

Skip to content

Add more helper properties in the Language class #293

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 1 commit into from
Apr 15, 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
38 changes: 21 additions & 17 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@
def tag(self) -> str:
return self.iso639_tag.replace("_", "-").lower()

@property
def is_translation(self) -> bool:
return self.tag != "en"

Check warning on line 285 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L285

Added line #L285 was not covered by tests

@property
def locale_repo_url(self) -> str:
return f"https://github.com/python/python-docs-{self.tag}.git"

Check warning on line 289 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L289

Added line #L289 was not covered by tests

@property
def switcher_label(self) -> str:
if self.translated_name:
Expand Down Expand Up @@ -549,7 +557,7 @@
logging.info("Skipping non-HTML build (language is HTML-only).")
return None # skipped
self.cpython_repo.switch(self.version.branch_or_tag)
if self.language.tag != "en":
if self.language.is_translation:

Check warning on line 560 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L560

Added line #L560 was not covered by tests
self.clone_translation()
if trigger_reason := self.should_rebuild(force_build):
self.build_venv()
Expand All @@ -569,6 +577,10 @@
return False
return True

@property
def locale_dir(self) -> Path:
return self.build_root / self.version.name / "locale"

Check warning on line 582 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L582

Added line #L582 was not covered by tests

@property
def checkout(self) -> Path:
"""Path to CPython git clone."""
Expand All @@ -582,15 +594,8 @@
def translation_repo(self) -> Repository:
"""See PEP 545 for translations repository naming convention."""

locale_repo = f"https://github.com/python/python-docs-{self.language.tag}.git"
locale_clone_dir = (
self.build_root
/ self.version.name
/ "locale"
/ self.language.iso639_tag
/ "LC_MESSAGES"
)
return Repository(locale_repo, locale_clone_dir)
locale_clone_dir = self.locale_dir / self.language.iso639_tag / "LC_MESSAGES"
return Repository(self.language.locale_repo_url, locale_clone_dir)

Check warning on line 598 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L597-L598

Added lines #L597 - L598 were not covered by tests

@property
def translation_branch(self) -> str:
Expand All @@ -611,10 +616,9 @@
logging.info("Build start.")
start_time = perf_counter()
sphinxopts = list(self.language.sphinxopts)
if self.language.tag != "en":
locale_dirs = self.build_root / self.version.name / "locale"
if self.language.is_translation:

Check warning on line 619 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L619

Added line #L619 was not covered by tests
sphinxopts.extend((
f"-D locale_dirs={locale_dirs}",
f"-D locale_dirs={self.locale_dir}",
f"-D language={self.language.iso639_tag}",
"-D gettext_compact=0",
"-D translation_progress_classes=1",
Expand All @@ -636,7 +640,7 @@

if self.includes_html:
site_url = self.version.url
if self.language.tag != "en":
if self.language.is_translation:

Check warning on line 643 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L643

Added line #L643 was not covered by tests
site_url += f"{self.language.tag}/"
# Define a tag to enable opengraph socialcards previews
# (used in Doc/conf.py and requires matplotlib)
Expand Down Expand Up @@ -718,7 +722,7 @@
logging.info("Publishing start.")
start_time = perf_counter()
self.www_root.mkdir(parents=True, exist_ok=True)
if self.language.tag == "en":
if not self.language.is_translation:

Check warning on line 725 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L725

Added line #L725 was not covered by tests
target = self.www_root / self.version.name
else:
language_dir = self.www_root / self.language.tag
Expand Down Expand Up @@ -786,7 +790,7 @@
logging.info("Should rebuild: no previous state found.")
return "no previous state"
cpython_sha = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
if self.language.tag != "en":
if self.language.is_translation:

Check warning on line 793 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L793

Added line #L793 was not covered by tests
translation_sha = self.translation_repo.run(
"rev-parse", "HEAD"
).stdout.strip()
Expand Down Expand Up @@ -849,7 +853,7 @@
"triggered_by": trigger,
"cpython_sha": self.cpython_repo.run("rev-parse", "HEAD").stdout.strip(),
}
if self.language.tag != "en":
if self.language.is_translation:

Check warning on line 856 in build_docs.py

View check run for this annotation

Codecov / codecov/patch

build_docs.py#L856

Added line #L856 was not covered by tests
state["translation_sha"] = self.translation_repo.run(
"rev-parse", "HEAD"
).stdout.strip()
Expand Down
0