Skip to content

Commit

Permalink
refactor: move run_exports to requiremens
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Dec 5, 2023
1 parent 4635fb3 commit 59fd5a2
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 220 deletions.
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
4 changes: 2 additions & 2 deletions src/recipe/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ mod test;

pub use self::{
about::About,
build::{Build, RunExports, ScriptEnv},
build::{Build, ScriptEnv},
output::find_outputs_from_src,
package::{OutputPackage, Package},
requirements::{Compiler, Dependency, PinSubpackage, Requirements},
requirements::{Compiler, Dependency, PinSubpackage, Requirements, RunExports, IgnoreRunExports},
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,14 +1,13 @@
use std::{collections::BTreeMap, str::FromStr};

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

use crate::{
_partialerror,
recipe::{
custom_yaml::{
HasSpan, RenderedMappingNode, RenderedNode, RenderedScalarNode, RenderedSequenceNode,
TryConvertNode,
HasSpan, RenderedMappingNode, RenderedNode, RenderedScalarNode, TryConvertNode,
},
error::{ErrorKind, PartialParsingError},
},
Expand All @@ -32,12 +31,6 @@ pub struct Build {
pub(super) script: Vec<String>,
/// Environment variables to pass through or set in the script
pub(super) script_env: ScriptEnv,
/// 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 @@ -72,25 +65,6 @@ impl Build {
&self.script_env
}

/// 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 @@ -135,18 +109,9 @@ impl TryConvertNode<Build> for RenderedMappingNode {
}
"script" => build.script = value.try_convert(key_str)?,
"script_env" => build.script_env = 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 @@ -328,17 +293,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 @@ -350,59 +304,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

0 comments on commit 59fd5a2

Please sign in to comment.