From 4b0020fb0079617fc34ef939277c4d91a5f6a528 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 31 May 2023 17:43:01 +0200 Subject: [PATCH 1/8] Revert "CI: Temporarily skip paths with spaces to avoid error (#105110)" This reverts commit 4c770617c0feae18ce3b05e0c8acd0910acc7082. --- .github/workflows/build.yml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a42cdad7f3501..1d97c0a60928e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,20 +87,7 @@ jobs: with: filter: | Doc/** - # Temporarily skip paths with spaces - # (i.e. "C API", "Core and Builtins") - # to avoid "Error: One of your files includes a space". - # Pending https://github.com/python/core-workflow/issues/186 - # Misc/** - Misc/NEWS.d/next/Build/** - Misc/NEWS.d/next/Documentation/** - Misc/NEWS.d/next/IDLE/** - Misc/NEWS.d/next/Library/** - Misc/NEWS.d/next/Security/** - Misc/NEWS.d/next/Tests/** - Misc/NEWS.d/next/Tools-Demos/** - Misc/NEWS.d/next/Windows/** - Misc/NEWS.d/next/macOS/** + Misc/** .github/workflows/reusable-docs.yml - name: Check for docs changes if: >- From 9517c2171c5b4b432c055d80f8a431b713b7887e Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 31 May 2023 17:53:31 +0200 Subject: [PATCH 2/8] Use CSV-separated outputs @ get-changed-files @ CI This is necessary because paths with whitespaces tend to crash said action[[1]][[2]][[3]]. Also, we don't need to use JSON as it's harder to parse while the value isn't used except for the emptiness check. The change fixes [[4]] [1]: https://github.com/Ana06/get-changed-files#get-all-changed-files-as-space-delimited [2]: https://github.com/python/cpython/pull/103914#issuecomment-1570050722 [3]: https://github.com/python/cpython/pull/103914#issuecomment-1568507127 [4]: https://github.com/python/cpython/pull/103914#issuecomment-1568486285 --- .github/workflows/build.yml | 1 + .github/workflows/reusable-docs.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d97c0a60928e3..455202a9c01e37 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,6 +89,7 @@ jobs: Doc/** Misc/** .github/workflows/reusable-docs.yml + format: csv # unbreaks paths /w whitespaces; json is harder to parse - name: Check for docs changes if: >- github.event_name == 'pull_request' diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 8a271e867c8b4d..831a49ad3e2719 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -40,6 +40,7 @@ jobs: uses: Ana06/get-changed-files@v2.2.0 with: filter: "Doc/**" + format: csv # unbreaks paths /w whitespaces; json is harder to parse - name: 'Build changed files in nit-picky mode' if: github.event_name == 'pull_request' continue-on-error: true From 03e0e4cbbd3373db471a9a49299ed95f8a01bcb8 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 1 Jun 2023 09:07:17 +0300 Subject: [PATCH 3/8] Add --clean arg to take a list of comma-seperated files to touch --- .github/workflows/reusable-docs.yml | 2 +- Doc/tools/touch-clean-files.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 831a49ad3e2719..4f8905f800536d 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -46,7 +46,7 @@ jobs: continue-on-error: true run: | # Mark files the pull request modified - touch ${{ steps.changed_files.outputs.added_modified }} + python Doc/tools/touch-clean-files.py --clean ${{ steps.changed_files.outputs.added_modified }} # Build docs with the '-n' (nit-picky) option; convert warnings to annotations make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n --keep-going" html 2>&1 | python Doc/tools/warnings-to-gh-actions.py diff --git a/Doc/tools/touch-clean-files.py b/Doc/tools/touch-clean-files.py index 19bc1be31deb26..78454c824eb79e 100644 --- a/Doc/tools/touch-clean-files.py +++ b/Doc/tools/touch-clean-files.py @@ -3,7 +3,8 @@ Touch files that must pass Sphinx nit-picky mode so they are rebuilt and we can catch regressions. """ - +import argparse +import csv from pathlib import Path wrong_directory_msg = "Must run this script from the repo root" @@ -28,14 +29,28 @@ rst for rst in Path("Doc/").rglob("*.rst") if rst.parts[1] not in EXCLUDE_SUBDIRS } -with Path("Doc/tools/.nitignore").open() as clean_files: - DIRTY = { + +parser = argparse.ArgumentParser( + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter +) +parser.add_argument("-c", "--clean", help="Comma-separated list of clean files") +args = parser.parse_args() + +if args.clean: + clean_files = next(csv.reader([args.clean])) + CLEAN = { Path(filename.strip()) for filename in clean_files - if filename.strip() and not filename.startswith("#") + if Path(filename.strip()).is_file() } - -CLEAN = ALL_RST - DIRTY - EXCLUDE_FILES +else: + with Path("Doc/tools/.nitignore").open() as ignored_files: + IGNORED = { + Path(filename.strip()) + for filename in ignored_files + if filename.strip() and not filename.startswith("#") + } + CLEAN = ALL_RST - IGNORED - EXCLUDE_FILES print("Touching:") for filename in sorted(CLEAN): From 1484c9f65b99fd5f48442bcefa6980f485642aaf Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 4 Jun 2023 22:59:36 +0200 Subject: [PATCH 4/8] React to any "build changed files" command failure --- .github/workflows/reusable-docs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 4f8905f800536d..bb953abfc70458 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -45,6 +45,7 @@ jobs: if: github.event_name == 'pull_request' continue-on-error: true run: | + set -Eeuo pipefail # Mark files the pull request modified python Doc/tools/touch-clean-files.py --clean ${{ steps.changed_files.outputs.added_modified }} # Build docs with the '-n' (nit-picky) option; convert warnings to annotations From 8fd85abb666304f55f710b8549f81284c546dff7 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 4 Jun 2023 23:00:45 +0200 Subject: [PATCH 5/8] Quote `touch-clean-files.py --clean` argument --- .github/workflows/reusable-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index bb953abfc70458..c4630f7bd3cf2c 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -47,7 +47,7 @@ jobs: run: | set -Eeuo pipefail # Mark files the pull request modified - python Doc/tools/touch-clean-files.py --clean ${{ steps.changed_files.outputs.added_modified }} + python Doc/tools/touch-clean-files.py --clean '${{ steps.changed_files.outputs.added_modified }}' # Build docs with the '-n' (nit-picky) option; convert warnings to annotations make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n --keep-going" html 2>&1 | python Doc/tools/warnings-to-gh-actions.py From f5a52204f7e404130027c45b681bf07041719fcd Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 4 Jun 2023 23:10:14 +0200 Subject: [PATCH 6/8] No-op fast with empty `--clean` passed for touch --- Doc/tools/touch-clean-files.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/tools/touch-clean-files.py b/Doc/tools/touch-clean-files.py index 78454c824eb79e..fc8e60237c0226 100644 --- a/Doc/tools/touch-clean-files.py +++ b/Doc/tools/touch-clean-files.py @@ -6,6 +6,7 @@ import argparse import csv from pathlib import Path +from sys import exit as exit_with_return_code_of wrong_directory_msg = "Must run this script from the repo root" assert Path("Doc").exists() and Path("Doc").is_dir(), wrong_directory_msg @@ -43,6 +44,11 @@ for filename in clean_files if Path(filename.strip()).is_file() } +elif args.clean is not None: + print( + "Not touching any files: an empty string `--clean` arg value passed.", + ) + exit_with_return_code_of(0) else: with Path("Doc/tools/.nitignore").open() as ignored_files: IGNORED = { From 5a9787bbb51da26fc2d67f2e686a29187cf2bf1f Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 4 Jun 2023 23:13:59 +0200 Subject: [PATCH 7/8] Apply csv arg code comments by Hugo Co-authored-by: Hugo van Kemenade --- .github/workflows/build.yml | 2 +- .github/workflows/reusable-docs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 455202a9c01e37..e6e02c47e87352 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,7 +89,7 @@ jobs: Doc/** Misc/** .github/workflows/reusable-docs.yml - format: csv # unbreaks paths /w whitespaces; json is harder to parse + format: csv # works for paths with spaces - name: Check for docs changes if: >- github.event_name == 'pull_request' diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index c4630f7bd3cf2c..2c3f19fdddaab4 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -40,7 +40,7 @@ jobs: uses: Ana06/get-changed-files@v2.2.0 with: filter: "Doc/**" - format: csv # unbreaks paths /w whitespaces; json is harder to parse + format: csv # works for paths with spaces - name: 'Build changed files in nit-picky mode' if: github.event_name == 'pull_request' continue-on-error: true From 3e6f488e949cbf50526bdfd55c896673b729b2f7 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 5 Jun 2023 23:22:56 +0200 Subject: [PATCH 8/8] Refer to `exit` from `sys` explicitly Co-authored-by: Hugo van Kemenade --- Doc/tools/touch-clean-files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/tools/touch-clean-files.py b/Doc/tools/touch-clean-files.py index fc8e60237c0226..2b045bd68a0cf0 100644 --- a/Doc/tools/touch-clean-files.py +++ b/Doc/tools/touch-clean-files.py @@ -5,8 +5,8 @@ """ import argparse import csv +import sys from pathlib import Path -from sys import exit as exit_with_return_code_of wrong_directory_msg = "Must run this script from the repo root" assert Path("Doc").exists() and Path("Doc").is_dir(), wrong_directory_msg @@ -48,7 +48,7 @@ print( "Not touching any files: an empty string `--clean` arg value passed.", ) - exit_with_return_code_of(0) + sys.exit(0) else: with Path("Doc/tools/.nitignore").open() as ignored_files: IGNORED = {