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

Fix requirements parsing with index URL option #1251

Merged
merged 13 commits into from
Oct 11, 2023
8 changes: 6 additions & 2 deletions lockfile/src/parsers/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ fn line<'a>(input: &'a str, registry: &mut Option<&'a str>) -> IResult<&'a str,
//
// Since `ThirdPartyVersion` only allows a single registry, we only record the
// primary one.
if let Some(index_url) = line.strip_prefix("--index-url ").or_else(|| line.strip_prefix("-i "))
if let Some(mut index_url) =
line.strip_prefix("--index-url").or_else(|| line.strip_prefix("-i"))
{
// Strip optional `=` from `--index-url=https://...`
index_url = index_url.trim().strip_prefix('=').unwrap_or(index_url).trim();

*registry = Some(index_url.trim());
line = "";
}
if line.starts_with("--extra-index-url ") {
if line.starts_with("--extra-index-url") {
line = "";
}

Expand Down
10 changes: 9 additions & 1 deletion lockfile/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ mod tests {
let pkgs = PyRequirements
.parse(include_str!("../../tests/fixtures/requirements-locked.txt"))
.unwrap();
assert_eq!(pkgs.len(), 13);
assert_eq!(pkgs.len(), 14);

let expected_pkgs = [
Package {
Expand Down Expand Up @@ -301,6 +301,14 @@ mod tests {
version: PackageVersion::Path(Some("/tmp/editable".into())),
package_type: PackageType::PyPi,
},
Package {
name: "other-registry-a".into(),
version: PackageVersion::ThirdParty(ThirdPartyVersion {
registry: "https://mirror1.phylum.io/simple/".into(),
version: "3.2.1".into(),
}),
package_type: PackageType::PyPi,
},
Package {
name: "other-registry".into(),
version: PackageVersion::ThirdParty(ThirdPartyVersion {
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/requirements-locked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ tomli @ https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a25
-e /tmp/editable ; python_version >= "3.7" and python_version < "3.12"

--index-url https://mirror1.phylum.io/simple/
cd-work marked this conversation as resolved.
Show resolved Hide resolved
-i https://mirror2.phylum.io/simple/
other-registry-a==3.2.1
-i=https://mirror2.phylum.io/simple/
kylewillmon marked this conversation as resolved.
Show resolved Hide resolved
--extra-index-url https://mirror3.phylum.io/simple/
--extra-index-url=https://mirror3.phylum.io/simple/
other-registry==1.2.3
Loading