-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate sources of requirements (#3269)
## Summary Fixes #1343. This is kinda a first draft at the moment, but does at least mostly work locally (barring some bits of the test suite that seem to not work for me in general). ## Test Plan Mostly running the existing tests and checking the revised output is sane ## Outstanding issues Most of these come down to "AFAIK, the existing tools don't support these patterns, but `uv` does" and so I'm not sure there's an existing good answer here! Most of the answers so far are "whatever was easiest to build" - [x] ~~Is "-r pyproject.toml" correct? Should it show something else or get skipped entirely~~ No it wasn't. Fixed in 3044fa8 - [ ] If the requirements file is stdin, that just gets skipped. Should it be recorded? - [ ] Overrides get shown as "--override<override.txt>". Correct? - [x] ~~Some of the tests (e.g. `dependency_excludes_non_contiguous_range_of_compatible_versions`) make assumptions about the order of package versions being outputted, which this PR breaks. I'm not sure if the text is fairly arbitrary and can be replaced or whether the behaviour needs fixing?~~ - fixed by removing the custom pubgrub PartialEq/Hash - [ ] Are all the `TrackedFromStr` et al changes needed, or is there an easier way? I don't think so, I think it's necessary to track these sort of things fairly comprehensively to make this feature work, and this sort of invasive change feels necessary, but happy to be proved wrong there :) - [x] ~~If you have a requirement coming in from two or more different requirements files only one turns up. I've got a closed-source example for this (can go into more detail if needed), mostly consisting of a complicated set of common deps creating a larger set. It's a rarer case, but worth considering.~~ 042432b - [ ] Doesn't add annotations for `setup.py` yet - This is pretty hard, as the correct location to insert the path is `crates/pypi-types/src/metadata.rs`'s `parse_pkg_info`, which as it's based off a source distribution has entirely thrown away such matters as "where did this package requirement get built from". Could add "`built package name`" as a dep, but that's a little odd.
- Loading branch information
Showing
42 changed files
with
1,287 additions
and
323 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use std::path::PathBuf; | ||
use uv_fs::Simplified; | ||
|
||
/// Source of a dependency, e.g., a `-r requirements.txt` file. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)] | ||
pub enum SourceAnnotation { | ||
/// A `pyproject.toml` file. | ||
PyProject { | ||
path: PathBuf, | ||
project_name: Option<String>, | ||
}, | ||
/// A `-c constraints.txt` file. | ||
Constraint(PathBuf), | ||
/// An `--override overrides.txt` file. | ||
Override(PathBuf), | ||
/// A `-r requirements.txt` file. | ||
Requirement(PathBuf), | ||
} | ||
|
||
impl<'de> Deserialize<'de> for SourceAnnotation { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?; | ||
Ok(SourceAnnotation::Requirement(PathBuf::from(s))) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for SourceAnnotation { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Requirement(path) => { | ||
write!(f, "-r {}", path.user_display()) | ||
} | ||
Self::Constraint(path) => { | ||
write!(f, "-c {}", path.user_display()) | ||
} | ||
Self::Override(path) => { | ||
write!(f, "--override {}", path.user_display()) | ||
} | ||
Self::PyProject { path, project_name } => { | ||
if let Some(project_name) = project_name { | ||
write!(f, "{} ({})", project_name, path.user_display()) | ||
} else { | ||
write!(f, "{}", path.user_display()) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -139,6 +139,7 @@ impl From<&ResolvedDist> for Requirement { | |
extras: vec![], | ||
marker: None, | ||
source, | ||
path: None, | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.