Skip to content

Python: fix(scripts): support native Windows paths in get_changed_packages - #9905

Open
chengrm (chengwudi1) wants to merge 1 commit into
microsoft:mainfrom
chengwudi1:fix/windows-changed-package-paths
Open

chengrm (chengwudi1) wants to merge 1 commit into
microsoft:mainfrom
chengwudi1:fix/windows-changed-package-paths

Conversation

@chengwudi1

Copy link
Copy Markdown

Summary

Fixes #9742.

In python/scripts/run_tasks_in_changed_packages.py, get_changed_packages only stripped the text prefix "python/" from repository-relative file paths:

if file_path_str.startswith("python/"):
    file_path_str = file_path_str[7:]

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 to workspace_root (which already points to the python directory), 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

  • Normalize relative file paths via Path.parts so the leading "python" component is stripped uniformly regardless of platform path separator (supporting both / and \, as well as ./ and .\ prefixes).
  • Added unit tests in python/scripts/tests/test_run_tasks_in_changed_packages.py covering:
    • Repository-relative paths (both forward-slash and Windows backslash).
    • Workspace-relative paths.
    • Dot-prefixed paths (./ and .\).
    • Absolute paths.
    • Non-core packages and flag evaluation (core_package_changed).
    • Out-of-tree and unrelated files filtering.
    • File list deduplication.

Verification

  • Ran unit tests:
    pytest python/scripts/tests/test_run_tasks_in_changed_packages.py -v -> 7 passed.
  • Ran ruff lint & format:
    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.
  • Ran pyright type check:
    pyright scripts/run_tasks_in_changed_packages.py scripts/tests/test_run_tasks_in_changed_packages.py -> 0 errors, 0 warnings.

…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.
@chengwudi1

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

1 inactive deployment
github-app-auth — 3dc32b07 Deployed Oct 31, 2026 by chengwudi1 via add_label #26758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: native Windows --files paths skip changed-package tasks

2 participants