Skip to content

Conversation

@DavidVujic
Copy link
Owner

@DavidVujic DavidVujic commented Jun 6, 2025

Description

Add support for exclude patterns that are paths, with or without wildcards.

Motivation and Context

Continued work from #339 and the discussion #338

This feature will make it possible to define exclude patterns in the Hatch config, such as:

[tool.hatch.build.targets.wheel]
exclude = ["example/*/assets/docs/*.rst"]

How Has This Been Tested?

✅ CI
✅ Local testing using hatch build

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

Comment on lines +53 to +60
def rewrite_modules(paths: List[Path], ns: str, top_ns: str) -> None:
for path in paths:
rewritten_bricks = parsing.rewrite_modules(path, ns, top_ns)

for item in rewritten_bricks:
print(f"Updated {item} with new top namespace for local imports.")


Copy link
Owner Author

Choose a reason for hiding this comment

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

This is refactored to separate function. The rewrite is only applicable when there's a defined top_ns (i.e. when publishing several public packages and to avoid namespace collisions).

Comment on lines +30 to +36
def ignore_paths(root: Path, patterns: Set[str]):
def fn(current_path: str, names: List[str]):
current = Path(current_path).resolve()

return {name for name in names if any_match(root, patterns, name, current)}

return fn
Copy link
Owner Author

Choose a reason for hiding this comment

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

A custom ignore-function according to the way shutil uses ignore. The default shutil.ignore_patterns only handles names (files or folders) and will not ignore paths. That is why there's need of a custom ignore function.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2025

@DavidVujic DavidVujic marked this pull request as ready for review June 6, 2025 16:15
@DavidVujic DavidVujic merged commit 8bda95d into main Jun 6, 2025
4 checks passed
@DavidVujic DavidVujic deleted the exclude-patterns-with-paths branch June 6, 2025 16:17
@DavidVujic DavidVujic mentioned this pull request Jun 6, 2025
6 tasks
@DavidVujic DavidVujic changed the title wip(hatch hook): add support for exclude patterns as paths with wildcards feat(hatch hook): add support for exclude patterns as paths with wildcards Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants