Repository navigation
Python: fix(scripts): support native Windows paths in get_changed_packages - #9905
Open
chengrm (chengwudi1) wants to merge 1 commit into
Open
chengrm (chengwudi1) wants to merge 1 commit into
chengrm (chengwudi1) wants to merge 1 commit into
Conversation
…kages Fixes microsoft#9742. In get_changed_packages, files were only stripped of the hardcoded forward-slash prefix python/. On Windows, repo-relative paths with native backslashes (e.g. python\packages\core\...) failed the prefix check and resolved under workspace_root / python\..., resulting in empty changed package sets and skipping package tasks. Use Path.parts to normalize and strip the repository prefix component across platforms, and add unit tests covering repo-relative, workspace-relative, and dot-prefixed paths in both forward-slash and backslash representations.
chengrm (chengwudi1)
temporarily deployed
to
github-app-auth
October 31, 2026 01:47 — with
GitHub Actions
Inactive
chengrm (chengwudi1)
requested review from
Darren Cohen (dargilco),
Jose Alvarez (jpalvarezl) and
sophia-ramsey
as code owners
October 31, 2026 01:47
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Incomplete separator normalization on POSIX causes workspace-relative and dot-prefixed backslash paths to skip package tasks and fail the new tests.
1 open issue
What changed in this PR
This PR addresses #9742 by updating the Python changed-package task runner to recognize native Windows repository-relative paths.
Changes:
- Replaces text-prefix stripping with path-component handling and a separator-normalization fallback.
- Adds tests for path formats, package selection, core-change flags, unrelated files, and deduplication.
| File | Description |
|---|---|
python/scripts/tests/test_run_tasks_in_changed_packages.py |
Adds seven tests covering path handling and package-routing behavior. |
python/scripts/run_tasks_in_changed_packages.py |
Updates relative-path normalization and adds a CLI entry-point docstring. |
Review effort: Balanced
Comment on lines
+32
to
+41
| # Strip 'python' prefix component if present (when git diff is run from repo root) | ||
| parts = path.parts | ||
| if parts and parts[0] == "python": | ||
| path = Path(*parts[1:]) | ||
| elif str(file_path).startswith(("python/", "python\\")): | ||
| # Fallback for non-native path separators on POSIX platforms | ||
| normalized = str(file_path).replace("\\", "/") | ||
| parts = Path(normalized).parts | ||
| if parts and parts[0] == "python": | ||
| path = Path(*parts[1:]) |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #9742.
In
python/scripts/run_tasks_in_changed_packages.py,get_changed_packagesonly stripped the text prefix"python/"from repository-relative file paths:On Windows, when file paths were supplied in native backslash spelling (e.g.
python\packages\core\agent_framework\_types.py), the check failed. The native path was then joined toworkspace_root(which already points to thepythondirectory), producing.../python/python\packages\core\.... As a result, the path failed to match any project package, returned(set(), False), and silently skipped package tasks.Changes
Path.partsso the leading"python"component is stripped uniformly regardless of platform path separator (supporting both/and\, as well as./and.\prefixes).python/scripts/tests/test_run_tasks_in_changed_packages.pycovering:./and.\).core_package_changed).Verification
pytest python/scripts/tests/test_run_tasks_in_changed_packages.py -v-> 7 passed.ruff check scripts/run_tasks_in_changed_packages.py scripts/tests/test_run_tasks_in_changed_packages.py-> All checks passed!ruff format --check scripts/run_tasks_in_changed_packages.py scripts/tests/test_run_tasks_in_changed_packages.py-> All formatted.pyright scripts/run_tasks_in_changed_packages.py scripts/tests/test_run_tasks_in_changed_packages.py-> 0 errors, 0 warnings.