Skip to content

Commit

Permalink
fix: issue 1797 (#1851)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruben Arts <[email protected]>
  • Loading branch information
baszalmstra and ruben-arts authored Aug 20, 2024
1 parent 1db68e0 commit 21a8c6a
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 152 deletions.
3 changes: 2 additions & 1 deletion crates/pixi_manifest/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ impl ManifestSource {
}
}
ManifestSource::PixiToml(_) => {
let mut pypi_requirement = PyPiRequirement::try_from(requirement.clone())?;
let mut pypi_requirement =
PyPiRequirement::try_from(requirement.clone()).map_err(Box::new)?;
if let Some(editable) = editable {
pypi_requirement.set_editable(editable);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/pixi_manifest/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum DependencyError {
NoDependency(String),
#[error("No Pypi dependencies.")]
NoPyPiDependencies,
#[error(transparent)]
Pep508ToPyPiRequirementError(#[from] Box<Pep508ToPyPiRequirementError>),
}

#[derive(Error, Debug)]
Expand All @@ -44,7 +46,7 @@ pub enum TomlError {
table_name: String,
},
#[error("Could not convert pep508 to pixi pypi requirement")]
Conversion(#[from] Pep508ToPyPiRequirementError),
Conversion(#[from] Box<Pep508ToPyPiRequirementError>),
}

impl TomlError {
Expand Down
48 changes: 41 additions & 7 deletions crates/pixi_manifest/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ impl Manifest {
let contents = contents.into();
let (parsed, file_name) = match manifest_kind {
ManifestKind::Pixi => (ParsedManifest::from_toml_str(&contents), "pixi.toml"),
ManifestKind::Pyproject => (
PyProjectManifest::from_toml_str(&contents)
ManifestKind::Pyproject => {
let manifest = match PyProjectManifest::from_toml_str(&contents)
.and_then(|m| m.ensure_pixi(&contents))
.map(|x| x.into()),
"pyproject.toml",
),
{
Ok(manifest) => Ok(manifest.try_into().into_diagnostic()?),
Err(e) => Err(e),
};
(manifest, "pyproject.toml")
}
};

let (manifest, document) = match parsed.and_then(|manifest| {
Expand Down Expand Up @@ -374,7 +377,7 @@ impl Manifest {
}

/// Add a pypi requirement to the manifest
pub fn add_pypi_dependency(
pub fn add_pep508_dependency(
&mut self,
requirement: &pep508_rs::Requirement,
platforms: &[Platform],
Expand All @@ -387,7 +390,7 @@ impl Manifest {
// Add the pypi dependency to the manifest
match self
.get_or_insert_target_mut(platform, Some(feature_name))
.try_add_pypi_dependency(requirement, editable, overwrite_behavior)
.try_add_pep508_dependency(requirement, editable, overwrite_behavior)
{
Ok(true) => {
self.document.add_pypi_dependency(
Expand Down Expand Up @@ -2108,4 +2111,35 @@ bar = "*"
ChannelPriority::Disabled
);
}

#[test]
pub fn test_unsupported_pep508_errors() {
let manifest_error = Manifest::from_str(
Path::new("pyproject.toml"),
r#"
[project]
name = "issue-1797"
version = "0.1.0"
dependencies = [
"attrs @ git+ssh://[email protected]/python-attrs/attrs.git@main"
]
[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["win-64"]
"#,
)
.unwrap_err();

let mut error = String::new();
let report_handler = NarratableReportHandler::new().with_cause_chain();
report_handler
.render_report(&mut error, manifest_error.as_ref())
.unwrap();
insta::assert_snapshot!(error, @r###"
Unsupported pep508 requirement: 'attrs @ git+ssh://[email protected]/python-attrs/attrs.git@main'
Diagnostic severity: error
Caused by: Found invalid characters for git revision 'main', branches and tags are not supported yet
"###);
}
}
1 change: 0 additions & 1 deletion crates/pixi_manifest/src/pypi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod pypi_options;
pub mod pypi_requirement;
pub mod pypi_requirement_types;

pub use pypi_requirement_types::{GitRev, PyPiPackageName, VersionOrStar};
Loading

0 comments on commit 21a8c6a

Please sign in to comment.