From f1a902a46f6edaceaffd88dca0cbda95af3b5aa3 Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Mon, 16 Dec 2024 08:32:25 -0600 Subject: [PATCH] feat: support --manifest-path to project directory Allow `pixi --manifest-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: https://github.com/prefix-dev/pixi/issues/2706 --- src/cli/cli_config.rs | 2 +- src/cli/completion.rs | 2 +- ...i__completion__tests__nushell_completion.snap | 2 +- src/project/mod.rs | 16 +++++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cli/cli_config.rs b/src/cli/cli_config.rs index a6fbd84bd..398f49c65 100644 --- a/src/cli/cli_config.rs +++ b/src/cli/cli_config.rs @@ -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, } diff --git a/src/cli/completion.rs b/src/cli/completion.rs index 806ed7e5d..5b6491e5b 100644 --- a/src/cli/completion.rs +++ b/src/cli/completion.rs @@ -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 diff --git a/src/cli/snapshots/pixi__cli__completion__tests__nushell_completion.snap b/src/cli/snapshots/pixi__cli__completion__tests__nushell_completion.snap index 8117489f6..1fe39f137 100644 --- a/src/cli/snapshots/pixi__cli__completion__tests__nushell_completion.snap +++ b/src/cli/snapshots/pixi__cli__completion__tests__nushell_completion.snap @@ -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 diff --git a/src/project/mod.rs b/src/project/mod.rs index ad95c5244..f9c48668b 100644 --- a/src/project/mod.rs +++ b/src/project/mod.rs @@ -242,7 +242,21 @@ impl Project { /// or any of the parent pub fn load_or_else_discover(manifest_path: Option<&Path>) -> miette::Result { let project = match manifest_path { - Some(path) => Project::from_path(path)?, + Some(path) => { + let path = if path.is_dir() { + &find_project_manifest(path).ok_or_else(|| { + miette::miette!( + "could not find {} or {} at directory {}", + consts::PROJECT_MANIFEST, + consts::PYPROJECT_MANIFEST, + path.to_string_lossy() + ) + })? + } else { + path + }; + Project::from_path(path)? + } None => Project::discover()?, }; Ok(project)