diff --git a/crates/pixi_core/src/workspace/discovery.rs b/crates/pixi_core/src/workspace/discovery.rs index e3c1c399ab..f84affa44e 100644 --- a/crates/pixi_core/src/workspace/discovery.rs +++ b/crates/pixi_core/src/workspace/discovery.rs @@ -151,6 +151,7 @@ impl WorkspaceLocator { /// Called to locate the workspace or error out if none could be located. pub fn locate(self) -> Result { // Determine the search root + let explicit_start = matches!(&self.start, DiscoveryStart::ExplicitManifest(_)); let discovery_start = match self.start { DiscoveryStart::ExplicitManifest(path) => { pixi_manifest::DiscoveryStart::ExplicitManifest(path) @@ -191,7 +192,7 @@ impl WorkspaceLocator { }; // Take into consideration any environment variables that may be set. - if self.consider_environment { + if self.consider_environment && !explicit_start { if let Some(WithWarnings { value: manifests, warnings: mut env_warnings, diff --git a/tests/integration_python/test_manifest_path.py b/tests/integration_python/test_manifest_path.py new file mode 100644 index 0000000000..27926d8e1d --- /dev/null +++ b/tests/integration_python/test_manifest_path.py @@ -0,0 +1,33 @@ +import json +from pathlib import Path + +from .common import EMPTY_BOILERPLATE_PROJECT, verify_cli_command + + +def test_explicit_manifest_correct_location(pixi: Path, tmp_path: Path) -> None: + current_dir = tmp_path / "current" + target_dir = tmp_path / "target" + current_dir.mkdir() + target_dir.mkdir() + + (current_dir / "pixi.toml").write_text(EMPTY_BOILERPLATE_PROJECT) + (target_dir / "pixi.toml").write_text(EMPTY_BOILERPLATE_PROJECT) + + out = verify_cli_command( + [ + pixi, + "shell-hook", + "--manifest-path", + target_dir, + "--json", + ], + cwd=current_dir, + ) + + payload = json.loads(out.stdout) + value = payload["environment_variables"].get("PIXI_PROJECT_MANIFEST") + assert value is not None, "PIXI_PROJECT_MANIFEST missing from activated env" + + expected = (target_dir / "pixi.toml").resolve() + actual = Path(value).resolve() + assert actual == expected