Skip to content

Commit

Permalink
feat: support --manifest-path to project directory
Browse files Browse the repository at this point in the history
Allow `pixi --manifest-path <path>` to accept a path to a project
directory. This makes it easier to use pixi when scripting as the script
does not need to know if a project is using pixi.toml or pyproject.toml.

Implements: prefix-dev#2706
  • Loading branch information
blmaier committed Dec 16, 2024
1 parent cb5c837 commit 526f05c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cli/cli_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::path::PathBuf;
/// Project configuration
#[derive(Parser, Debug, Default, Clone)]
pub struct ProjectConfig {
/// The path to `pixi.toml` or `pyproject.toml`
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[arg(long, global = true)]
pub manifest_path: Option<PathBuf>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ _arguments "${_arguments_options[@]}" \
# Runs task in project
export extern "pixi run" [
...task: string # The pixi task or a task shell command you want to run in the project's environment, which can be an executable in the environment's PATH
--manifest-path: string # The path to `pixi.toml` or `pyproject.toml`
--manifest-path: string # The path to `pixi.toml`, `pyproject.toml`, or the project directory
--frozen # Install the environment as defined in the lockfile, doesn't update lockfile if it isn't up-to-date with the manifest file
--locked # Check if lockfile is up-to-date before installing the environment, aborts when lockfile isn't up-to-date with the manifest file
--environment(-e): string # The environment to run the task in
Expand Down
2 changes: 1 addition & 1 deletion src/cli/project/description/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
/// Commands to manage project description.
#[derive(Parser, Debug)]
pub struct Args {
/// The path to `pixi.toml` or `pyproject.toml`
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[clap(long, global = true)]
pub manifest_path: Option<PathBuf>,

Expand Down
2 changes: 1 addition & 1 deletion src/cli/project/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
/// Commands to manage project environments.
#[derive(Parser, Debug)]
pub struct Args {
/// The path to `pixi.toml` or `pyproject.toml`
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[clap(long, global = true)]
pub manifest_path: Option<PathBuf>,

Expand Down
2 changes: 1 addition & 1 deletion src/cli/project/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
/// Commands to manage project platforms.
#[derive(Parser, Debug)]
pub struct Args {
/// The path to `pixi.toml` or `pyproject.toml`
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[clap(long, global = true)]
pub manifest_path: Option<PathBuf>,

Expand Down
2 changes: 1 addition & 1 deletion src/cli/project/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::PathBuf;
/// Commands to manage project version.
#[derive(Parser, Debug)]
pub struct Args {
/// The path to `pixi.toml` or `pyproject.toml`
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[clap(long, global = true)]
pub manifest_path: Option<PathBuf>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ expression: result
# Runs task in project
export extern "pixi run" [
...task: string@"nu-complete pixi run" # The pixi task or a task shell command you want to run in the project's environment, which can be an executable in the environment's PATH
--manifest-path: string # The path to `pixi.toml` or `pyproject.toml`
--manifest-path: string # The path to `pixi.toml`, `pyproject.toml`, or the project directory
--frozen # Install the environment as defined in the lockfile, doesn't update lockfile if it isn't up-to-date with the manifest file
--locked # Check if lockfile is up-to-date before installing the environment, aborts when lockfile isn't up-to-date with the manifest file
--environment(-e): string@"nu-complete pixi run environment" # The environment to run the task in
Expand Down
17 changes: 15 additions & 2 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,22 @@ impl Project {
}

/// Loads a project from manifest file.
pub fn from_path(manifest_path: &Path) -> miette::Result<Self> {
pub fn from_path(manifest_path: impl AsRef<Path>) -> miette::Result<Self> {
let manifest_path = manifest_path.as_ref();
let manifest_path = if manifest_path.is_dir() {
find_project_manifest(manifest_path).ok_or_else(|| {
miette::miette!(
"could not find {} or {} at directory {}",
consts::PROJECT_MANIFEST,
consts::PYPROJECT_MANIFEST,
manifest_path.to_string_lossy()
)
})?
} else {
manifest_path.to_path_buf()
};
let manifest = Manifest::from_path(manifest_path)?;
Ok(Project::from_manifest(manifest))
Ok(Self::from_manifest(manifest))
}

/// Loads a project manifest file or discovers it in the current directory
Expand Down

0 comments on commit 526f05c

Please sign in to comment.