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

Annotate sources of requirements #3269

Merged
merged 36 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8afbb25
Annotate packages that are from a requirements file
palfrey Apr 25, 2024
6db1eec
Merge branch 'main' into annotate-requirements-sources
palfrey Apr 25, 2024
5818459
Fix clippy, fmt and _most_ of the test failures
palfrey Apr 25, 2024
8cad31d
Fix remaining "missing via -r" test fails
palfrey Apr 25, 2024
cf170e5
resolve_configuration has many snapshots
palfrey Apr 25, 2024
9655e91
Fix contraints output
palfrey Apr 26, 2024
90966c7
Merge branch 'main' into annotate-requirements-sources
palfrey Apr 26, 2024
042432b
Strip sources out of pubgrub
palfrey Apr 26, 2024
5358db9
Ignore too many args to DisplayResolutionGraph
palfrey Apr 26, 2024
c5b159b
Fix various extra constraints test failures
palfrey Apr 26, 2024
a53b968
Sort source annotations
palfrey Apr 26, 2024
3044fa8
Fix pyproject to not be a -r annotation
palfrey Apr 29, 2024
e005d96
Merge branch 'main' into annotate-requirements-sources
palfrey Apr 29, 2024
cf56fc4
Update newer tests
palfrey Apr 29, 2024
0ac36f7
Merge branch 'main' into annotate-requirements-sources
palfrey May 5, 2024
e15914d
Update to latest main
palfrey May 5, 2024
8512f8d
Fix windows-specific test compile
palfrey May 5, 2024
cfba144
And reformat the windows-specific fix
palfrey May 5, 2024
2c31ee6
Attempt to unfudge the windows testing
palfrey May 5, 2024
54064be
Fix some remaining path regex errors
palfrey May 5, 2024
264cc3d
Simplify expand_env_var_requirements_txt filters
palfrey May 5, 2024
493cf85
Fix requirements-txt snapshots
palfrey May 5, 2024
6332d06
Remove TrackedStr from other structs
charliermarsh May 8, 2024
4da1f65
Use with_source instead of TrackedFromStr
charliermarsh May 8, 2024
76df774
Merge branch 'main' into annotate-requirements-sources
charliermarsh May 8, 2024
9f5fa04
Move sources to distribution-types
charliermarsh May 8, 2024
e832262
Change signature
charliermarsh May 8, 2024
e57ce3f
Re-generate fixtures
charliermarsh May 8, 2024
b8decb4
Fix Ubuntu and macOS test
charliermarsh May 8, 2024
eb3ea98
Add sources for editables
palfrey May 8, 2024
6bd18ce
Fix clippy issue (and some test results along the way)
palfrey May 8, 2024
0ebe593
Strip UNC
charliermarsh May 9, 2024
e09fe28
Add debug logging
charliermarsh May 9, 2024
cc89b87
Add debug logging
charliermarsh May 9, 2024
641b107
Set stack size
charliermarsh May 9, 2024
14630d2
Retry filters
charliermarsh May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions crates/distribution-types/src/annotation.rs
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 {
Copy link
Member

Choose a reason for hiding this comment

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

I renamed this because we have some other "source" concepts and I wanted to disambiguate it.

/// A `pyproject.toml` file.
PyProject {
path: PathBuf,
project_name: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

This is now optional.

},
/// 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())
}
}
}
}
}
2 changes: 2 additions & 0 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use pep440_rs::Version;
use pep508_rs::{Pep508Url, Scheme, VerbatimUrl};
use uv_normalize::PackageName;

pub use crate::annotation::*;
pub use crate::any::*;
pub use crate::buildable::*;
pub use crate::cached::*;
Expand All @@ -62,6 +63,7 @@ pub use crate::resolved::*;
pub use crate::specified_requirement::*;
pub use crate::traits::*;

mod annotation;
mod any;
mod buildable;
mod cached;
Expand Down
2 changes: 2 additions & 0 deletions crates/distribution-types/src/requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Requirement {
pub extras: Vec<ExtraName>,
pub marker: Option<MarkerTree>,
pub source: RequirementSource,
pub path: Option<PathBuf>,
}

impl Requirement {
Expand Down Expand Up @@ -62,6 +63,7 @@ impl Requirement {
extras: requirement.extras,
marker: requirement.marker,
source,
path: requirement.path,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl From<&ResolvedDist> for Requirement {
extras: vec![],
marker: None,
source,
path: None,
}
}
}
2 changes: 2 additions & 0 deletions crates/distribution-types/src/specified_requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct UnresolvedRequirementSpecification {
pub requirement: UnresolvedRequirement,
/// Hashes of the downloadable packages.
pub hashes: Vec<String>,
/// Path of the source of the requirement
pub path: Option<String>,
}

/// A requirement read from a `requirements.txt` or `pyproject.toml` file.
Expand Down
17 changes: 16 additions & 1 deletion crates/pep508-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
#[cfg(feature = "pyo3")]
use std::ops::Deref;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str::FromStr;

#[cfg(feature = "pyo3")]
Expand Down Expand Up @@ -148,6 +148,16 @@ pub struct Requirement<T: Pep508Url = VerbatimUrl> {
/// `requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8"`.
/// Those are a nested and/or tree.
pub marker: Option<MarkerTree>,
/// The source file containing the requirement.
pub path: Option<PathBuf>,
}

impl Requirement {
/// Set the source file containing the requirement.
#[must_use]
pub fn with_source(self, path: Option<PathBuf>) -> Self {
Self { path, ..self }
}
}

impl<T: Pep508Url + Display> Display for Requirement<T> {
Expand Down Expand Up @@ -482,6 +492,7 @@ impl<T: Pep508Url> Requirement<T> {
extras,
version_or_url,
marker,
path,
} = self;
Requirement {
name,
Expand All @@ -494,6 +505,7 @@ impl<T: Pep508Url> Requirement<T> {
Some(VersionOrUrl::Url(url)) => Some(VersionOrUrl::Url(U::from(url))),
},
marker,
path,
}
}
}
Expand Down Expand Up @@ -1017,6 +1029,7 @@ fn parse_pep508_requirement<T: Pep508Url>(
extras,
version_or_url: requirement_kind,
marker,
path: None,
})
}

Expand Down Expand Up @@ -1158,6 +1171,7 @@ mod tests {
operator: MarkerOperator::LessThan,
r_value: MarkerValue::QuotedString("2.7".to_string()),
})),
path: None,
};
assert_eq!(requests, expected);
}
Expand Down Expand Up @@ -1383,6 +1397,7 @@ mod tests {
extras: vec![],
marker: None,
version_or_url: Some(VersionOrUrl::Url(Url::parse(url).unwrap())),
path: None,
};
assert_eq!(pip_url, expected);
}
Expand Down
11 changes: 10 additions & 1 deletion crates/pep508-rs/src/unnamed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::{Display, Formatter};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -30,6 +30,8 @@ pub struct UnnamedRequirement {
/// `requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8"`.
/// Those are a nested and/or tree.
pub marker: Option<MarkerTree>,
/// The source file containing the requirement.
pub path: Option<PathBuf>,
}

impl UnnamedRequirement {
Expand All @@ -41,6 +43,12 @@ impl UnnamedRequirement {
true
}
}

/// Set the source file containing the requirement.
#[must_use]
pub fn with_source(self, path: Option<PathBuf>) -> Self {
Self { path, ..self }
}
}

impl Display for UnnamedRequirement {
Expand Down Expand Up @@ -159,6 +167,7 @@ fn parse_unnamed_requirement(
url,
extras,
marker,
path: None,
})
}

Expand Down
Loading
Loading