-
Notifications
You must be signed in to change notification settings - Fork 70
fix: use pathlib.Path.glob to include dotfiles in output manifests #1039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
crowecawcaw
wants to merge
1
commit into
aws-deadline:mainline
Choose a base branch
from
crowecawcaw:fix/glob-dotfiles-consistency
base: mainline
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| """ | ||
| Glob utilities for file matching in job attachment manifests. | ||
|
|
||
| Uses pathlib.Path.glob which, unlike the glob module, treats dotfiles | ||
| (files and directories starting with '.') the same as any other file. | ||
| The '*' wildcard matches dotfiles without requiring a leading dot in | ||
| the pattern. This is consistent with .gitignore behavior and with the | ||
| os.walk-based file discovery used by the main job submission path. | ||
| """ | ||
|
|
||
| import os | ||
| import glob | ||
| import json | ||
| from pathlib import Path | ||
| from typing import List, Optional | ||
|
|
@@ -55,17 +64,17 @@ def _match_files_with_pattern(base_path: str, patterns: List[str]) -> set: | |
| Set of normalized file paths that match the patterns | ||
| """ | ||
| matched_files = set() | ||
| root = Path(base_path) | ||
| for pattern in patterns: | ||
| # Make pattern relative to base path | ||
| full_pattern = os.path.join(base_path, pattern) | ||
|
|
||
| # Use recursive glob for directory matching | ||
| for matched_path in glob.glob(full_pattern, recursive=True): | ||
| # Only add files, not directories | ||
| if os.path.isfile(matched_path): | ||
| # Convert to proper path format | ||
| normalized_path = os.path.normpath(matched_path) | ||
| matched_files.add(normalized_path) | ||
| for matched_path in root.glob(pattern): | ||
| if matched_path.is_file(): | ||
| matched_files.add(os.path.normpath(str(matched_path))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a quick search, it seems 3.11+ the default would support the hidden folders but < 3.11 the behavior depends. So I dont' think we want variation of behaviour on different versions of python. |
||
| # On Python <3.13, a trailing "**" only yields directories. | ||
| # Append "/*" so files inside those directories are also matched. | ||
| if pattern.endswith("**"): | ||
| for matched_path in root.glob(pattern + "/*"): | ||
| if matched_path.is_file(): | ||
| matched_files.add(os.path.normpath(str(matched_path))) | ||
|
|
||
| return matched_files | ||
|
|
||
|
|
||
Empty file.
Empty file.
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that this will work, but do we want to change this behavior? What if the customer's job checkout a git clone and now they get a whole new hidden git tree getting uploaded?