Skip to content

Commit 783e704

Browse files
committed
Convert changed to an integer count
1 parent d6f8429 commit 783e704

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

build_docs.py

+12-21
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,15 @@ def run_with_logging(cmd: Sequence[str | Path], cwd: Path | None = None) -> None
337337
raise subprocess.CalledProcessError(return_code, cmd[0])
338338

339339

340-
def changed_files(left: Path, right: Path) -> list[str]:
341-
"""Compute a list of different files between left and right, recursively.
342-
Resulting paths are relative to left.
343-
"""
344-
changed = []
340+
def changed_files(left: Path, right: Path) -> int:
341+
"""Compute the number of different files in the two directory trees."""
345342

346-
def traverse(dircmp_result: filecmp.dircmp) -> None:
347-
base = Path(dircmp_result.left).relative_to(left)
348-
for file in dircmp_result.diff_files:
349-
changed.append(str(base / file))
350-
if file == "index.html":
351-
changed.append(str(base) + "/")
352-
for dircomp in dircmp_result.subdirs.values():
353-
traverse(dircomp)
343+
def traverse(dircmp_result: filecmp.dircmp) -> int:
344+
changed = len(dircmp_result.diff_files)
345+
changed += sum(map(traverse, dircmp_result.subdirs.values()))
346+
return changed
354347

355-
traverse(filecmp.dircmp(left, right))
356-
return changed
348+
return traverse(filecmp.dircmp(left, right))
357349

358350

359351
@dataclasses.dataclass
@@ -735,10 +727,10 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
735727
logging.warning("Can't change mod of %s: %s", target, str(err))
736728
chgrp(target, group=self.group, recursive=True)
737729

738-
changed = []
730+
changed = 0
739731
if self.includes_html:
740732
# Copy built HTML files to webroot (default /srv/docs.python.org)
741-
changed = changed_files(self.checkout / "Doc" / "build" / "html", target)
733+
changed += changed_files(self.checkout / "Doc" / "build" / "html", target)
742734
logging.info("Copying HTML files to %s", target)
743735
chgrp(
744736
self.checkout / "Doc" / "build" / "html/",
@@ -768,13 +760,12 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
768760
archives_dir.stat().st_mode | stat.S_IROTH | stat.S_IXOTH
769761
)
770762
chgrp(archives_dir, group=self.group)
763+
changed += 1
771764
for dist_file in dist_dir.iterdir():
772765
shutil.copy2(dist_file, archives_dir / dist_file.name)
773-
changed.append("archives/")
774-
for file in archives_dir.iterdir():
775-
changed.append(f"archives/{file.name}")
766+
changed += 1
776767

777-
logging.info("%s files changed", len(changed))
768+
logging.info("%s files changed", changed)
778769
if changed and not self.skip_cache_invalidation:
779770
surrogate_key = f"{self.language.tag}/{self.version.name}"
780771
purge_surrogate_key(http, surrogate_key)

0 commit comments

Comments
 (0)