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

refactor: move run_exports to requiremens #394

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 12 additions & 11 deletions examples/mamba/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ outputs:
script:
- ${{ "build_mamba.sh" if unix }}
- ${{ "build_mamba.bat" if win }}
run_exports:
- ${{ pin_subpackage('libmamba', max_pin='x.x') }}
ignore_run_exports:
- spdlog
- python
# - ${{ "python" if win }}
requirements:
build:
- ${{ compiler('cxx') }}
Expand All @@ -54,6 +48,13 @@ outputs:
- zstd
run:
- libsolv >=0.7.23
run_exports:
- ${{ pin_subpackage('libmamba', max_pin='x.x') }}
ignore_run_exports:
by_name:
- spdlog
- python
# - ${{ "python" if win }}
test:
commands:
- if: unix
Expand Down Expand Up @@ -81,10 +82,6 @@ outputs:
- ${{ "build_mamba.sh" if unix }}
- ${{ "build_mamba.bat" if win }}
string: py_sup${{ python | version_to_buildstring }}h${{ hash }}_${{ build_number }}
run_exports:
- ${{ pin_subpackage('libmambapy', max_pin='x.x') }}
ignore_run_exports:
- spdlog
requirements:
build:
- ${{ compiler('cxx') }}
Expand Down Expand Up @@ -112,7 +109,11 @@ outputs:
run:
- python
- ${{ pin_subpackage('libmamba', exact=True) }}

run_exports:
- ${{ pin_subpackage('libmambapy', max_pin='x.x') }}
ignore_run_exports:
by_name:
- spdlog
test:
imports:
- libmambapy
Expand Down
12 changes: 11 additions & 1 deletion src/recipe/custom_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::{collections::BTreeMap, fmt, hash::Hash, ops, path::PathBuf};

use indexmap::IndexMap;
use indexmap::{IndexMap, IndexSet};
use marked_yaml::{types::MarkedScalarNode, Span};
use url::Url;

Expand Down Expand Up @@ -1086,6 +1086,16 @@ where
}
}

impl<T: Hash + Eq> TryConvertNode<IndexSet<T>> for RenderedNode
where
RenderedNode: TryConvertNode<T>,
RenderedScalarNode: TryConvertNode<T>,
{
fn try_convert(&self, name: &str) -> Result<IndexSet<T>, PartialParsingError> {
TryConvertNode::<Vec<T>>::try_convert(self, name).map(|v| v.into_iter().collect())
}
}

impl<T> TryConvertNode<Vec<T>> for RenderedNode
where
RenderedNode: TryConvertNode<T>,
Expand Down
6 changes: 4 additions & 2 deletions src/recipe/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ mod test;

pub use self::{
about::About,
build::{Build, RunExports},
build::Build,
output::find_outputs_from_src,
package::{OutputPackage, Package},
requirements::{Compiler, Dependency, PinSubpackage, Requirements},
requirements::{
Compiler, Dependency, IgnoreRunExports, PinSubpackage, Requirements, RunExports,
},
script::{Script, ScriptContent},
source::{Checksum, GitSource, GitUrl, PathSource, Source, UrlSource},
test::{PackageContent, Test},
Expand Down
103 changes: 2 additions & 101 deletions src/recipe/parser/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use rattler_conda_types::{package::EntryPoint, NoArchKind, NoArchType, PackageName};
use rattler_conda_types::{package::EntryPoint, NoArchKind, NoArchType};
use serde::{Deserialize, Serialize};

use super::Dependency;
Expand All @@ -9,8 +9,7 @@ use crate::{
_partialerror,
recipe::{
custom_yaml::{
HasSpan, RenderedMappingNode, RenderedNode, RenderedScalarNode, RenderedSequenceNode,
TryConvertNode,
HasSpan, RenderedMappingNode, RenderedNode, RenderedScalarNode, TryConvertNode,
},
error::{ErrorKind, PartialParsingError},
},
Expand All @@ -30,12 +29,6 @@ pub struct Build {
/// The build script can be either a list of commands or a path to a script. By
/// default, the build script is set to `build.sh` or `build.bat` on Unix and Windows respectively.
pub(super) script: Script,
/// A recipe can choose to ignore certain run exports of its dependencies
pub(super) ignore_run_exports: Vec<PackageName>,
/// A recipe can choose to ignore all run exports of coming from some packages
pub(super) ignore_run_exports_from: Vec<PackageName>,
/// The recipe can specify a list of run exports that it provides
pub(super) run_exports: RunExports,
/// A noarch package runs on any platform. It can be either a python package or a generic package.
pub(super) noarch: NoArchType,
/// For a Python noarch package to have executables it is necessary to specify the python entry points.
Expand Down Expand Up @@ -65,25 +58,6 @@ impl Build {
&self.script
}

/// Get run exports.
pub const fn run_exports(&self) -> &RunExports {
&self.run_exports
}

/// Get the ignore run exports.
///
/// A recipe can choose to ignore certain run exports of its dependencies
pub fn ignore_run_exports(&self) -> &[PackageName] {
self.ignore_run_exports.as_slice()
}

/// Get the ignore run exports from.
///
/// A recipe can choose to ignore all run exports of coming from some packages
pub fn ignore_run_exports_from(&self) -> &[PackageName] {
self.ignore_run_exports_from.as_slice()
}

/// Get the noarch type.
pub const fn noarch(&self) -> &NoArchType {
&self.noarch
Expand Down Expand Up @@ -127,18 +101,9 @@ impl TryConvertNode<Build> for RenderedMappingNode {
build.skip = conds.iter().any(|&v| v);
}
"script" => build.script = value.try_convert(key_str)?,
"ignore_run_exports" => {
build.ignore_run_exports = value.try_convert(key_str)?;
}
"ignore_run_exports_from" => {
build.ignore_run_exports_from = value.try_convert(key_str)?;
}
"noarch" => {
build.noarch = value.try_convert(key_str)?;
}
"run_exports" => {
build.run_exports = value.try_convert(key_str)?;
}
"entry_points" => {
if let Some(NoArchKind::Generic) = build.noarch.kind() {
return Err(_partialerror!(
Expand Down Expand Up @@ -224,17 +189,6 @@ impl RunExports {
}
}

impl TryConvertNode<RunExports> for RenderedNode {
fn try_convert(&self, name: &str) -> Result<RunExports, PartialParsingError> {
match self {
RenderedNode::Scalar(s) => s.try_convert(name),
RenderedNode::Sequence(seq) => seq.try_convert(name),
RenderedNode::Mapping(map) => map.try_convert(name),
RenderedNode::Null(_) => Ok(RunExports::default()),
}
}
}

impl TryConvertNode<RunExports> for RenderedScalarNode {
fn try_convert(&self, name: &str) -> Result<RunExports, PartialParsingError> {
let mut run_exports = RunExports::default();
Expand All @@ -246,59 +200,6 @@ impl TryConvertNode<RunExports> for RenderedScalarNode {
}
}

impl TryConvertNode<RunExports> for RenderedSequenceNode {
fn try_convert(&self, name: &str) -> Result<RunExports, PartialParsingError> {
let mut run_exports = RunExports::default();

for node in self.iter() {
let deps = node.try_convert(name)?;
run_exports.weak = deps;
}

Ok(run_exports)
}
}

impl TryConvertNode<RunExports> for RenderedMappingNode {
fn try_convert(&self, name: &str) -> Result<RunExports, PartialParsingError> {
let mut run_exports = RunExports::default();

for (key, value) in self.iter() {
let key_str = key.as_str();
match key_str {
"noarch" => {
run_exports.noarch = value.try_convert(key_str)?;
}
"strong" => {
let deps = value.try_convert(key_str)?;
run_exports.strong = deps;
}
"strong_constrains" => {
let deps = value.try_convert(key_str)?;
run_exports.strong_constrains = deps;
}
"weak" => {
let deps = value.try_convert(key_str)?;
run_exports.weak = deps;
}
"weak_constrains" => {
let deps = value.try_convert(key_str)?;
run_exports.weak_constrains = deps;
}
invalid => {
return Err(_partialerror!(
*key.span(),
ErrorKind::InvalidField(invalid.to_owned().into()),
help = format!("fields for {name} should be one of: `weak`, `strong`, `noarch`, `strong_constrains`, or `weak_constrains`")
));
}
}
}

Ok(run_exports)
}
}

impl TryConvertNode<NoArchType> for RenderedNode {
fn try_convert(&self, name: &str) -> Result<NoArchType, PartialParsingError> {
self.as_scalar()
Expand Down
Loading
Loading