10000 Merge branch 'master' into JulienPalard/server · python/docsbuild-scripts@2caf1f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2caf1f3

Browse files
authored
Merge branch 'master' into JulienPalard/server
2 parents 81a4e1e + 53e5de7 commit 2caf1f3

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

build_docs.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
"""Build the Python docs for various branches and various languages.
44
5-
Usage:
6-
7-
build_docs.py [-h] [-d] [-q] [-b 3.7] [-r BUILD_ROOT] [-w WWW_ROOT]
8-
[--skip-cache-invalidation] [--group GROUP] [--git]
9-
[--log-directory LOG_DIRECTORY]
10-
[--languages [fr [fr ...]]]
11-
12-
135
Without any arguments builds docs for all active versions configured in the
146
global VERSIONS list and all languages configured in the LANGUAGES list,
157
ignoring the -d flag as it's given in the VERSIONS configuration.
@@ -106,7 +98,7 @@ def title(self):
10698
# their doc, they don't follow Sphinx deprecations.
10799
VERSIONS = [
108100
Version("2.7", "2.7", "EOL", sphinx_version="2.3.1"),
109-
Version("3.5", "3.5", "security-fixes", sphinx_version="1.8.4"),
101+
Version("3.5", "3.5", "EOL", sphinx_version="1.8.4"),
110102
Version("3.6", "3.6", "security-fixes", sphinx_version="2.3.1"),
111103
Version("3.7", "3.7", "security-fixes", sphinx_version="2.3.1"),
112104
Version("3.8", "3.8", "stable", sphinx_version="2.4.4"),
@@ -427,6 +419,8 @@ def build_one(
427419
"-D gettext_compact=0",
428420
)
429421
)
422+
if version.status == "EOL":
423+
sphinxopts.append("-D html_context.outdated=1")
430424
git_clone("https://github.com/python/cpython.git", checkout, version.branch)
431425
maketarget = (
432426
"autobuild-"
@@ -472,14 +466,14 @@ def build_one(
472466
logging.info("Build done for version: %s, language: %s", version.name, language.tag)
473467

474468

475-
def build_venv(build_root, version):
469+
def build_venv(build_root, version, theme):
476470
"""Build a venv for the specific version.
477471
This is used to pin old Sphinx versions to old cpython branches.
478472
"""
479473
requirements = [
480474
"blurb",
481475
"jieba",
482-
"python-docs-theme",
476+
theme,
483477
"sphinx=={}".format(version.sphinx_version),
484478
]
485479
venv_path = os.path.join(build_root, "venv-with-sphinx-" + version.sphinx_version)
@@ -491,13 +485,18 @@ def build_venv(build_root, version):
491485
return venv_path
492486

493487

494-
def build_robots_txt(www_root):
488+
def build_robots_txt(www_root, group, skip_cache_invalidation):
489+
robots_file = os.path.join(www_root, "robots.txt")
495490
with open(HERE / "templates" / "robots.txt") as robots_txt_template_file:
496-
with open(os.path.join(www_root, "robots.txt"), "w") as robots_txt_file:
491+
with open(robots_file, "w") as robots_txt_file:
497492
template = jinja2.Template(robots_txt_template_file.read())
498493
robots_txt_file.write(
499494
template.render(languages=LANGUAGES, versions=VERSIONS) + "\n"
500495
)
496+
os.chmod(robots_file, 0o775)
497+
shell_out(["chgrp", group, robots_file])
498+
if not skip_cache_invalidation:
499+
shell_out(["curl", "-XPURGE", "https://docs.python.org/robots.txt"])
501500

502501

503502
def build_sitemap(www_root):
@@ -621,13 +620,21 @@ def head(lines, n=10):
621620

622621

623622
def version_info():
624-
platex_version = head(
625-
subprocess.check_output(["platex", "--version"], universal_newlines=True), n=3
626-
)
623+
try:
624+
platex_version = head(
625+
subprocess.check_output(["platex", "--version"], universal_newlines=True),
626+
n=3,
627+
)
628+
except FileNotFoundError:
629+
platex_version = "Not installed."
627630

628-
xelatex_version = head(
629-
subprocess.check_output(["xelatex", "--version"], universal_newlines=True), n=2
630-
)
631+
try:
632+
xelatex_version = head(
633+
subprocess.check_output(["xelatex", "--version"], universal_newlines=True),
634+
n=2,
635+
)
636+
except FileNotFoundError:
637+
xelatex_version = "Not installed."
631638
print(
632639
"""build_docs: {VERSION}
633640
@@ -717,6 +724,12 @@ def parse_args():
717724
action="store_true",
718725
help="Get build_docs and dependencies version info",
719726
)
727+
parser.add_argument(
728+
"--theme",
729+
default="python-docs-theme",
730+
help="Python package to use for python-docs-theme: Usefull to test branches:"
731+
" --theme git+https://github.com/obulat/python-docs-theme@master",
732+
)
720733
return parser.parse_args()
721734

722735

@@ -838,7 +851,7 @@ def main():
838851
args.skip_cache_invalidation,
839852
)
840853
build_sitemap(args.www_root)
841-
build_robots_txt(args.www_root)
854+
build_robots_txt(args.www_root, args.group, args.skip_cache_invalidation)
842855

843856

844857
if __name__ == "__main__":

templates/switchers.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
function on_version_switch() {
8282
var selected_version = $(this).children('option:selected').attr('value') + '/';
8383
var url = window.location.href;
84-
var current_language = language_segment_from_url(url);
85-
var current_version = version_segment_in_url(url);
84+
var current_language = language_segment_from_url();
85+
var current_version = version_segment_from_url();
8686
var new_url = url.replace('/' + current_language + current_version,
8787
'/' + current_language + selected_version);
8888
if (new_url != url) {
@@ -100,8 +100,8 @@
100100
function on_language_switch() {
101101
var selected_language = $(this).children('option:selected').attr('value') + '/';
102102
var url = window.location.href;
103-
var current_language = language_segment_from_url(url);
104-
var current_version = version_segment_in_url(url);
103+
var current_language = language_segment_from_url();
104+
var current_version = version_segment_from_url();
105105
if (selected_language == 'en/') // Special 'default' case for english.
106106
selected_language = '';
107107
var new_url = url.replace('/' + current_language + current_version,
@@ -116,29 +116,31 @@
116116

117117
// Returns the path segment of the language as a string, like 'fr/'
118118
// or '' if not found.
119-
function language_segment_from_url(url) {
119+
function language_segment_from_url() {
120+
var path = window.location.pathname;
120121
var language_regexp = '/((?:' + Object.keys(all_languages).join("|") + ')/)'
121-
var match = url.match(language_regexp);
122+
var match = path.match(language_regexp);
122123
if (match !== null)
123-
return match[1];
124+
return match[1];
124125
return '';
125126
}
126127

127128
// Returns the path segment of the version as a string, like '3.6/'
128129
// or '' if not found.
129-
function version_segment_in_url(url) {
130-
var language_segment = language_segment_from_url(url);
130+
function version_segment_from_url() {
131+
var path = window.location.pathname;
132+
var language_segment = language_segment_from_url();
131133
var version_segment = '(?:(?:' + version_regexs.join('|') + ')/)';
132134
var version_regexp = language_segment + '(' + version_segment + ')';
133-
var match = url.match(version_regexp);
135+
var match = path.match(version_regexp);
134136
if (match !== null)
135137
return match[1];
136138
return ''
137139
}
138140

139141
function create_placeholders_if_missing() {
140-
var version_segment = version_segment_in_url(window.location.href);
141-
var language_segment = language_segment_from_url(window.location.href);
142+
var version_segment = version_segment_from_url();
143+
var language_segment = language_segment_from_url();
142144
var index = "/" + language_segment + version_segment;
143145

144146
if ($('.version_switcher_placeholder').length)
@@ -164,7 +166,7 @@
164166
}
165167

166168
$(document).ready(function() {
167-
var language_segment = language_segment_from_url(window.location.href);
169+
var language_segment = language_segment_from_url();
168170
var current_language = language_segment.replace(/\/+$/g, '') || 'en';
169171
var version_select = build_version_select(DOCUMENTATION_OPTIONS.VERSION);
170172

0 commit comments

Comments
 (0)
0