Skip to content

Commit

Permalink
fix: Reorder manifest discovery logic (#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian authored Nov 26, 2024
1 parent 67f3830 commit f77b02f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 58 deletions.
2 changes: 2 additions & 0 deletions docs/features/advanced_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ This setting can also be set from the command line with `pixi run --clean-env TA
On Windows it's hard to create a "clean environment" as `conda-forge` doesn't ship Windows compilers and Windows needs a lot of base variables.
Making this feature not worthy of implementing as the amount of edge cases will make it unusable.



## Our task runner: deno_task_shell

To support the different OS's (Windows, OSX and Linux), pixi integrates a shell that can run on all of them.
Expand Down
6 changes: 3 additions & 3 deletions docs/features/global_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ The manifest can be found at the following locations depending on your operating

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 1 | `$HOME/.pixi/manifests/pixi-global.toml` | User-specific manifest |
| 2 | `$PIXI_HOME/manifests/pixi-global.toml` | Global manifest in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 1 | `$HOME/.pixi/manifests/pixi-global.toml` | User-specific manifest |

=== "macOS"

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 1 | `$HOME/.pixi/manifests/pixi-global.toml` | User-specific manifest |
| 2 | `$PIXI_HOME/manifests/pixi-global.toml` | Global manifest in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 1 | `$HOME/.pixi/manifests/pixi-global.toml` | User-specific manifest |

=== "Windows"

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| 1 | `%USERPROFILE%\.pixi\manifests\pixi-global.toml` | User-specific manifest |
| 2 | `$PIXI_HOME\manifests/pixi-global.toml` | Global manifest in the user home directory. `PIXI_HOME` defaults to `%USERPROFILE%/.pixi` |
| 1 | `%USERPROFILE%\.pixi\manifests\pixi-global.toml` | User-specific manifest |

!!! note
If multiple locations exist, the manifest with the highest priority will be used.
Expand Down
28 changes: 14 additions & 14 deletions docs/reference/pixi_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ The configuration is loaded in the following order:

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 1 | `/etc/pixi/config.toml` | System-wide configuration |
| 2 | `$XDG_CONFIG_HOME/pixi/config.toml` | XDG compliant user-specific configuration |
| 3 | `$HOME/.config/pixi/config.toml` | User-specific configuration |
| 4 | `$PIXI_HOME/config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 5 | `your_project/.pixi/config.toml` | Project-specific configuration |
| 6 | Command line arguments (`--tls-no-verify`, `--change-ps1=false`, etc.) | Configuration via command line arguments |
| 5 | `your_project/.pixi/config.toml` | Project-specific configuration |
| 4 | `$PIXI_HOME/config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 3 | `$HOME/.config/pixi/config.toml` | User-specific configuration |
| 2 | `$XDG_CONFIG_HOME/pixi/config.toml` | XDG compliant user-specific configuration |
| 1 | `/etc/pixi/config.toml` | System-wide configuration |

=== "macOS"

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 1 | `/etc/pixi/config.toml` | System-wide configuration |
| 2 | `$XDG_CONFIG_HOME/pixi/config.toml` | XDG compliant user-specific configuration |
| 3 | `$HOME/Library/Application Support/pixi/config.toml` | User-specific configuration |
| 4 | `$PIXI_HOME/config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 5 | `your_project/.pixi/config.toml` | Project-specific configuration |
| 6 | Command line arguments (`--tls-no-verify`, `--change-ps1=false`, etc.) | Configuration via command line arguments |
| 5 | `your_project/.pixi/config.toml` | Project-specific configuration |
| 4 | `$PIXI_HOME/config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `~/.pixi` |
| 3 | `$HOME/Library/Application Support/pixi/config.toml` | User-specific configuration |
| 2 | `$XDG_CONFIG_HOME/pixi/config.toml` | XDG compliant user-specific configuration |
| 1 | `/etc/pixi/config.toml` | System-wide configuration |

=== "Windows"

| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| 1 | `C:\ProgramData\pixi\config.toml` | System-wide configuration |
| 2 | `%APPDATA%\pixi\config.toml` | User-specific configuration |
| 3 | `$PIXI_HOME\config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `%USERPROFILE%/.pixi` |
| 4 | `your_project\.pixi\config.toml` | Project-specific configuration |
| 5 | Command line arguments (`--tls-no-verify`, `--change-ps1=false`, etc.) | Configuration via command line arguments |
| 4 | `your_project\.pixi\config.toml` | Project-specific configuration |
| 3 | `$PIXI_HOME\config.toml` | Global configuration in the user home directory. `PIXI_HOME` defaults to `%USERPROFILE%/.pixi` |
| 2 | `%APPDATA%\pixi\config.toml` | User-specific configuration |
| 1 | `C:\ProgramData\pixi\config.toml` | System-wide configuration |

!!! note
The highest priority wins. If a configuration file is found in a higher priority location, the values from the configuration read from lower priority locations are overwritten.
Expand Down
26 changes: 22 additions & 4 deletions docs/reference/project_configuration.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
---
part: pixi
title: Configuration
description: Learn what you can do in the pixi.toml configuration.
title: Manifest
description: Learn what you can do in the pixi manifest.
---

The `pixi.toml` is the pixi project configuration file, also known as the project manifest.
The `pixi.toml` is the project manifest, also known as the pixi project configuration file.

A `toml` file is structured in different tables.
This document will explain the usage of the different tables.
For more technical documentation check pixi on [crates.io](https://docs.rs/pixi/latest/pixi/project/manifest/struct.ProjectManifest.html).
For more technical documentation check pixi on [docs.rs](https://docs.rs/pixi/latest/pixi/project/manifest/struct.ProjectManifest.html).

!!! tip
We also support the `pyproject.toml` file. It has the same structure as the `pixi.toml` file. except that you need to prepend the tables with `tool.pixi` instead of just the table name.
For example, the `[project]` table becomes `[tool.pixi.project]`.
There are also some small extras that are available in the `pyproject.toml` file, checkout the [pyproject.toml](../advanced/pyproject_toml.md) documentation for more information.

## Manifest discovery

The manifest can be found at the following locations depending on your operating system.


| **Priority** | **Location** | **Comments** |
|--------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 6 | `--manifest-path` | Command-line argument |
| 5 | `pixi.toml` | In your current working directory. |
| 4 | `pyproject.toml` | In your current working directory. |
| 3 | `pixi.toml` or `pyproject.toml` | Iterate through all parent directories. The first discovered manifest is used. |
| 1 | `$PIXI_PROJECT_MANIFEST` | If `$PIXI_IN_SHELL` is set. This happens with `pixi shell` or `pixi run`. |


!!! note
If multiple locations exist, the manifest with the highest priority will be used.


## The `project` table

The minimally required information in the `project` table is:
Expand Down
33 changes: 16 additions & 17 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,30 @@ impl Project {
pub(crate) fn discover() -> miette::Result<Self> {
let project_toml = find_project_manifest(std::env::current_dir().into_diagnostic()?);

if std::env::var("PIXI_IN_SHELL").is_ok() {
if let Ok(env_manifest_path) = std::env::var("PIXI_PROJECT_MANIFEST") {
if let Some(project_toml) = project_toml {
if let Some(project_toml) = project_toml {
if std::env::var("PIXI_IN_SHELL").is_ok() {
if let Ok(env_manifest_path) = std::env::var("PIXI_PROJECT_MANIFEST") {
if env_manifest_path != project_toml.to_string_lossy() {
tracing::warn!(
"Using manifest {} from `PIXI_PROJECT_MANIFEST` rather than local {}",
"Using local manifest {} rather than {} from environment variable `PIXI_PROJECT_MANIFEST`",
project_toml.to_string_lossy(),
env_manifest_path,
project_toml.to_string_lossy()
);
}
}
return Self::from_path(Path::new(env_manifest_path.as_str()));
}
return Self::from_path(&project_toml);
}

let project_toml = match project_toml {
Some(file) => file,
None => miette::bail!(
"could not find {} or {} which is configured to use pixi",
consts::PROJECT_MANIFEST,
consts::PYPROJECT_MANIFEST
),
};
if let Ok(env_manifest_path) = std::env::var("PIXI_PROJECT_MANIFEST") {
return Self::from_path(Path::new(env_manifest_path.as_str()));
}

Self::from_path(&project_toml)
miette::bail!(
"could not find {} or {} which is configured to use pixi",
consts::PROJECT_MANIFEST,
consts::PYPROJECT_MANIFEST
);
}

/// Loads a project from manifest file.
Expand Down Expand Up @@ -253,9 +252,9 @@ impl Project {
if let (Some(discover_path), Ok(env_path)) = (discover_path, env_path) {
if env_path.as_str() != discover_path.to_str().unwrap() {
tracing::warn!(
"Used manifest {} from `PIXI_PROJECT_MANIFEST` rather than local {}",
"Used local manifest {} rather than {} from environment variable `PIXI_PROJECT_MANIFEST`",
discover_path.to_string_lossy(),
env_path,
discover_path.to_string_lossy()
);
}
}
Expand Down
16 changes: 7 additions & 9 deletions tests/integration_python/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ def verify_cli_command(
stderr_contains: str | list[str] | None = None,
stderr_excludes: str | list[str] | None = None,
env: dict[str, str] | None = None,
cwd: str | Path | None = None,
reset_env: bool = False,
) -> Output:
# Setup the environment type safe.
base_env = dict(os.environ)
if env is not None:
complete_env = base_env | env
else:
complete_env = base_env
# Avoid to have miette splitting up lines
complete_env = complete_env | {"NO_GRAPHICS": "1"}
base_env = {} if reset_env else dict(os.environ)
complete_env = base_env if env is None else base_env | env
# Set `NO_GRAPHICS` to avoid to have miette splitting up lines
complete_env |= {"NO_GRAPHICS": "1"}

process = subprocess.run(command, capture_output=True, text=True, env=complete_env)
process = subprocess.run(command, capture_output=True, text=True, env=complete_env, cwd=cwd)
stdout, stderr, returncode = process.stdout, process.stderr, process.returncode
output = Output(command, stdout, stderr, returncode)
print(f"command: {command}, stdout: {stdout}, stderr: {stderr}, code: {returncode}")
Expand Down
Loading

0 comments on commit f77b02f

Please sign in to comment.