Skip to content

Commit

Permalink
fix: stricter input parsing and more lenient parsing of run exports f…
Browse files Browse the repository at this point in the history
…rom other packages (#1271)
  • Loading branch information
wolfv authored Dec 17, 2024
1 parent bc98f43 commit 8a3484b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 30 deletions.
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 RenderedNode {

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 {
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

0 comments on commit 8a3484b

Please sign in to comment.