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

Added a bunch of fields inspired by cargo & conda-build #218

Merged
merged 7 commits into from
Jul 14, 2023
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ serde_json = "1.0.96"
serde_spanned = "0.6.2"
serde_with = { version = "3.0.0", features = ["indexmap"] }
shlex = "1.1.0"
spdx = "0.10.1"
tempfile = "3.5.0"
tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "signal"] }
tokio-util = "0.7.8"
Expand Down
3 changes: 3 additions & 0 deletions examples/flask-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is a very simple example of a flask project

Just run `pixi run start` to get going with a flask server.
3 changes: 3 additions & 0 deletions examples/flask-hello-world/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ description = "Example how to get started with flask in a pixi environment."
authors = ["Wolf Vollprecht <wolf@prefix.dev>"]
channels = ["conda-forge"]
platforms = ["linux-64", "win-64", "osx-64", "osx-arm64"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/prefix/pixi"
readme = "README.md"

[tasks]
start = "python -m flask run --port=5050"
Expand Down
52 changes: 50 additions & 2 deletions src/project/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{consts, task::Task};
use ::serde::Deserialize;
use indexmap::IndexMap;
use miette::{LabeledSpan, NamedSource, Report};
use miette::{Context, IntoDiagnostic, LabeledSpan, NamedSource, Report};
use rattler_conda_types::{Channel, NamelessMatchSpec, Platform, Version};
use rattler_virtual_packages::{Archspec, Cuda, LibC, Linux, Osx, VirtualPackage};
use serde::Deserializer;
Expand All @@ -10,6 +10,8 @@ use serde_with::de::DeserializeAsWrap;
use serde_with::{serde_as, DeserializeAs, DisplayFromStr, PickFirst};
use std::collections::HashMap;
use std::ops::Range;
use std::path::{Path, PathBuf};
use url::Url;

/// Describes the contents of a project manifest.
#[serde_as]
Expand Down Expand Up @@ -66,7 +68,7 @@ pub struct ProjectManifest {

impl ProjectManifest {
/// Validate the
pub fn validate(&self, source: NamedSource) -> miette::Result<()> {
pub fn validate(&self, source: NamedSource, root_folder: &Path) -> miette::Result<()> {
// Check if the targets are defined for existing platforms
for target_sel in self.target.keys() {
match target_sel.as_ref() {
Expand All @@ -82,6 +84,34 @@ impl ProjectManifest {
}
}

// parse the SPDX license expression to make sure that it is a valid expression.
if let Some(spdx_expr) = &self.project.license {
spdx::Expression::parse(spdx_expr)
.into_diagnostic()
.with_context(|| {
format!(
"failed to parse the SPDX license expression '{}'",
spdx_expr
)
})?;
}

let check_file_existence = |x: &Option<PathBuf>| {
if let Some(path) = x {
let full_path = root_folder.join(path);
if !full_path.exists() {
return Err(miette::miette!(
"the file '{}' does not exist",
full_path.display()
));
}
}
Ok(())
};

check_file_existence(&self.project.license_file)?;
check_file_existence(&self.project.readme)?;

Ok(())
}
}
Expand Down Expand Up @@ -169,6 +199,24 @@ pub struct ProjectMetadata {
// TODO: This is actually slightly different from the rattler_conda_types::Platform because it
// should not include noarch.
pub platforms: Spanned<Vec<Platform>>,

/// The license as a valid SPDX string (e.g. MIT AND Apache-2.0)
pub license: Option<String>,

/// The license file (relative to the project root)
pub license_file: Option<PathBuf>,

/// Path to the README file of the project (relative to the project root)
pub readme: Option<PathBuf>,

/// URL of the project homepage
pub homepage: Option<Url>,

/// URL of the project source repository
pub repository: Option<Url>,

/// URL of the project documentation
pub documentation: Option<Url>,
}

#[serde_as]
Expand Down
9 changes: 5 additions & 4 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn task_as_toml(task: Task) -> Item {
impl Project {
/// Discovers the project manifest file in the current directory or any of the parent
/// directories.
/// This will also set the current working directory to the project root.
pub fn discover() -> miette::Result<Self> {
let project_toml = match find_project_root() {
Some(root) => root.join(consts::PROJECT_MANIFEST),
Expand Down Expand Up @@ -212,10 +213,10 @@ impl Project {
};

// Validate the contents of the manifest
manifest.validate(NamedSource::new(
consts::PROJECT_MANIFEST,
contents.to_owned(),
))?;
manifest.validate(
NamedSource::new(consts::PROJECT_MANIFEST, contents.to_owned()),
root,
)?;

Ok(Self {
root: root.to_path_buf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ProjectManifest {
span: 121..123,
value: [],
},
license: None,
license_file: None,
readme: None,
homepage: None,
repository: None,
documentation: None,
},
tasks: {},
system_requirements: SystemRequirements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ProjectManifest {
span: 121..123,
value: [],
},
license: None,
license_file: None,
readme: None,
homepage: None,
repository: None,
documentation: None,
},
tasks: {},
system_requirements: SystemRequirements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ProjectManifest {
span: 117..119,
value: [],
},
license: None,
license_file: None,
readme: None,
homepage: None,
repository: None,
documentation: None,
},
tasks: {},
system_requirements: SystemRequirements {
Expand Down
Loading