puffin_interpreter cleanup ahead of #235 (#492)

Preparing for #235, some refactoring to `puffin_interpreter`.

* Added a dedicated error type instead of anyhow
* `InterpreterInfo` -> `Interpreter`
* `detect_virtual_env` now returns an option so it can be chained for
#235
This commit is contained in:
konsti 2023-11-23 09:57:33 +01:00 committed by GitHub
parent 9d35128840
commit 1c0e03f807
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 201 additions and 163 deletions

View file

@ -15,7 +15,7 @@ use pep440_rs::Version;
use pep508_rs::{Requirement, VersionOrUrl};
use platform_tags::{TagPriority, Tags};
use puffin_client::RegistryClient;
use puffin_interpreter::InterpreterInfo;
use puffin_interpreter::Interpreter;
use puffin_normalize::PackageName;
use pypi_types::{File, IndexUrl, SimpleJson};
@ -26,21 +26,17 @@ pub struct DistFinder<'a> {
tags: &'a Tags,
client: &'a RegistryClient,
reporter: Option<Box<dyn Reporter>>,
interpreter_info: &'a InterpreterInfo,
interpreter: &'a Interpreter,
}
impl<'a> DistFinder<'a> {
/// Initialize a new distribution finder.
pub fn new(
tags: &'a Tags,
client: &'a RegistryClient,
interpreter_info: &'a InterpreterInfo,
) -> Self {
pub fn new(tags: &'a Tags, client: &'a RegistryClient, interpreter: &'a Interpreter) -> Self {
Self {
tags,
client,
reporter: None,
interpreter_info,
interpreter,
}
}
@ -157,7 +153,7 @@ impl<'a> DistFinder<'a> {
.requires_python
.as_ref()
.map_or(true, |requires_python| {
requires_python.contains(self.interpreter_info.version())
requires_python.contains(self.interpreter.version())
})
{
continue;

View file

@ -552,7 +552,7 @@ impl<'a, Context: BuildContext + Send + Sync> Resolver<'a, Context> {
metadata,
&package_name,
self.tags,
self.build_context.interpreter_info().version(),
self.build_context.interpreter().version(),
self.exclude_newer.as_ref(),
);
self.index