diff --git a/.github/workflows/lib-deps-check.yaml b/.github/workflows/lib-deps-check.yaml index 9ef7943fe..66ecd46d7 100644 --- a/.github/workflows/lib-deps-check.yaml +++ b/.github/workflows/lib-deps-check.yaml @@ -50,35 +50,51 @@ jobs: persist-credentials: false - name: Get changed Lib files - id: changed-files + id: all-changed-files run: | # Get the list of changed files under Lib/ - changed=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'Lib/*.py' 'Lib/**/*.py' | head -50) - echo "Changed files:" - echo "$changed" + { + echo 'changed< test_pydoc, Lib/test/test_pydoc/foo.py -> test_pydoc - module=$(echo "$file" | sed -E 's|^Lib/test/||; s|\.py$||; s|/.*||') - # Skip non-test files in test/ (e.g., support.py, __init__.py) - if [[ ! "$module" == test_* ]]; then + git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'Lib/*.py' 'Lib/**/*.py' + + echo 'EOF' + } >> "$GITHUB_OUTPUT" + + - name: Parse changed files + id: changed-files + run: | + from os import environ + + files = environ["FILES"] + modules = set() + for file in files.splitlines(): + file = file.strip() + + if file.startswith("Lib/test/"): + # Test files: + # Lib/test/test_pydoc.py -> test_pydoc + # Lib/test/test_pydoc/foo.py -> test_pydoc + module = file.removeprefix("Lib/test/").split("/")[0] + if not module.startswith("test_"): continue - fi - else - # Lib files: Lib/foo.py -> foo, Lib/foo/__init__.py -> foo - module=$(echo "$file" | sed -E 's|^Lib/||; s|/__init__\.py$||; s|\.py$||; s|/.*||') - fi - if [[ -n "$module" && " $modules " != *" $module "* ]]; then - modules="$modules $module" - fi - done + else: + # Lib files: + # Lib/foo.py -> foo + # Lib/foo/__init__.py -> foo + module = file.removeprefix("Lib/").split("/")[0] + + module = module.split(".")[0] + modules.add(module) - modules=$(echo "$modules" | xargs) # trim whitespace - echo "Detected modules: $modules" - echo "modules=$modules" >> "$GITHUB_OUTPUT" + print(f"{modules=}") + output = " ".join(sorted(modules)) + output_file = environ["GITHUB_OUTPUT"] + with open(output_file, mode="a", encoding="utf-8") as fd: + fd.write(f"modules={output}\n") + env: + FILES: ${{ steps.all-changed-files.outputs.changed }} + shell: python - name: Setup Python if: steps.changed-files.outputs.modules != '' diff --git a/scripts/update_lib/cmd_deps.py b/scripts/update_lib/cmd_deps.py index affb4b360..569cbfd0c 100644 --- a/scripts/update_lib/cmd_deps.py +++ b/scripts/update_lib/cmd_deps.py @@ -392,7 +392,7 @@ def show_deps( """Show all dependency information for modules.""" # Expand "all" to all module names expanded_names = [] - for name in names: + for name in set(names): if name == "all": expanded_names.extend(get_all_modules(cpython_prefix)) else: @@ -446,6 +446,11 @@ def main(argv: list[str] | None = None) -> int: args = parser.parse_args(argv) + # When user does `./update_lib/ deps "foo bar" "baz"` + # We still want to get a list of + # ["foo", "bar", "baz"], not ["foo bar", "baz"] + args.names = [name for names in args.names for name in names.split()] + try: show_deps(args.names, args.cpython, args.lib, args.depth) return 0