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 21, 2024
1 parent 247f313 commit f1a902a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 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
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
16 changes: 15 additions & 1 deletion src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,21 @@ impl Project {
/// or any of the parent
pub fn load_or_else_discover(manifest_path: Option<&Path>) -> miette::Result<Self> {
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)
Expand Down

0 comments on commit f1a902a

Please sign in to comment.