Skip to content

Commit 7fd0da9

Browse files
authored
Fix libs deps check (RustPython#7732)
* Convert parsing logic to python * Trigger job. (DROP ME BEFORE MERGE!) * Missing EOF * Add found modules to set * Suggestion by @fanninpm * Fix missing trailing slash * Ensure no `.py` at module name * Strip any file auffix * Revert "Trigger job. (DROP ME BEFORE MERGE!)" This reverts commit 8cf9651. * Handle quoted args
1 parent c027ffc commit 7fd0da9

2 files changed

Lines changed: 48 additions & 27 deletions

File tree

.github/workflows/lib-deps-check.yaml

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,51 @@ jobs:
5050
persist-credentials: false
5151

5252
- name: Get changed Lib files
53-
id: changed-files
53+
id: all-changed-files
5454
run: |
5555
# Get the list of changed files under Lib/
56-
changed=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'Lib/*.py' 'Lib/**/*.py' | head -50)
57-
echo "Changed files:"
58-
echo "$changed"
59-
60-
# Extract unique module names
61-
modules=""
62-
for file in $changed; do
63-
if [[ "$file" == Lib/test/* ]]; then
64-
# Test files: Lib/test/test_pydoc.py -> test_pydoc, Lib/test/test_pydoc/foo.py -> test_pydoc
65-
module=$(echo "$file" | sed -E 's|^Lib/test/||; s|\.py$||; s|/.*||')
66-
# Skip non-test files in test/ (e.g., support.py, __init__.py)
67-
if [[ ! "$module" == test_* ]]; then
56+
{
57+
echo 'changed<<EOF'
58+
59+
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'Lib/*.py' 'Lib/**/*.py'
60+
61+
echo 'EOF'
62+
} >> "$GITHUB_OUTPUT"
63+
64+
- name: Parse changed files
65+
id: changed-files
66+
run: |
67+
from os import environ
68+
69+
files = environ["FILES"]
70+
modules = set()
71+
for file in files.splitlines():
72+
file = file.strip()
73+
74+
if file.startswith("Lib/test/"):
75+
# Test files:
76+
# Lib/test/test_pydoc.py -> test_pydoc
77+
# Lib/test/test_pydoc/foo.py -> test_pydoc
78+
module = file.removeprefix("Lib/test/").split("/")[0]
79+
if not module.startswith("test_"):
6880
continue
69-
fi
70-
else
71-
# Lib files: Lib/foo.py -> foo, Lib/foo/__init__.py -> foo
72-
module=$(echo "$file" | sed -E 's|^Lib/||; s|/__init__\.py$||; s|\.py$||; s|/.*||')
73-
fi
74-
if [[ -n "$module" && " $modules " != *" $module "* ]]; then
75-
modules="$modules $module"
76-
fi
77-
done
78-
79-
modules=$(echo "$modules" | xargs) # trim whitespace
80-
echo "Detected modules: $modules"
81-
echo "modules=$modules" >> "$GITHUB_OUTPUT"
81+
else:
82+
# Lib files:
83+
# Lib/foo.py -> foo
84+
# Lib/foo/__init__.py -> foo
85+
module = file.removeprefix("Lib/").split("/")[0]
86+
87+
module = module.split(".")[0]
88+
modules.add(module)
89+
90+
print(f"{modules=}")
91+
output = " ".join(sorted(modules))
92+
output_file = environ["GITHUB_OUTPUT"]
93+
with open(output_file, mode="a", encoding="utf-8") as fd:
94+
fd.write(f"modules={output}\n")
95+
env:
96+
FILES: ${{ steps.all-changed-files.outputs.changed }}
97+
shell: python
8298

8399
- name: Setup Python
84100
if: steps.changed-files.outputs.modules != ''

scripts/update_lib/cmd_deps.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def show_deps(
392392
"""Show all dependency information for modules."""
393393
# Expand "all" to all module names
394394
expanded_names = []
395-
for name in names:
395+
for name in set(names):
396396
if name == "all":
397397
expanded_names.extend(get_all_modules(cpython_prefix))
398398
else:
@@ -446,6 +446,11 @@ def main(argv: list[str] | None = None) -> int:
446446

447447
args = parser.parse_args(argv)
448448

449+
# When user does `./update_lib/ deps "foo bar" "baz"`
450+
# We still want to get a list of
451+
# ["foo", "bar", "baz"], not ["foo bar", "baz"]
452+
args.names = [name for names in args.names for name in names.split()]
453+
449454
try:
450455
show_deps(args.names, args.cpython, args.lib, args.depth)
451456
return 0

0 commit comments

Comments
 (0)