8000 FIX issue 16: Build missing translations branches with nearest one. · python/docsbuild-scripts@6922a3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6922a3d

Browse files
committed
FIX issue 16: Build missing translations branches with nearest one.
1 parent 06375b6 commit 6922a3d

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

build_docs.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ def _file_unchanged(old, new):
7272
def shell_out(cmd):
7373
logging.debug("Running command %r", cmd)
7474
try:
75-
subprocess.check_output(cmd, shell=True, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
75+
return subprocess.check_output(cmd, shell=True,
76+
stdin=subprocess.PIPE,
77+
stderr=subprocess.STDOUT,
78+
universal_newlines=True)
7679
except subprocess.CalledProcessError as e:
77-
logging.error("command failed with output %r", e.output.decode("utf-8"))
80+
logging.debug("Command failed with output %r", e.output)
7881
raise
7982

8083

@@ -95,13 +98,14 @@ def changed_files(directory, other):
9598
return changed
9699

97100

98-
def git_clone(repository, directory, branch='master'):
99-
"""Clone or update the given branch of the given repository in the
100-
given directory.
101+
def git_clone(repository, directory, branch=None):
102+
"""Clone or update the given repository in the given directory.
103+
Optionally checking out a branch.
101104
"""
102105
logging.info("Updating repository %s in %s", repository, directory)
103106
try:
104-
shell_out("git -C {} checkout {}".format(directory, branch))
107+
if branch:
108+
shell_out("git -C {} checkout {}".format(directory, branch))
105109
shell_out("git -C {} pull --ff-only".format(directory))
106110
except subprocess.CalledProcessError:
107111
if os.path.exists(directory):
@@ -110,7 +114,8 @@ def git_clone(repository, directory, branch='master'):
110114
os.makedirs(directory, mode=0o775)
111115
shell_out("git clone --depth 1 --no-single-branch {} {}".format(
112116
repository, directory))
113-
shell_out("git -C {} checkout {}".format(directory, branch))
117+
if branch:
118+
shell_out("git -C {} checkout {}".format(directory, branch))
114119

115120

116121
def pep_545_tag_to_gettext_tag(tag):
@@ -124,6 +129,27 @@ def pep_545_tag_to_gettext_tag(tag):
124129
return language + '_' + region.upper()
125130

126131

132+
def translation_branch(locale_repo, locale_clone_dir, needed_version):
133+
"""Some cpython versions may be untranslated, being either too old or
134+
too new.
135+
136+
This function looks for remote branches on the given repo, and
137+
returns the name of the nearest existing branch.
138+
"""
139+
git_clone(locale_repo, locale_clone_dir)
140+
remote_branches = shell_out(
141+
"git -C {} branch -r".format(locale_clone_dir))
142+
translated_branches = []
143+
for translated_branch in remote_branches.split('\n'):
144+
if not translated_branch:
145+
continue
146+
try:
147+
translated_branches.append(float(translated_branch.split('/')[1]))
148+
except ValueError:
149+
pass # Skip non-version branches like 'master' if they exists.
150+
return sorted(translated_branches, key=lambda x: abs(needed_version - x))[0]
151+
152+
127153
def build_one(version, isdev, quick, sphinxbuild, build_root, www_root,
128154
skip_cache_invalidation=False, group='docs', git=False,
129155
log_directory='/var/log/docsbuild/', language='en'):
@@ -139,7 +165,9 @@ def build_one(version, isdev, quick, sphinxbuild, build_root, www_root,
139165
locale_dirs, gettext_language_tag, 'LC_MESSAGES')
140166
locale_repo = 'https://github.com/python/python-docs-{}.git'.format(
141167
language)
142-
git_clone(locale_repo, locale_clone_dir, version)
168+
git_clone(locale_repo, locale_clone_dir,
169+
translation_branch(locale_repo, locale_clone_dir,
170+
version))
143171
sphinxopts += ('-D locale_dirs={} '
144172
'-D language={} '
145173
'-D gettext_compact=0').format(locale_dirs,

0 commit comments

Comments
 (0)
0