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: stricter input parsing and more lenient parsing of run exports from other packages #1271

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ requirements:
host:
- pip
- poetry-core >=1.0.0
- python 3.10
- python 3.10.*
run:
# sync with normalized deps from poetry-generated setup.py
- markdown-it-py >=2.2.0
- pygments >=2.13.0,<3.0.0
- python 3.10
- python 3.10.*
- typing_extensions >=4.0.0,<5.0.0

tests:
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ requirements:
host:
- pip
- poetry-core >=1.0.0
- python 3.10
- python 3.10.*
run:
# sync with normalized deps from poetry-generated setup.py
- markdown-it-py >=2.2.0
- pygments >=2.13.0,<3.0.0
- python 3.10
- python 3.10.*
- typing_extensions >=4.0.0,<5.0.0

tests:
Expand Down
4 changes: 2 additions & 2 deletions examples/rich/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ requirements:
host:
- pip
- poetry-core >=1.0.0
- python 3.10
- python 3.10.*
run:
# sync with normalized deps from poetry-generated setup.py
- markdown-it-py >=2.2.0
- pygments >=2.13.0,<3.0.0
- python 3.10
- python 3.10.*
- typing_extensions >=4.0.0,<5.0.0

tests:
Expand Down
8 changes: 3 additions & 5 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{path::PathBuf, vec};

use miette::{Context, IntoDiagnostic};
use rattler_conda_types::{Channel, MatchSpec, ParseStrictness};
use rattler_conda_types::{Channel, MatchSpec};

use crate::{
metadata::{build_reindexed_channels, Output},
Expand Down Expand Up @@ -39,10 +39,8 @@ pub async fn skip_existing(

let match_specs = outputs
.iter()
.map(|o| {
MatchSpec::from_str(o.name().as_normalized(), ParseStrictness::Strict).into_diagnostic()
})
.collect::<Result<Vec<_>, _>>()?;
.map(|o| o.name().clone().into())
.collect::<Vec<MatchSpec>>();

let channels = if only_local {
vec![
Expand Down
11 changes: 4 additions & 7 deletions src/package_test/run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ impl PythonTest {

// Add `pip` if pip_check is set to true
if self.pip_check {
dependencies_map.iter_mut().for_each(|(_, v)| {
v.push(MatchSpec::from_str("pip", ParseStrictness::Strict).unwrap())
});
dependencies_map
.iter_mut()
.for_each(|(_, v)| v.push("pip".parse().unwrap()));
}

// Run tests for each python version
Expand Down Expand Up @@ -613,10 +613,7 @@ impl PerlTest {
ParseStrictness::Lenient,
)?;

let dependencies = vec![
MatchSpec::from_str("perl", ParseStrictness::Strict).unwrap(),
match_spec,
];
let dependencies = vec!["perl".parse().unwrap(), match_spec];

create_environment(
"test",
Expand Down
26 changes: 26 additions & 0 deletions src/recipe/parser/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,32 @@

impl TryConvertNode<MatchSpec> for RenderedScalarNode {
fn try_convert(&self, _name: &str) -> Result<MatchSpec, Vec<PartialParsingError>> {
let string = self.as_str();

// if we have a matchspec that is only numbers, and ., we complain and ask the user to add a
// `.*` or `==` in front of it.
let split_string = string.split_whitespace().collect::<Vec<_>>();
if split_string.len() >= 2 {

Check failure on line 374 in src/recipe/parser/requirements.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

[clippy] reported by reviewdog 🐶 error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | Raw Output: src/recipe/parser/requirements.rs:374:9:e:error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | __END__

Check failure on line 374 in src/recipe/parser/requirements.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

[clippy] reported by reviewdog 🐶 error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | Raw Output: src/recipe/parser/requirements.rs:374:9:e:error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | __END__

Check failure on line 374 in src/recipe/parser/requirements.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

[clippy] reported by reviewdog 🐶 error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | Raw Output: src/recipe/parser/requirements.rs:374:9:e:error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | __END__

Check failure on line 374 in src/recipe/parser/requirements.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

[clippy] reported by reviewdog 🐶 error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | Raw Output: src/recipe/parser/requirements.rs:374:9:e:error: this `if` statement can be collapsed --> src/recipe/parser/requirements.rs:374:9 | 374 | / if split_string.len() >= 2 { 375 | | if split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 376 | | let name = split_string[0]; 377 | | let version = split_string[1]; ... | 392 | | } 393 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 374 ~ if split_string.len() >= 2 && split_string[1].chars().all(|c| c.is_numeric() || c == '.') { 375 + let name = split_string[0]; 376 + let version = split_string[1]; 377 + let rest = split_string[2..].join(" "); 378 + let rest = if rest.is_empty() { 379 + "".to_string() 380 + } else { 381 + format!(" {}", rest) 382 + }; 383 + 384 + return Err(vec![_partialerror!( 385 + *self.span(), 386 + ErrorKind::Other, 387 + label = format!( 388 + "This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?" 389 + ) 390 + )]); 391 + } | __END__
if split_string[1].chars().all(|c| c.is_numeric() || c == '.') {
let name = split_string[0];
let version = split_string[1];
let rest = split_string[2..].join(" ");
let rest = if rest.is_empty() {
"".to_string()
} else {
format!(" {}", rest)
};

return Err(vec![_partialerror!(
*self.span(),
ErrorKind::Other,
label = format!(
"This match spec is ambiguous. Do you mean `{name} =={version}{rest}` or `{name} {version}.*{rest}`?"
)
)]);
}
}

MatchSpec::from_str(self.as_str(), ParseStrictness::Strict).map_err(|err| {
let str = self.as_str();
vec![_partialerror!(
Expand Down
3 changes: 2 additions & 1 deletion src/render/run_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl IgnoreRunExports {
let to_specs = |strings: &Vec<String>| -> Result<Vec<MatchSpec>, ParseMatchSpecError> {
strings
.iter()
.map(|s| MatchSpec::from_str(s, ParseStrictness::Strict))
// We have to parse these as lenient as they come from packages
.map(|s| MatchSpec::from_str(s, ParseStrictness::Lenient))
.filter_map(|result| match result {
Ok(spec) => {
if spec
Expand Down
4 changes: 2 additions & 2 deletions test-data/recipes/package-content-tests/rich-recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ requirements:
host:
- pip
- poetry-core >=1.0.0
- python 3.10
- python 3.10.*
run:
# sync with normalized deps from poetry-generated setup.py
- markdown-it-py >=2.2.0
- pygments >=2.13.0,<3.0.0
- python 3.10
- python 3.10.*
- typing_extensions >=4.0.0,<5.0.0

tests:
Expand Down
2 changes: 0 additions & 2 deletions test-data/recipes/race-condition/recipe-python-min.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ package:

requirements:
host:
- python ${{ python_min }}
- python >=${{ python_min }}
- python ${{ python_min }}.*
- python ${{ python_min ~ ".*,<4.0a0" }}
run:
- python ${{ python_min }}
- python >=${{ python_min }}
- python ${{ python_min }}.*
- python ${{ python_min ~ ".*,<4.0a0" }}
4 changes: 2 additions & 2 deletions test-data/recipes/rich/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ requirements:
host:
- pip
- poetry-core >=1.0.0
- python 3.10
- python 3.10.*
run:
# sync with normalized deps from poetry-generated setup.py
- markdown-it-py >=2.2.0
- pygments >=2.13.0,<3.0.0
- python 3.10
- python 3.10.*
- typing_extensions >=4.0.0,<5.0.0

tests:
Expand Down
6 changes: 3 additions & 3 deletions test-data/recipes/toml/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ build:

requirements:
host:
- python 3.12.1
- pip 23.3.2
- setuptools 68
- python 3.12.1.*
- pip 23.3.2.*
- setuptools 68.*
run:
- python

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"host": [
"python ==3.8.0",
"python >=3.8.0",
"python 3.8.0.*",
"python 3.8.0.*,<4.0a0"
],
"run": [
"python ==3.8.0",
"python >=3.8.0",
"python 3.8.0.*",
"python 3.8.0.*,<4.0a0"
Expand Down
Loading