Skip to content

Commit

Permalink
fix: subdirectory in pypi url (#2065)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Sep 17, 2024
1 parent de470e7 commit db022c7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
22 changes: 21 additions & 1 deletion crates/pixi_manifest/src/pypi/pypi_requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl TryFrom<Url> for ParsedGitUrl {

// Strip the git+ from the url.
let url_without_git = url.as_str().strip_prefix("git+").unwrap_or(url.as_str());
let url = Url::parse(url_without_git)?;
let mut url = Url::parse(url_without_git)?;
url.set_fragment(None);

// Split the repository url and the rev.
let (repository_url, rev) = if let Some((prefix, suffix)) = url
Expand Down Expand Up @@ -954,6 +955,25 @@ mod tests {
GitRevParseError::InvalidCharacters(characters)
)) if characters == "main"
);

// With subdirectory
let parsed = pep508_rs::Requirement::from_str(
"ribasim@git+https://github.com/Deltares/Ribasim.git#subdirectory=python/ribasim",
)
.unwrap();
assert_eq!(
PyPiRequirement::try_from(parsed).unwrap(),
PyPiRequirement::Git {
url: ParsedGitUrl {
git: Url::parse("https://github.com/Deltares/Ribasim.git").unwrap(),
branch: None,
tag: None,
rev: None,
subdirectory: Some("python/ribasim".to_string()),
},
extras: vec![],
}
);
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/pixi_manifest/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ impl Target {
///
/// This will overwrite any existing dependency of the same name
pub fn add_pypi_dependency(&mut self, name: PyPiPackageName, requirement: PyPiRequirement) {
tracing::info!(
"Adding pypi dependency: {} {}",
name.as_normalized(),
requirement
);
self.pypi_dependencies
.get_or_insert_with(Default::default)
.insert(name, requirement);
Expand Down
4 changes: 4 additions & 0 deletions schema/examples/valid/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ warmup = "python warmup.py"
[feature.cuda2.target.osx-arm64.dependencies]
mlx = "x.y.z"

[feature.dev.pypi-dependencies]
ribasim = { git = "https://github.com/Deltares/Ribasim.git", subdirectory = "python/ribasim" }
ribasim2 = { path = "test/riba", subdirectory = "python/ribasim" }

# Channels and Platforms are not available as separate tables as they are implemented as lists
[feature.cuda2]
channels = ["nvidia"]
Expand Down
7 changes: 6 additions & 1 deletion schema/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
VERSION = CARGO_TOML_DATA["package"]["version"]
SCHEMA_URI = f"https://pixi.sh/v{VERSION}/schema/manifest/schema.json"


NonEmptyStr = Annotated[str, StringConstraints(min_length=1)]
Md5Sum = Annotated[str, StringConstraints(pattern=r"^[a-fA-F0-9]{32}$")]
Sha256Sum = Annotated[str, StringConstraints(pattern=r"^[a-fA-F0-9]{64}$")]
Expand Down Expand Up @@ -200,6 +199,9 @@ class _PyPiGitRequirement(_PyPIRequirement):
None,
description="The `git` URL to the repo e.g https://github.com/prefix-dev/pixi",
)
subdirectory: NonEmptyStr | None = Field(
None, description="The subdirectory in the repo, a path from the root of the repo."
)


class PyPIGitRevRequirement(_PyPiGitRequirement):
Expand All @@ -222,6 +224,9 @@ class PyPIPathRequirement(_PyPIRequirement):
editable: Optional[bool] = Field(
None, description="If `true` the package will be installed as editable"
)
subdirectory: NonEmptyStr | None = Field(
None, description="The subdirectory in the repo, a path from the root of the repo."
)


class PyPIUrlRequirement(_PyPIRequirement):
Expand Down
24 changes: 24 additions & 0 deletions schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@
"description": "The `git` URL to the repo e.g https://github.com/prefix-dev/pixi",
"type": "string",
"minLength": 1
},
"subdirectory": {
"title": "Subdirectory",
"description": "The subdirectory in the repo, a path from the root of the repo.",
"type": "string",
"minLength": 1
}
}
},
Expand Down Expand Up @@ -854,6 +860,12 @@
"description": "A `git` SHA revision to use",
"type": "string",
"minLength": 1
},
"subdirectory": {
"title": "Subdirectory",
"description": "The subdirectory in the repo, a path from the root of the repo.",
"type": "string",
"minLength": 1
}
}
},
Expand All @@ -877,6 +889,12 @@
"type": "string",
"minLength": 1
},
"subdirectory": {
"title": "Subdirectory",
"description": "The subdirectory in the repo, a path from the root of the repo.",
"type": "string",
"minLength": 1
},
"tag": {
"title": "Tag",
"description": "A `git` tag to use",
Expand Down Expand Up @@ -994,6 +1012,12 @@
"description": "A path to a local source or wheel",
"type": "string",
"minLength": 1
},
"subdirectory": {
"title": "Subdirectory",
"description": "The subdirectory in the repo, a path from the root of the repo.",
"type": "string",
"minLength": 1
}
}
},
Expand Down

0 comments on commit db022c7

Please sign in to comment.