Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change global config to kebab-case #1308

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions docs/advanced/global_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,41 @@ loaded in the following order:

## Reference

??? info "Casing In Configuration"
In versions of pixi `0.20.1` and older the global configuration used snake_case
we've changed to `kebab-case` for consistency with the rest of the configuration.
But we still support the old `snake_case` configuration, for older configuration options.
These are:

- `default_channels`
- `change_ps1`
- `tls_no_verify`
- `authentication_override_file`
- `mirrors` and sub-options
- `repodata-config` and sub-options

The following reference describes all available configuration options.

```toml
# The default channels to select when running `pixi init` or `pixi global install`.
# This defaults to only conda-forge.
default_channels = ["conda-forge"]
default-channels = ["conda-forge"]

# When set to false, the `(pixi)` prefix in the shell prompt is removed.
# This applies to the `pixi shell` subcommand.
# You can override this from the CLI with `--change-ps1`.
change_ps1 = true
change-ps1 = true

# When set to true, the TLS certificates are not verified. Note that this is a
# security risk and should only be used for testing purposes or internal networks.
# You can override this from the CLI with `--tls-no-verify`.
tls_no_verify = false
tls-no-verify = false

# Override from where the authentication information is loaded.
# Usually we try to use the keyring to load authentication data from, and only use a JSON
# file as fallback. This option allows you to force the use of a JSON file.
# Read more in the authentication section.
authentication_override_file = "/path/to/your/override.json"
authentication-override-file = "/path/to/your/override.json"

# configuration for conda channel-mirrors
[mirrors]
Expand All @@ -60,13 +73,13 @@ authentication_override_file = "/path/to/your/override.json"
"https://prefix.dev/bioconda",
]

[repodata_options]
[repodata-config]
# disable fetching of jlap, bz2 or zstd repodata files.
# This should only be used for specific old versions of artifactory and other non-compliant
# servers.
disable_jlap = true # don't try to download repodata.jlap
disable_bzip2 = true # don't try to download repodata.json.bz2
disable_zstd = true # don't try to download repodata.json.zst
disable-jlap = true # don't try to download repodata.jlap
disable-bzip2 = true # don't try to download repodata.json.bz2
disable-zstd = true # don't try to download repodata.json.zst
```

## Mirror configuration
Expand Down
62 changes: 62 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,50 @@ pub struct ConfigCliPrompt {
#[derive(Clone, Default, Debug, Deserialize)]
pub struct RepodataConfig {
/// Disable JLAP compression for repodata.
#[serde(alias = "disable-jlap")] // BREAK: rename instead of alias
pub disable_jlap: Option<bool>,
/// Disable bzip2 compression for repodata.
#[serde(alias = "disable-bzip2")] // BREAK: rename instead of alias
pub disable_bzip2: Option<bool>,
/// Disable zstd compression for repodata.
#[serde(alias = "disable-zstd")] // BREAK: rename instead of alias
pub disable_zstd: Option<bool>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct Config {
#[serde(default)]
#[serde(alias = "default-channels")] // BREAK: rename instead of alias
pub default_channels: Vec<String>,

/// If set to true, pixi will set the PS1 environment variable to a custom value.
#[serde(default)]
#[serde(alias = "change-ps1")] // BREAK: rename instead of alias
change_ps1: Option<bool>,

/// Path to the file containing the authentication token.
#[serde(default)]
#[serde(alias = "authentication-override-file")] // BREAK: rename instead of alias
authentication_override_file: Option<PathBuf>,

/// If set to true, pixi will not verify the TLS certificate of the server.
#[serde(default)]
#[serde(alias = "tls-no-verify")] // BREAK: rename instead of alias
tls_no_verify: Option<bool>,

#[serde(default)]
mirrors: HashMap<Url, Vec<Url>>,

#[serde(skip)]
#[serde(alias = "loaded-from")] // BREAK: rename instead of alias
pub loaded_from: Vec<PathBuf>,

#[serde(skip, default = "default_channel_config")]
#[serde(alias = "channel-config")] // BREAK: rename instead of alias
pub channel_config: ChannelConfig,

/// Configuration for repodata fetching.
#[serde(alias = "repodata-config")] // BREAK: rename instead of alias
pub repodata_config: Option<RepodataConfig>,
}

Expand Down Expand Up @@ -397,4 +407,56 @@ mod tests {
let debug = debug.replace(&d.to_str().unwrap().replace('\\', "/"), "path");
insta::assert_snapshot!(debug);
}

#[test]
fn test_parse_kebab_and_snake_case() {
let toml = r#"
default_channels = ["conda-forge"]
change_ps1 = true
tls_no_verify = false
authentication_override_file = "/path/to/your/override.json"
[mirrors]
"https://conda.anaconda.org/conda-forge" = [
"https://prefix.dev/conda-forge"
]
[repodata_config]
disable_jlap = true
disable_bzip2 = true
disable_zstd = true
"#;
let config = Config::from_toml(toml, &PathBuf::from("")).unwrap();
assert_eq!(config.default_channels, vec!["conda-forge"]);
assert_eq!(config.tls_no_verify, Some(false));
assert_eq!(
config.authentication_override_file,
Some(PathBuf::from("/path/to/your/override.json"))
);
assert_eq!(config.change_ps1, Some(true));
assert_eq!(
config
.mirrors
.get(&Url::parse("https://conda.anaconda.org/conda-forge").unwrap()),
Some(&vec![Url::parse("https://prefix.dev/conda-forge").unwrap()])
);
let repodata_config = config.repodata_config.unwrap();
assert_eq!(repodata_config.disable_jlap, Some(true));
assert_eq!(repodata_config.disable_bzip2, Some(true));
assert_eq!(repodata_config.disable_zstd, Some(true));
// See if the toml parses in kebab-case
let toml = r#"
default-channels = ["conda-forge"]
change-ps1 = true
tls-no-verify = false
authentication-override-file = "/path/to/your/override.json"
[mirrors]
"https://conda.anaconda.org/conda-forge" = [
"https://prefix.dev/conda-forge"
]
[repodata-config]
disable-jlap = true
disable-bzip2 = true
disable-zstd = true
"#;
Config::from_toml(toml, &PathBuf::from("")).unwrap();
}
}
Loading