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 2 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ impl From<Dist> for Requirement {
),
)),
marker: None,
path: None,
},

Dist::Built(BuiltDist::DirectUrl(wheel)) => Self {
name: wheel.filename.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(wheel.url)),
marker: None,
path: None,
},
Dist::Built(BuiltDist::Path(wheel)) => Self {
name: wheel.filename.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(wheel.url)),
marker: None,
path: None,
},
Dist::Source(SourceDist::Registry(sdist)) => Self {
name: sdist.filename.name,
Expand All @@ -106,24 +109,28 @@ impl From<Dist> for Requirement {
),
)),
marker: None,
path: None,
},
Dist::Source(SourceDist::DirectUrl(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
},
Dist::Source(SourceDist::Git(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
},
Dist::Source(SourceDist::Path(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
},
}
}
Expand All @@ -140,6 +147,7 @@ impl From<InstalledDist> for Requirement {
)),
)),
marker: None,
path: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/pep440-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#[cfg(feature = "pyo3")]
pub use version::PyVersion;
pub use {
tracked_from_str::TrackedFromStr,
version::{
LocalSegment, Operator, OperatorParseError, PreRelease, PreReleaseKind, Version,
VersionParseError, VersionPattern, VersionPatternParseError, MIN_VERSION,
Expand All @@ -47,6 +48,7 @@ pub use {
},
};

mod tracked_from_str;
mod version;
mod version_specifier;

Expand Down
14 changes: 14 additions & 0 deletions crates/pep440-rs/src/tracked_from_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::Path;

/// Like FromStr, but with information about where the str came from
pub trait TrackedFromStr: Sized {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not entirely sure this is the right package, but AFAIK, it's the only crate that everything that needs it can depend on....

Copy link
Member

Choose a reason for hiding this comment

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

I want to experiment with a slightly different approach here. Instead of a trait, could we just always use None for the source, and then add a method to set the source after parsing? Since the parsing itself doesn't depend on the source at all, right?

Copy link
Member

Choose a reason for hiding this comment

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

(I can give it a try.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. If you can make it work, all good!

/// The associated error which can be returned from parsing.
type Err;

/// Convert from input with optional source and working_dir
fn tracked_from_str(
input: &str,
source: Option<&Path>,
working_dir: Option<&Path>,
) -> Result<Self, Self::Err>;
}
19 changes: 16 additions & 3 deletions crates/pep440-rs/src/version_specifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "pyo3")]
use std::hash::{Hash, Hasher};
use std::{cmp::Ordering, str::FromStr};
use std::{cmp::Ordering, path::Path, str::FromStr};

#[cfg(feature = "pyo3")]
use pyo3::{
Expand All @@ -15,7 +15,8 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "pyo3")]
use crate::version::PyVersion;
use crate::{
version, Operator, OperatorParseError, Version, VersionPattern, VersionPatternParseError,
tracked_from_str::TrackedFromStr, version, Operator, OperatorParseError, Version,
VersionPattern, VersionPatternParseError,
};

/// A thin wrapper around `Vec<VersionSpecifier>` with a serde implementation
Expand Down Expand Up @@ -66,11 +67,23 @@ impl FromIterator<VersionSpecifier> for VersionSpecifiers {
}
}

impl TrackedFromStr for VersionSpecifiers {
type Err = VersionSpecifiersParseError;

fn tracked_from_str(
input: &str,
_source: Option<&Path>,
_working_dir: Option<&Path>,
) -> Result<Self, Self::Err> {
parse_version_specifiers(input).map(Self)
}
}

impl FromStr for VersionSpecifiers {
type Err = VersionSpecifiersParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
parse_version_specifiers(s).map(Self)
Self::tracked_from_str(s, None, None)
}
}

Expand Down
Loading
Loading