-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aff917
commit 0cad13a
Showing
4 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use pep440_rs::Version; | ||
use pep508_rs::MarkerEnvironment; | ||
use puffin_interpreter::Interpreter; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct PythonRequirement<'a> { | ||
/// The installed version of Python. | ||
installed: &'a Version, | ||
/// The target version of Python; that is, the version of Python for which we are resolving | ||
/// dependencies. This is typically the same as the installed version, but may be different | ||
/// when specifying an alternate Python version for the resolution. | ||
target: Option<&'a Version>, | ||
} | ||
|
||
impl<'a> PythonRequirement<'a> { | ||
pub fn new(interpreter: &'a Interpreter, markers: &'a MarkerEnvironment) -> Self { | ||
let installed = interpreter.version(); | ||
let target = &markers.python_version.version; | ||
Self { | ||
installed, | ||
target: if installed == target { | ||
None | ||
} else { | ||
Some(target) | ||
}, | ||
} | ||
} | ||
|
||
/// Return a version in the given range. | ||
pub(crate) fn version(&self) -> &'a Version { | ||
self.installed | ||
} | ||
|
||
/// Returns an iterator over the versions of Python to consider when resolving dependencies. | ||
pub(crate) fn versions(&self) -> impl Iterator<Item = &'a Version> { | ||
self.target | ||
.into_iter() | ||
.chain(std::iter::once(self.installed)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters