azure-ai-projects: replace hard-coded skip lists with .gitignore-based filtering in _upload_folder_to_blob#46037
Draft
Copilot wants to merge 2 commits intofeature/azure-ai-projects/2.0.2from
Conversation
- Add pathspec>=0.9.0 to pyproject.toml dependencies - Add _load_gitignore_spec() and _is_ignored() module-level helpers in _patch_evaluators.py; reuse them in _patch_evaluators_async.py - Replace hard-coded skip_dirs/skip_extensions with gitignore-based filtering; .git is always excluded as a safety guard - Update and extend unit tests for both sync and async code paths Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/7c2df3db-ebbe-4987-86ca-07b8339f05c5 Co-authored-by: w-javed <7674577+w-javed@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update _upload_folder_to_blob to respect .gitignore patterns
azure-ai-projects: replace hard-coded skip lists with Apr 1, 2026
.gitignore-based filtering in _upload_folder_to_blob
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.
_upload_folder_to_blobused hard-codedskip_dirs/skip_extensionssets (__pycache__,.venv,*.pyc, etc.). Users had no way to control what gets uploaded without modifying SDK code.Changes
pyproject.toml— addpathspec>=0.9.0runtime dependency.operations/_patch_evaluators.py— two new module-level helpers:_load_gitignore_spec(root)— readsroot/.gitignoreandroot/.git/info/exclude; returns a compiledpathspec.PathSpec. Returns empty spec (upload everything) when neither file exists._is_ignored(spec, root, path)— tests a path against the spec using its POSIX-relative form._upload_folder_to_blobnow prunesdirs[:]and skips files using the spec..gitis unconditionally excluded as a safety guard regardless of.gitignorecontents.aio/operations/_patch_evaluators_async.py— imports and reuses the same helpers from the sync module; identical walk/filter logic withawait.test_upload_skips_pycache_and_pyc_filesupdated to provide a.gitignore; four new tests added per variant covering: ignored directory not traversed, ignored file not uploaded, no.gitignoreuploads all files,.gitalways excluded.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh gh auth status bash --no�� s/tests/evaluators/test_evaluators_upload_async.py(http block)/usr/bin/gh gh pr create --title Use .gitignore-based filtering in_upload_folder_to_blob` for azure-ai-projects evaluators --body ## SummaryReplaces the hard-coded
skip_dirs/skip_extensionslists in_upload_folder_to_blobwith dynamic.gitignore-based filtering using thepathspeclibrary (gitwildmatchdialect).Changes
sdk/ai/azure-ai-projects/pyproject.tom /opt/hostedtoolcache/Python/3.9.25/x64/bash get -projects/2.0.2 rgo/bin/bash bash ts/a�� --noprofile -c -for-python/.venv/bin/git get --local ndor/bin/lsb_rel--noprofile rustc(http block)Original prompt
Goal: Update
sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch_evaluators.pyso that_upload_folder_to_blobrespects.gitignorepatterns (and possibly.git/info/exclude) instead of using hard-codedskip_dirsandskip_extensions.Context:
sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch_evaluators.py07fea0818cc1f95521abc44aafd97776ce41c918Current behavior:
__pycache__,.git,.venv,venv,node_modules.pyc,.pyoDesired behavior:
.gitignorerules from the uploaded folder root to decide which paths to skip during upload..gititself is never uploaded, even if.gitignoreis missing or doesn’t include it (safety).Implementation requirements:
pathspecwithgitwildmatch).os.walkloop by mutatingdirs[:]and filtering files..gitignoregracefully (upload everything except safety exclusions)..pycignored by default only if.gitignorecovers it (or decide to keep.pycexcluded as a safety default; document decision).Update packaging:
azure-ai-projectspackage.Deliverables:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: I have this code. How can I use .gitignore instead of this.
lines [61:62]
skip_dirs = {"pycache", ".git", ".venv", "venv", "node_modules"}
skip_extensions = {".pyc", ".pyo"}
Assistant: You can replace the hard-coded
skip_dirs/skip_extensionswith “honor the repo’s.gitignore” by using a gitignore parser and filtering paths before upload.Recommended approach (practical + predictable)
.gitignorefile in the folder being uploaded (and optionally global ignores like.git/info/exclude)In Python, the most straightforward way is to use a library that implements gitignore semantics, e.g.
pathspec(commonly used for this). Pseudocode (showing the shape of the change):Then inside
_upload_folder_to_blob:spec = _load_gitignore_spec(Path(folder))os.walk, filterdirs[:]by checking_is_ignored(spec, root_path, Path(root)/d)_is_ignored(...)is trueThat gives you behavior consistent with
.gitignore, and users can control what gets uploaded without changing SDK code.Two important constraints to check first
azure-ai-projectscan’t take a new dependency, you’ll need an alternative..gitignoreshould mean here:.gitignoreignores untracked files by default, but it can also match tracked files. For uploading, you probably want “exclude anything that.gitignorewould ignore”, regardless of whether it’s tracked.If you want: I can propose a dependency-free fallback
If adding
pathspecisn’t acceptable, the next-best options are:git ls-files -co --exclude-standardto enumerate upload candidates (requiresgitCLI present), orIf you tell me whether adding a small dependency is allowed for
azure-ai-projectsin this branch, I can sketch the exact implementation you’d drop into `_upl...This pull request was created from Copilot chat.