Skip to content

Commit

Permalink
Refactor manifest (#572)
Browse files Browse the repository at this point in the history
Refactoring the `Project` into `Manifest`

This is done to split the responsibilities.
  • Loading branch information
ruben-arts authored Dec 18, 2023
1 parent 174a21a commit c211842
Show file tree
Hide file tree
Showing 17 changed files with 1,028 additions and 926 deletions.
26 changes: 16 additions & 10 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::environment::{update_prefix, verify_prefix_location_unchanged};
use crate::prefix::Prefix;
use crate::project::DependencyType::CondaDependency;
use crate::project::{DependencyType, SpecType};
use crate::{
consts,
Expand Down Expand Up @@ -94,11 +93,11 @@ impl DependencyType {
if args.pypi {
Self::PypiDependency
} else if args.host {
CondaDependency(SpecType::Host)
DependencyType::CondaDependency(SpecType::Host)
} else if args.build {
CondaDependency(SpecType::Build)
DependencyType::CondaDependency(SpecType::Build)
} else {
CondaDependency(SpecType::Run)
DependencyType::CondaDependency(SpecType::Run)
}
}
}
Expand All @@ -122,7 +121,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.filter(|p| !project.platforms().contains(p))
.cloned()
.collect::<Vec<Platform>>();
project.add_platforms(platforms_to_add.iter())?;
project.manifest.add_platforms(platforms_to_add.iter())?;

match dependency_type {
DependencyType::CondaDependency(spec_type) => {
Expand Down Expand Up @@ -183,7 +182,10 @@ pub async fn execute(args: Args) -> miette::Result<()> {
}

// Print if it is something different from host and dep
if !matches!(dependency_type, CondaDependency(SpecType::Run)) {
if !matches!(
dependency_type,
DependencyType::CondaDependency(SpecType::Run)
) {
eprintln!(
"Added these as {}.",
console::style(dependency_type.name()).bold()
Expand Down Expand Up @@ -212,10 +214,12 @@ pub async fn add_pypi_specs_to_project(
// TODO: Get best version
// Add the dependency to the project
if specs_platforms.is_empty() {
project.add_pypi_dependency(name, spec)?;
project.manifest.add_pypi_dependency(name, spec)?;
} else {
for platform in specs_platforms.iter() {
project.add_target_pypi_dependency(*platform, name.clone(), spec)?;
project
.manifest
.add_target_pypi_dependency(*platform, name.clone(), spec)?;
}
}
}
Expand Down Expand Up @@ -309,10 +313,12 @@ pub async fn add_conda_specs_to_project(

// Add the dependency to the project
if specs_platforms.is_empty() {
project.add_dependency(&spec, spec_type)?;
project.manifest.add_dependency(&spec, spec_type)?;
} else {
for platform in specs_platforms.iter() {
project.add_target_dependency(*platform, &spec, spec_type)?;
project
.manifest
.add_target_dependency(*platform, &spec, spec_type)?;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let project_info = project.map(|p| ProjectInfo {
manifest_path: p.root().to_path_buf().join("pixi.toml"),
tasks: p
.manifest
.tasks(Some(Platform::current()))
.into_keys()
.map(|k| k.to_string())
Expand Down
4 changes: 3 additions & 1 deletion src/cli/project/channel/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
let lock_file = load_lock_file(&project).await?;

// Add the channels to the lock-file
project.add_channels(missing_channels.iter().map(|(name, _channel)| name))?;
project
.manifest
.add_channels(missing_channels.iter().map(|(name, _channel)| name))?;

// Try to update the lock-file with the new channels
let lock_file = update_lock_file(&project, lock_file, None).await?;
Expand Down
6 changes: 4 additions & 2 deletions src/cli/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.iter()
.map(|dep| {
if let Some(p) = &args.platform {
project.remove_target_dependency(dep, &spec_type, p)
project
.manifest
.remove_target_dependency(dep, &spec_type, p)
} else {
project.remove_dependency(dep, &spec_type)
project.manifest.remove_dependency(dep, &spec_type)
}
})
.collect::<Vec<_>>();
Expand Down
1 change: 1 addition & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ async fn execute_task<'p>(
if status_code == 127 {
let available_tasks = task
.project()
.manifest
.tasks(Some(Platform::current()))
.into_keys()
.sorted()
Expand Down
13 changes: 9 additions & 4 deletions src/cli/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ pub fn execute(args: Args) -> miette::Result<()> {
Operation::Add(args) => {
let name = &args.name;
let task: Task = args.clone().into();
project.add_task(name, task.clone(), args.platform)?;
project
.manifest
.add_task(name, task.clone(), args.platform)?;
eprintln!(
"{}Added task {}: {}",
console::style(console::Emoji("✔ ", "+")).green(),
Expand All @@ -152,6 +154,7 @@ pub fn execute(args: Args) -> miette::Result<()> {
for name in args.names.iter() {
if let Some(platform) = args.platform {
if !project
.manifest
.target_specific_tasks(platform)
.contains_key(name.as_str())
{
Expand All @@ -163,7 +166,7 @@ pub fn execute(args: Args) -> miette::Result<()> {
);
continue;
}
} else if !project.tasks(None).contains_key(name.as_str()) {
} else if !project.manifest.tasks(None).contains_key(name.as_str()) {
eprintln!(
"{}Task {} does not exist",
console::style(console::Emoji("❌ ", "X")).red(),
Expand Down Expand Up @@ -191,7 +194,7 @@ pub fn execute(args: Args) -> miette::Result<()> {
}

for (name, platform) in to_remove {
project.remove_task(name, platform)?;
project.manifest.remove_task(name, platform)?;
eprintln!(
"{}Removed task {} ",
console::style(console::Emoji("✔ ", "+")).green(),
Expand All @@ -202,7 +205,9 @@ pub fn execute(args: Args) -> miette::Result<()> {
Operation::Alias(args) => {
let name = &args.alias;
let task: Task = args.clone().into();
project.add_task(name, task.clone(), args.platform)?;
project
.manifest
.add_task(name, task.clone(), args.platform)?;
eprintln!(
"{} Added alias {}: {}",
console::style("@").blue(),
Expand Down
4 changes: 2 additions & 2 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn sanity_check_project(project: &Project) -> miette::Result<()> {
// Make sure the project supports the current platform
let platform = Platform::current();
if !project.platforms().contains(&platform) {
let span = project.manifest.project.platforms.span();
let span = project.manifest.parsed.project.platforms.span();
return Err(miette::miette!(
help = format!(
"The project needs to be configured to support your platform ({platform})."
Expand All @@ -99,7 +99,7 @@ pub fn sanity_check_project(project: &Project) -> miette::Result<()> {
)],
"the project is not configured for your current platform"
)
.with_source_code(project.source()));
.with_source_code(project.manifest_named_source()));
}

// Make sure the system requirements are met
Expand Down
2 changes: 1 addition & 1 deletion src/lock_file/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub async fn resolve_pypi_dependencies<'p>(
// Determine the compatible tags
let compatible_tags = project_platform_tags(
platform,
&project.manifest.system_requirements,
project.system_requirements(),
python_record.as_ref(),
);

Expand Down
Loading

0 comments on commit c211842

Please sign in to comment.