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

feat: use named environments (only "default" for now) #674

Merged
merged 4 commits into from
Jan 17, 2024
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
8 changes: 7 additions & 1 deletion src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let spec_platforms = &args.platform;

// Sanity check of prefix location
verify_prefix_location_unchanged(project.pixi_dir().join(consts::PREFIX_FILE_NAME).as_path())?;
verify_prefix_location_unchanged(
project
.default_environment()
.dir()
.join(consts::PREFIX_FILE_NAME)
.as_path(),
)?;

// Add the platform if it is not already present
let platforms_to_add = spec_platforms
Expand Down
2 changes: 1 addition & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub const PROJECT_MANIFEST: &str = "pixi.toml";
pub const PROJECT_LOCK_FILE: &str = "pixi.lock";
pub const PIXI_DIR: &str = ".pixi";
pub const PREFIX_FILE_NAME: &str = "prefix";
pub const ENVIRONMENT_DIR: &str = "env";
pub const ENVIRONMENTS_DIR: &str = "envs";
pub const PYPI_DEPENDENCIES: &str = "pypi-dependencies";

pub const DEFAULT_ENVIRONMENT_NAME: &str = "default";
32 changes: 21 additions & 11 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
consts, default_authenticated_client, install, install_pypi, lock_file, prefix::Prefix,
progress, Project,
};
use miette::{Context, IntoDiagnostic};
use miette::IntoDiagnostic;

use crate::lock_file::lock_file_satisfies_project;
use crate::project::virtual_packages::verify_current_platform_has_required_virtual_packages;
Expand Down Expand Up @@ -58,11 +58,28 @@ fn create_prefix_location_file(prefix_file: &Path) -> miette::Result<()> {
/// 2. It verifies that the system requirements are met.
pub fn sanity_check_project(project: &Project) -> miette::Result<()> {
// Sanity check of prefix location
verify_prefix_location_unchanged(project.pixi_dir().join(consts::PREFIX_FILE_NAME).as_path())?;
verify_prefix_location_unchanged(
project
.default_environment()
.dir()
.join(consts::PREFIX_FILE_NAME)
.as_path(),
)?;

// Make sure the system requirements are met
verify_current_platform_has_required_virtual_packages(&project.default_environment())?;

// TODO: remove on a 1.0 release
// Check for old `env` folder as we moved to `envs` in 0.13.0
let old_pixi_env_dir = project.pixi_dir().join("env");
if old_pixi_env_dir.exists() {
tracing::warn!(
"The `{}` folder is deprecated, please remove it as we now use the `{}` folder",
old_pixi_env_dir.display(),
consts::ENVIRONMENTS_DIR
);
}

Ok(())
}

Expand Down Expand Up @@ -122,7 +139,7 @@ pub async fn get_up_to_date_prefix(
sanity_check_project(project)?;

// Start loading the installed packages in the background
let prefix = Prefix::new(project.environment_dir())?;
let prefix = Prefix::new(project.default_environment().dir())?;
let installed_packages_future = {
let prefix = prefix.clone();
tokio::spawn(async move { prefix.find_installed_packages(None).await })
Expand Down Expand Up @@ -277,14 +294,7 @@ pub async fn update_prefix_conda(
}

// Mark the location of the prefix
create_prefix_location_file(
&prefix
.root()
.parent()
.map(|p| p.join(consts::PREFIX_FILE_NAME))
.ok_or_else(|| miette::miette!("we should be able to create a prefix file name."))?,
)
.with_context(|| "failed to create prefix location file.".to_string())?;
create_prefix_location_file(&prefix.root().join(consts::PREFIX_FILE_NAME))?;

// Determine if the python version changed.
Ok(PythonStatus::from_transaction(&transaction))
Expand Down
7 changes: 7 additions & 0 deletions src/project/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ impl<'p> Environment<'p> {
self.environment
}

/// Returns the directory where this environment is stored.
pub fn dir(&self) -> std::path::PathBuf {
self.project
.environments_dir()
.join(self.environment.name.as_str())
}

/// Returns references to the features that make up this environment. The default feature is
/// always added at the end.
pub fn features(&self) -> impl Iterator<Item = &'p Feature> + DoubleEndedIterator + '_ {
Expand Down
4 changes: 2 additions & 2 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ impl Project {
}

/// Returns the environment directory
pub fn environment_dir(&self) -> PathBuf {
self.pixi_dir().join(consts::ENVIRONMENT_DIR)
pub fn environments_dir(&self) -> PathBuf {
self.pixi_dir().join(consts::ENVIRONMENTS_DIR)
}

/// Returns the path to the manifest file.
Expand Down
Loading