Skip to content

fix: support input globs #3812

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
merged 7 commits into from
May 22, 2025
Merged

Conversation

nichmor
Copy link
Contributor

@nichmor nichmor commented May 22, 2025

Fixes:
#3778

Overview

The idea is that sometimes, we can have semantic input globs.

What do we mean by semantic? Semantic is something that has a special meaning on different platforms.
Example:
../*.toml - in this case, .. is a semantic prefix, and it doesn't have the relative meaning for glob patterns. Our wax will try to match .. as a wrong file.

In this PR, we start checking if we have some semantic prefix - if yes, we partition it in two pieces - a prefix and a new glob, and create a new effective_walk_root which is the previous root_path + prefix.

How to test it?

You can create a structure where you have a workspace in pixi.toml, then in some sources folder another package pixi.toml which will use pixi-build-rattler-build with a recipe.yaml that points somewhere relative.

When running pixi install ( pixi build will not trigger this code path ), pixi-build-rattler-build will emit a relative glob that will be used, for example, for caching.

@@ -72,25 +75,55 @@ impl<'t> GlobSet<'t> {
.include
.iter()
.flat_map(move |glob| {
glob.walk(root_dir.clone())
let (effective_walk_root, glob) = if glob.has_semantic_literals() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is basically new behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

is that check really necessary?
Can't you always use partition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - let's take an example that we have pixi.toml glob

Calling partition on it, we will receive
pixi.toml prefix and empty glob, which when walking will not match.

Copy link
Contributor

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

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

Great work Nichita!

I left a few comments :)

Comment on lines 227 to 255
#[test]
fn test_filters_with_just_a_file_glob() {
let temp_dir = tempdir().unwrap();
let root_path = temp_dir.path();

// Create files and directories
File::create(root_path.join("pixi.toml")).unwrap();

// Test globs: include all .txt but exclude exclude.txt
let filter_globs = GlobSet::create(vec!["pixi.toml", "!exclude.txt"]).unwrap();

// Filter directory and get results as strings
let mut filtered_files: Vec<_> = filter_globs
// pretend that we are in the workspace folder
// and our recipe yaml is living inside some folder
// that will point outside
.filter_directory(root_path)
.collect::<Result<Vec<_>, _>>()
.unwrap()
.into_iter()
.map(|p| p.path().strip_prefix(root_path).unwrap().to_path_buf())
.collect();

// Assert the expected files are present
filtered_files.sort();

let expected = vec!["pixi.toml".parse::<PathBuf>().unwrap()];
assert_eq!(filtered_files, expected);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't have a glob with .. in front.
Why did you add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to test this edge case:
#3812 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay!

@@ -72,25 +75,55 @@ impl<'t> GlobSet<'t> {
.include
.iter()
.flat_map(move |glob| {
glob.walk(root_dir.clone())
let (effective_walk_root, glob) = if glob.has_semantic_literals() {
Copy link
Contributor

Choose a reason for hiding this comment

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

is that check really necessary?
Can't you always use partition?

Copy link
Contributor

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

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

One last comment, then we can bring it in :)

@nichmor nichmor merged commit a81c736 into prefix-dev:main May 22, 2025
35 checks passed
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