Skip to content
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

Build source distributions in the resolver #138

Merged
merged 13 commits into from
Oct 25, 2023
Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented Oct 19, 2023

This is isn't ready, but it can resolve meine_stadt_transparent==0.2.14.

The source distributions are currently being built serially one after the other, i don't know if that is incidentally due to the resolution order, because sdist building is blocking or because of something in the resolver that could be improved.

It's a bit annoying that the thing that was supposed to do http requests now suddenly also has to a whole download/unpack/resolve/install/build routine, it messes up the type hierarchy. The much bigger problem though is avoid recursive crate dependencies, it's the reason for the callback and for splitting the builder into two crates (badly named atm)

@charliermarsh
Copy link
Member

Thanks, for this one let's do a proper review cycle (I'll try to read it today).

@konstin
Copy link
Member Author

konstin commented Oct 19, 2023

Please wait with proper reviewing, it's very much not ready yet

@charliermarsh
Copy link
Member

Sounds good, mark it as ready when you think it's time.

I'm guessing the serial building is just due to the resolution order? But not sure.

@konstin konstin changed the base branch from main to sdist-filenames October 20, 2023 12:54
@konstin
Copy link
Member Author

konstin commented Oct 20, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

Base automatically changed from sdist-filenames to main October 20, 2023 15:45
@konstin konstin force-pushed the resolve-sdist branch 4 times, most recently from 0a4db66 to 60d4783 Compare October 22, 2023 16:12
@konstin konstin marked this pull request as ready for review October 22, 2023 16:13
@konstin
Copy link
Member Author

konstin commented Oct 22, 2023

I tested this with meine_stadt_transparent as requirement, which has 4 sdist dependencies

@konstin konstin force-pushed the resolve-sdist branch 2 times, most recently from f8a1890 to 6fa4c77 Compare October 24, 2023 12:12
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Nice, this looks like good progress. I have comments but not requesting any major refactoring -- mostly small things. I think we can move forward with this general structure and refine it from here.

// TODO(konstin): Check wheel filename
Ok(wheel)
Ok(dist_wheel.file_name().to_string_lossy().to_string())
Copy link
Member

Choose a reason for hiding this comment

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

Why change the return type here? It seems strictly less flexible.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to parse the WheelFilename, this avoids two unwraps later

@@ -51,14 +51,16 @@ pub(crate) async fn pip_compile(
// Detect the current Python interpreter.
let platform = Platform::current()?;
let python = PythonExecutable::from_env(platform, cache)?;

// Determine the current environment markers.
let markers = python.markers().clone();
Copy link
Member

Choose a reason for hiding this comment

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

Is this clone necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to clone either the python or the markers as the build context needs an owned PythonExecutable (it's not worth the trait async lifetime problems we get otherwise).

@@ -0,0 +1,198 @@
#![allow(unstable_name_collisions)] // intersperse
Copy link
Member

Choose a reason for hiding this comment

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

What is this? Why is it necessary?

Copy link
Member Author

@konstin konstin Oct 25, 2023

Choose a reason for hiding this comment

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

clippy complains that's there's an unstable Iterator::intersperse that would shadow Itertools::intersperse if stabilized, but there's no activity of that happening and also it would be nice because it would just move the itertools features to std. (extended the comment.)

let Some(file) = self
// Try to find a wheel. If there isn't any, to a find a source distribution. If there
// isn't any either, short circuit and fail the resolution.
// TODO: Group files by version, then check for each version first for compatible wheels
Copy link
Member

Choose a reason for hiding this comment

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

Nit: please write TODOs as TODO(konsti): Group files by version....

crates/puffin-resolver/src/resolver.rs Outdated Show resolved Hide resolved
client: &RegistryClient,
puffin_ctx: &impl PuffinCtx,
sdist_filename: &SourceDistributionFilename,
) -> anyhow::Result<Metadata21> {
Copy link
Member

Choose a reason for hiding this comment

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

Here and elsewhere, can we use the direct Result type without the anyhow::, for consistency with the other crates?

pub fn version(&self, name: &PackageName, version: &Version) -> PathBuf {
self.0.join(name.to_string()).join(version.to_string())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I find this struct strange because it doesn't actually do any cache operations, i.e., it's not itself a cache. Hmm... Could we instead just put a method like id on SourceDistributionFilename?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted a central abstraction that know the structure of the built wheel cache. It's half baked because i want to move towards a more centralized cache abstraction in the future anyway, for know i put the find_wheel part on it also so it at least acts as a cache abstraction.

operator: Operator::Equal,
version,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Tempted to say we should just inline this since it's only used in one place.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't allow construction arbitrary VersionSpecifier instances because e.g. foo!=1.2.* is banned, this avoids unwrapping from VersionSpecifier::new.

self.python.markers(),
&tags,
&self.client,
// TODO: nested builds are not supported yet
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand this one. What is the limitation? What does it have to do with passing self here?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's done, i forgot to remove the comment

marker: None,
})
.collect()
}
Copy link
Member

Choose a reason for hiding this comment

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

Feels like this should be a From implementation but maybe that's strange when we don't have a wrapper type for Vec<Requirement>.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, i hope this will become more clearly a graph query vs. a conversion once get more complex e.g. with root extras.

@konstin
Copy link
Member Author

konstin commented Oct 25, 2023

I think i've addressed all comments

@charliermarsh
Copy link
Member

Cool, thanks! I'll give this another read later today and will merge it if you're offline at that point.

@charliermarsh charliermarsh enabled auto-merge (squash) October 25, 2023 20:02
@charliermarsh charliermarsh merged commit 1fbe328 into main Oct 25, 2023
3 checks passed
@charliermarsh charliermarsh deleted the resolve-sdist branch October 25, 2023 20:05
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