-
Notifications
You must be signed in to change notification settings - Fork 771
feat: bundle comments and file ignore #511
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
Merged
+790
−21
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb4f64b
feat: bundle comments and file ignore
alienzach c4f120c
fix: tests
alienzach b698c44
feat: ignore secret example
alienzach 6c94486
feat: add pathsec dep
alienzach ce313b3
refactor: ignore without code cleanup
alienzach 4888557
fix: example file should be included
alienzach 4a57ba3
feat: doc updates
alienzach d2842e6
fix: use cur dir
alienzach 51daafb
feat: default to .mcpacignore
alienzach 620d492
fix: file logs minimal
alienzach 93eadef
fix: console print for file list
alienzach 660ac95
Merge branch 'main' into 09-18-feat_bundle_comments_and_file_ignore
alienzach f35880b
fix: lint and comments
alienzach ae754fa
feat: more tests
alienzach 94be33f
Merge branch 'main' into 09-18-feat_bundle_comments_and_file_ignore
alienzach f21a84e
fix: docs and error logic
alienzach 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Ignore-file helpers for the deploy bundler. | ||
This module focuses on two things: | ||
- Parse an ignore file (gitignore-compatible syntax) into a `PathSpec` matcher. | ||
- Provide an adapter that works with `shutil.copytree(ignore=...)` to decide | ||
which directory entries to skip during a copy. | ||
There is no implicit reading of `.gitignore` here. Callers must explicitly | ||
pass the ignore file path they want to use (e.g., `.mcpacignore`). | ||
""" | ||
|
||
from pathlib import Path | ||
from typing import Optional, Set | ||
import pathspec | ||
|
||
|
||
def create_pathspec_from_gitignore(ignore_file_path: Path) -> Optional[pathspec.PathSpec]: | ||
"""Create and return a `PathSpec` from an ignore file. | ||
The file is parsed using the `gitwildmatch` (gitignore) syntax. If the file | ||
does not exist, `None` is returned so callers can fall back to default | ||
behavior. | ||
Args: | ||
ignore_file_path: Path to the ignore file (e.g., `.mcpacignore`). | ||
Returns: | ||
A `PathSpec` that can match file/directory paths, or `None`. | ||
""" | ||
if not ignore_file_path.exists(): | ||
return None | ||
|
||
with open(ignore_file_path, "r", encoding="utf-8") as f: | ||
spec = pathspec.PathSpec.from_lines("gitwildmatch", f) | ||
|
||
return spec | ||
|
||
|
||
|
||
def should_ignore_by_gitignore( | ||
path_str: str, names: list, project_dir: Path, spec: Optional[pathspec.PathSpec] | ||
) -> Set[str]: | ||
"""Return the subset of `names` to ignore for `shutil.copytree`. | ||
This function is designed to be passed as the `ignore` callback to | ||
`shutil.copytree`. For each entry in the current directory (`path_str`), it | ||
computes the path relative to the `project_dir` root and checks it against | ||
the provided `spec` (a `PathSpec` created from an ignore file). | ||
Notes: | ||
- If `spec` is `None`, this returns an empty set (no additional ignores). | ||
- For directories, we also check the relative path with a trailing slash | ||
(a common gitignore convention). | ||
""" | ||
if spec is None: | ||
return set() | ||
|
||
ignored: Set[str] = set() | ||
current_path = Path(path_str) | ||
|
||
for name in names: | ||
full_path = current_path / name | ||
try: | ||
rel_path = full_path.relative_to(project_dir) | ||
rel_path_str = str(rel_path) | ||
|
||
# Match files exactly; for directories also try with a trailing slash | ||
# to respect patterns like `build/`. | ||
if spec.match_file(rel_path_str): | ||
ignored.add(name) | ||
elif full_path.is_dir() and spec.match_file(rel_path_str + "/"): | ||
ignored.add(name) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
except ValueError: | ||
# If `full_path` is not under `project_dir`, ignore matching is skipped. | ||
continue | ||
|
||
return ignored |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.