uv/crates/uv-globfilter
konsti 77268ee152
Build backend: Case sensitive module discovery (#13468)
We may run on case-sensitive file systems (Linux, generally) or on
case-insensitive file systems (Windows, generally), while modules in
Python may be lower or upper case. For robustness over filesystem
casing, we require an explicit module name for modules with upper cases.

Fixes #13419
2025-05-16 14:25:35 +02:00
..
src Build backend: Case sensitive module discovery (#13468) 2025-05-16 14:25:35 +02:00
Cargo.toml Build backend: Allow escaping in globs (#13313) 2025-05-07 18:31:41 +02:00
README.md Build backend: Add reference docs and schema (#12803) 2025-04-21 12:27:49 +02:00

README.md

globfilter

Portable directory walking with includes and excludes.

Motivating example: You want to allow the user to select paths within a project.

include = ["src", "License.txt", "resources/icons/*.svg"]
exclude = ["target", "/dist", ".cache", "*.tmp"]

When traversing the directory, you can use GlobDirFilter::from_globs(...)?.match_directory(&relative) skip directories that never match in WalkDirs filter_entry.

Syntax

This crate supports the cross-language, restricted glob syntax from PEP 639:

  • Alphanumeric characters, underscores (_), hyphens (-) and dots (.) are matched verbatim.
  • The special glob characters are:
    • *: Matches any number of characters except path separators
    • ?: Matches a single character except the path separator
    • **: Matches any number of characters including path separators
    • [], containing only the verbatim matched characters: Matches a single of the characters contained. Within [...], the hyphen indicates a locale-agnostic range (e.g., a-z, order based on Unicode code points). Hyphens at the start or end are matched literally.
  • The path separator is the forward slash character (/). Patterns are relative to the given directory, a leading slash character for absolute paths is not supported.
  • Parent directory indicators (..) are not allowed.

These rules mean that matching the backslash (\) is forbidden, which avoid collisions with the windows path separator.