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

Rename env functions #2954

Merged
merged 5 commits into from
Oct 31, 2023
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
2 changes: 1 addition & 1 deletion libmamba/include/mamba/api/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ namespace mamba
{
for (const auto& env_var : m_env_var_names)
{
auto env_var_value = util::getenv(env_var);
auto env_var_value = util::get_env(env_var);
if (env_var_value)
{
try
Expand Down
6 changes: 3 additions & 3 deletions libmamba/include/mamba/util/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace mamba::util
{
auto getenv(const std::string& key) -> std::optional<std::string>;
void setenv(const std::string& key, const std::string& value);
void unsetenv(const std::string& key);
auto get_env(const std::string& key) -> std::optional<std::string>;
void set_env(const std::string& key, const std::string& value);
void unset_env(const std::string& key);
}
#endif
24 changes: 12 additions & 12 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace mamba

for (const auto& env_var : m_env_var_names)
{
if (util::getenv(env_var))
if (util::get_env(env_var))
{
return true;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace mamba
{
for (const auto& ev : p_impl->m_env_var_names)
{
util::unsetenv(ev);
util::unset_env(ev);
}
}
return std::move(*this);
Expand Down Expand Up @@ -402,7 +402,7 @@ namespace mamba
// strip $
var = var.substr(1);
}
auto val = util::getenv(var);
auto val = util::get_env(var);
if (val)
{
s.replace(match[0].first, match[0].second, val.value());
Expand Down Expand Up @@ -591,7 +591,7 @@ namespace mamba
bool use_fallback = config.at("use_target_prefix_fallback").value<bool>();
if (use_fallback)
{
prefix = std::getenv("CONDA_PREFIX") ? std::getenv("CONDA_PREFIX") : "";
prefix = util::get_env("CONDA_PREFIX").value_or("");
}
}

Expand All @@ -617,9 +617,9 @@ namespace mamba

if (prefix.empty())
{
if (util::getenv("MAMBA_DEFAULT_ROOT_PREFIX"))
if (util::get_env("MAMBA_DEFAULT_ROOT_PREFIX"))
{
prefix = util::getenv("MAMBA_DEFAULT_ROOT_PREFIX").value();
prefix = util::get_env("MAMBA_DEFAULT_ROOT_PREFIX").value();
LOG_WARNING << unindent(R"(
'MAMBA_DEFAULT_ROOT_PREFIX' is meant for testing purpose.
Consider using 'MAMBA_ROOT_PREFIX' instead)");
Expand Down Expand Up @@ -870,7 +870,7 @@ namespace mamba
std::vector<fs::u8path> paths = { context.prefix_params.root_prefix / "pkgs",
env::home_directory() / ".mamba" / "pkgs" };
#ifdef _WIN32
auto appdata = util::getenv("APPDATA");
auto appdata = util::get_env("APPDATA");
if (appdata)
{
paths.push_back(fs::u8path(appdata.value()) / ".mamba" / "pkgs");
Expand Down Expand Up @@ -936,7 +936,7 @@ namespace mamba
{
if (!config.at("root_prefix").configured() || force)
{
util::setenv("MAMBA_ROOT_PREFIX", get_conda_root_prefix().string());
util::set_env("MAMBA_ROOT_PREFIX", get_conda_root_prefix().string());
}
}

Expand Down Expand Up @@ -1852,9 +1852,9 @@ namespace mamba
env::home_directory() / ".conda/condarc.d",
env::home_directory() / ".condarc",
};
if (util::getenv("CONDARC"))
if (util::get_env("CONDARC"))
{
conda_user.push_back(fs::u8path(util::getenv("CONDARC").value()));
conda_user.push_back(fs::u8path(util::get_env("CONDARC").value()));
}

std::vector<fs::u8path> mamba_user = {
Expand All @@ -1863,9 +1863,9 @@ namespace mamba
env::home_directory() / ".mamba/mambarc", env::home_directory() / ".mamba/mambarc.d",
env::home_directory() / ".mambarc",
};
if (util::getenv("MAMBARC"))
if (util::get_env("MAMBARC"))
{
mamba_user.push_back(fs::u8path(util::getenv("MAMBARC").value()));
mamba_user.push_back(fs::u8path(util::get_env("MAMBARC").value()));
}

std::vector<fs::u8path> prefix = { context.prefix_params.target_prefix / ".condarc",
Expand Down
3 changes: 1 addition & 2 deletions libmamba/src/api/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ namespace mamba
location = "-";
}

if (std::getenv("CONDA_PREFIX")
&& (std::getenv("CONDA_PREFIX") == ctx.prefix_params.target_prefix))
if (auto prefix = util::get_env("CONDA_PREFIX"); prefix == ctx.prefix_params.target_prefix)
{
name += " (active)";
}
Expand Down
6 changes: 3 additions & 3 deletions libmamba/src/core/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ namespace mamba
}

// if we are in a `mamba shell -n <env>` we don't want to activate base
auto has_prefix = util::getenv("CONDA_PREFIX");
auto has_prefix = util::get_env("CONDA_PREFIX");
if (m_context.auto_activate_base && !has_prefix.has_value())
{
builder << "micromamba activate base\n";
Expand Down Expand Up @@ -786,7 +786,7 @@ namespace mamba
// use.
return { "", "" };
}
auto current_prompt_modifier = util::getenv("CONDA_PROMPT_MODIFIER");
auto current_prompt_modifier = util::get_env("CONDA_PROMPT_MODIFIER");
if (current_prompt_modifier)
{
util::replace_all(ps1, current_prompt_modifier.value(), "");
Expand Down Expand Up @@ -899,7 +899,7 @@ namespace mamba
CshActivator::update_prompt(const std::string& conda_prompt_modifier)
{
std::string prompt = (m_env.find("prompt") != m_env.end()) ? m_env["prompt"] : "";
auto current_prompt_modifier = util::getenv("CONDA_PROMPT_MODIFIER");
auto current_prompt_modifier = util::get_env("CONDA_PROMPT_MODIFIER");
if (current_prompt_modifier)
{
util::replace_all(prompt, current_prompt_modifier.value(), "");
Expand Down
10 changes: 5 additions & 5 deletions libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ namespace mamba

Context::Context(const ContextOptions& options)
{
on_ci = static_cast<bool>(util::getenv("CI"));
prefix_params.root_prefix = util::getenv("MAMBA_ROOT_PREFIX").value_or("");
on_ci = static_cast<bool>(util::get_env("CI"));
prefix_params.root_prefix = util::get_env("MAMBA_ROOT_PREFIX").value_or("");
prefix_params.conda_prefix = prefix_params.root_prefix;

envs_dirs = { prefix_params.root_prefix / "envs" };
pkgs_dirs = { prefix_params.root_prefix / "pkgs",
fs::u8path("~") / ".mamba" / "pkgs"
#ifdef _WIN32
,
fs::u8path(util::getenv("APPDATA").value_or("")) / ".mamba" / "pkgs"
fs::u8path(util::get_env("APPDATA").value_or("")) / ".mamba" / "pkgs"
#endif
};

keep_temp_files = util::getenv("MAMBA_KEEP_TEMP") ? true : false;
keep_temp_directories = util::getenv("MAMBA_KEEP_TEMP_DIRS") ? true : false;
keep_temp_files = util::get_env("MAMBA_KEEP_TEMP") ? true : false;
keep_temp_directories = util::get_env("MAMBA_KEEP_TEMP_DIRS") ? true : false;

set_persist_temporary_files(keep_temp_files);
set_persist_temporary_directories(keep_temp_directories);
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace mamba
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);

// if NETRC is exported in ENV, we forward it to curl
std::string netrc_file = util::getenv("NETRC").value_or("");
std::string netrc_file = util::get_env("NETRC").value_or("");
if (netrc_file != "")
{
curl_easy_setopt(handle, CURLOPT_NETRC_FILE, netrc_file.c_str());
Expand Down
20 changes: 10 additions & 10 deletions libmamba/src/core/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "mamba/core/util.hpp"
#include "mamba/core/util_scope.hpp"
#include "mamba/util/build.hpp"
#include "mamba/util/environment.hpp"
#include "mamba/util/iterator.hpp"
#include "mamba/util/string.hpp"
#include "mamba/util/url.hpp"
Expand Down Expand Up @@ -60,11 +61,13 @@ namespace mamba
}
#endif

if (!remote_fetch_params.ssl_verify.size()
&& std::getenv("REQUESTS_CA_BUNDLE") != nullptr)
if (!remote_fetch_params.ssl_verify.size())
{
remote_fetch_params.ssl_verify = std::getenv("REQUESTS_CA_BUNDLE");
LOG_INFO << "Using REQUESTS_CA_BUNDLE " << remote_fetch_params.ssl_verify;
if (auto ca = util::get_env("REQUESTS_CA_BUNDLE"); ca.has_value())
{
remote_fetch_params.ssl_verify = ca.value();
LOG_INFO << "Using REQUESTS_CA_BUNDLE " << remote_fetch_params.ssl_verify;
}
}
else if (remote_fetch_params.ssl_verify == "<system>" && util::on_linux)
{
Expand Down Expand Up @@ -101,14 +104,11 @@ namespace mamba
{
// TODO: we should probably store set_low_speed_limit and set_ssl_no_revoke in
// RemoteFetchParams if the request is slower than 30b/s for 60 seconds, cancel.
const std::string no_low_speed_limit = std::getenv("MAMBA_NO_LOW_SPEED_LIMIT")
? std::getenv("MAMBA_NO_LOW_SPEED_LIMIT")
: "0";
const std::string no_low_speed_limit = util::get_env("MAMBA_NO_LOW_SPEED_LIMIT")
.value_or("0");
const bool set_low_speed_opt = (no_low_speed_limit == "0");

const std::string ssl_no_revoke_env = std::getenv("MAMBA_SSL_NO_REVOKE")
? std::getenv("MAMBA_SSL_NO_REVOKE")
: "0";
const std::string ssl_no_revoke_env = util::get_env("MAMBA_SSL_NO_REVOKE").value_or("0");
const bool set_ssl_no_revoke = context.remote_fetch_params.ssl_no_revoke
|| (ssl_no_revoke_env != "0");

Expand Down
16 changes: 8 additions & 8 deletions libmamba/src/core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace mamba::env
fs::u8path which(const std::string& exe, const std::string& override_path)
{
// TODO maybe add a cache?
auto env_path = override_path == "" ? util::getenv("PATH") : override_path;
auto env_path = override_path == "" ? util::get_env("PATH") : override_path;
if (env_path)
{
std::string path = env_path.value();
Expand Down Expand Up @@ -156,12 +156,12 @@ namespace mamba::env
fs::u8path home_directory()
{
#ifdef _WIN32
std::string maybe_home = util::getenv("USERPROFILE").value_or("");
std::string maybe_home = util::get_env("USERPROFILE").value_or("");
if (maybe_home.empty())
{
maybe_home = util::concat(
util::getenv("HOMEDRIVE").value_or(""),
util::getenv("HOMEPATH").value_or("")
util::get_env("HOMEDRIVE").value_or(""),
util::get_env("HOMEPATH").value_or("")
);
}
if (maybe_home.empty())
Expand All @@ -171,7 +171,7 @@ namespace mamba::env
);
}
#else
std::string maybe_home = util::getenv("HOME").value_or("");
std::string maybe_home = util::get_env("HOME").value_or("");
if (maybe_home.empty())
{
maybe_home = getpwuid(getuid())->pw_dir;
Expand All @@ -186,7 +186,7 @@ namespace mamba::env

fs::u8path user_config_dir()
{
std::string maybe_user_config_dir = util::getenv("XDG_CONFIG_HOME").value_or("");
std::string maybe_user_config_dir = util::get_env("XDG_CONFIG_HOME").value_or("");
if (maybe_user_config_dir.empty())
{
#ifdef _WIN32
Expand All @@ -202,7 +202,7 @@ namespace mamba::env

fs::u8path user_data_dir()
{
std::string maybe_user_data_dir = util::getenv("XDG_DATA_HOME").value_or("");
std::string maybe_user_data_dir = util::get_env("XDG_DATA_HOME").value_or("");
if (maybe_user_data_dir.empty())
{
#ifdef _WIN32
Expand All @@ -218,7 +218,7 @@ namespace mamba::env

fs::u8path user_cache_dir()
{
std::string maybe_user_cache_dir = util::getenv("XDG_CACHE_HOME").value_or("");
std::string maybe_user_cache_dir = util::get_env("XDG_CACHE_HOME").value_or("");
if (maybe_user_cache_dir.empty())
{
#ifdef _WIN32
Expand Down
6 changes: 3 additions & 3 deletions libmamba/src/core/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace mamba
if (util::on_win)
{
ensure_comspec_set();
auto comspec = util::getenv("COMSPEC");
auto comspec = util::get_env("COMSPEC");
if (!comspec)
{
LOG_ERROR << "Failed to run " << action << " for " << pkg_info.name
Expand Down Expand Up @@ -417,7 +417,7 @@ namespace mamba
envmap["PKG_VERSION"] = pkg_info.version;
envmap["PKG_BUILDNUM"] = std::to_string(pkg_info.build_number);

std::string PATH = util::getenv("PATH").value_or("");
std::string PATH = util::get_env("PATH").value_or("");
envmap["PATH"] = util::concat(path.parent_path().string(), env::pathsep(), PATH);

std::string cargs = util::join(" ", command_args);
Expand Down Expand Up @@ -457,7 +457,7 @@ namespace mamba
if (ec)
{
LOG_ERROR << "response code: " << status << " error message: " << ec.message();
if (script_file != nullptr && util::getenv("CONDA_TEST_SAVE_TEMPS"))
if (script_file != nullptr && util::get_env("CONDA_TEST_SAVE_TEMPS"))
{
LOG_ERROR << "CONDA_TEST_SAVE_TEMPS :: retaining run_script" << script_file->path();
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace mamba
}
else
{
auto val = util::getenv(e);
auto val = util::get_env(e);
if (val)
{
env_map[e] = val.value();
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace mamba
std::map<std::string, std::string> envmap;
auto& ctx = context();
envmap["MAMBA_EXTRACT_THREADS"] = std::to_string(ctx.threads_params.extract_threads);
auto qemu_ld_prefix = util::getenv("QEMU_LD_PREFIX");
auto qemu_ld_prefix = util::get_env("QEMU_LD_PREFIX");
if (qemu_ld_prefix)
{
envmap["QEMU_LD_PREFIX"] = qemu_ld_prefix.value();
Expand Down
16 changes: 8 additions & 8 deletions libmamba/src/core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,14 +1299,14 @@ namespace mamba

bool ensure_comspec_set()
{
std::string cmd_exe = util::getenv("COMSPEC").value_or("");
std::string cmd_exe = util::get_env("COMSPEC").value_or("");
if (!util::ends_with(util::to_lower(cmd_exe), "cmd.exe"))
{
cmd_exe = (fs::u8path(util::getenv("SystemRoot").value_or("")) / "System32" / "cmd.exe")
cmd_exe = (fs::u8path(util::get_env("SystemRoot").value_or("")) / "System32" / "cmd.exe")
.string();
if (!fs::is_regular_file(cmd_exe))
{
cmd_exe = (fs::u8path(util::getenv("windir").value_or("")) / "System32" / "cmd.exe")
cmd_exe = (fs::u8path(util::get_env("windir").value_or("")) / "System32" / "cmd.exe")
.string();
}
if (!fs::is_regular_file(cmd_exe))
Expand All @@ -1316,7 +1316,7 @@ namespace mamba
}
else
{
util::setenv("COMSPEC", cmd_exe);
util::set_env("COMSPEC", cmd_exe);
}
}
return true;
Expand Down Expand Up @@ -1381,7 +1381,7 @@ namespace mamba
}
else
{
conda_bat = util::getenv("CONDA_BAT")
conda_bat = util::get_env("CONDA_BAT")
.value_or((fs::absolute(root_prefix) / "condabin" / bat_name).string());
}
if (!fs::exists(conda_bat) && options.is_micromamba)
Expand Down Expand Up @@ -1454,9 +1454,9 @@ namespace mamba
}
else
{
if (std::getenv("CONDA_EXE"))
if (auto exe = util::get_env("CONDA_EXE"))
{
shebang = std::getenv("CONDA_EXE");
shebang = exe.value();
}
else
{
Expand Down Expand Up @@ -1520,7 +1520,7 @@ namespace mamba
if (util::on_win)
{
ensure_comspec_set();
auto comspec = util::getenv("COMSPEC");
auto comspec = util::get_env("COMSPEC");
if (!comspec)
{
throw std::runtime_error(
Expand Down
Loading