8000 Invalidate when removing a canonical link. · python/docsbuild-scripts@ac1adcb · GitHub
[go: up one dir, main page]

Skip to content

Commit ac1adcb

Browse files
committed
Invalidate when removing a canonical link.
1 parent ae2a8fc commit ac1adcb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

build_docs.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import zc.lockfile
4545
import jinja2
46+
import requests
4647

4748
HERE = Path(__file__).resolve().parent
4849

@@ -508,14 +509,7 @@ def build_robots_txt(www_root: Path, group, skip_cache_invalidation):
508509
robots_file.chmod(0o775)
509510
run(["chgrp", group, robots_file])
510511
if not skip_cache_invalidation:
511-
run(
512-
[
513-
"curl",
514-
"--silent",
515-
"-XPURGE",
516-
"https://docs.python.org/robots.txt",
517-
]
518-
)
512+
requests.request("PURGE", "https://docs.python.org/robots.txt")
519513

520514

521515
def build_sitemap(www_root: Path):
@@ -968,7 +962,7 @@ def dev_symlink(www_root: Path, group):
968962
symlink(www_root, language, current_dev, "dev", group)
969963

970964

971-
def proofread_canonicals(www_root: Path) -> None:
965+
def proofread_canonicals(www_root: Path, skip_cache_invalidation: bool) -> None:
972966
"""In www_root we check that all canonical links point to existing contents.
973967
974968
It can happen that a canonical is "broken":
@@ -989,6 +983,10 @@ def proofread_canonicals(www_root: Path) -> None:
989983
logging.info("Removing broken canonical from %s to %s", file, target)
990984
html = html.replace(canonical.group(0), "")
991985
file.write_text(html, encoding="UTF-8", errors="surrogateescape")
986+
if not skip_cache_invalidation:
987+
url = str(file).replace("/srv/", "https://")
988+
logging.info("Purging %s from CDN", url)
989+
requests.request("PURGE", url)
992990

993991

994992
def main():
@@ -1023,7 +1021,7 @@ def main():
10231021
build_robots_txt(args.www_root, args.group, args.skip_cache_invalidation)
10241022
major_symlinks(args.www_root, args.group)
10251023
dev_symlink(args.www_root, args.group)
1026-
proofread_canonicals(args.www_root)
1024+
proofread_canonicals(args.www_root, args.skip_cache_invalidation)
10271025

10281026

10291027
if __name__ == "__main__":

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
jinja2
2+
requests
23
sentry-sdk
34
zc.lockfile

0 commit comments

Comments
 (0)
0