Skip to content

Commit

Permalink
fix: config search order
Browse files Browse the repository at this point in the history
This fixes three problems:
- the config order was wrong, global config was for some cases winning over local
- move config file of tmp_pixi_workspace to correct folder
- add a config reset for all tests so that our test run with a clean config
  • Loading branch information
Hofer-Julian committed Dec 12, 2024
1 parent b6d8407 commit 87f420c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
18 changes: 10 additions & 8 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl RepodataConfig {

/// Merge the given RepodataConfig into the current one.
/// `other` is mutable to allow for moving the values out of it.
/// The given config will have higher priority
pub fn merge(&self, mut other: Self) -> Self {
let mut per_channel: HashMap<_, _> = self
.per_channel
Expand Down Expand Up @@ -909,10 +910,11 @@ impl Config {
}

/// Merge the given config into the current one.
/// The given config will have higher priority
#[must_use]
pub fn merge_config(mut self, other: Config) -> Self {
self.mirrors.extend(other.mirrors);
self.loaded_from.extend(other.loaded_from);
pub fn merge_config(self, mut other: Config) -> Self {
other.mirrors.extend(self.mirrors);
other.loaded_from.extend(self.loaded_from);

Self {
default_channels: if other.default_channels.is_empty() {
Expand All @@ -925,16 +927,16 @@ impl Config {
authentication_override_file: other
.authentication_override_file
.or(self.authentication_override_file),
mirrors: self.mirrors,
loaded_from: self.loaded_from,
mirrors: other.mirrors,
loaded_from: other.loaded_from,
// currently this is always the default so just use the other value
channel_config: other.channel_config,
repodata_config: other.repodata_config.merge(self.repodata_config),
pypi_config: other.pypi_config.merge(self.pypi_config),
repodata_config: self.repodata_config.merge(other.repodata_config),
pypi_config: self.pypi_config.merge(other.pypi_config),
detached_environments: other.detached_environments.or(self.detached_environments),
pinning_strategy: other.pinning_strategy.or(self.pinning_strategy),
force_activate: other.force_activate,
experimental: other.experimental.merge(self.experimental),
experimental: self.experimental.merge(other.experimental),
// Make other take precedence over self to allow for setting the value through the CLI
concurrency: self.concurrency.merge(other.concurrency),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/pixi_config/src/lib.rs
expression: debug
snapshot_kind: text
---
Config {
default_channels: [
Expand All @@ -25,8 +24,8 @@ Config {
mirrors: {},
pinning_strategy: None,
loaded_from: [
"path/config_1.toml",
"path/config_2.toml",
"path/config_1.toml",
],
channel_config: ChannelConfig {
channel_alias: Url {
Expand Down
18 changes: 17 additions & 1 deletion tests/integration_python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ def pixi(request: pytest.FixtureRequest) -> Path:
@pytest.fixture
def tmp_pixi_workspace(tmp_path: Path) -> Path:
pixi_config = """
# Reset to defaults
default-channels = ["conda-forge"]
change-ps1 = true
tls-no-verify = false
detached-environments = false
pinning-strategy = "semver"
[concurrency]
downloads = 50
[experimental]
use-environment-activation-cache = false
# Enable sharded repodata
[repodata-config."https://prefix.dev/"]
disable-sharded = false
"""
tmp_path.joinpath("config.toml").write_text(pixi_config)
dot_pixi = tmp_path.joinpath(".pixi")
dot_pixi.mkdir()
dot_pixi.joinpath("config.toml").write_text(pixi_config)
return tmp_path


Expand Down

0 comments on commit 87f420c

Please sign in to comment.