File size: 9,617 Bytes
2492322 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | // Copyright (c) 2019, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.
#ifndef MAMBA_CORE_CONTEXT_HPP
#define MAMBA_CORE_CONTEXT_HPP
#include <map>
#include <optional>
#include <string>
#include <vector>
#include "mamba/core/common_types.hpp"
#include "mamba/core/context_params.hpp"
#include "mamba/core/palette.hpp"
#include "mamba/core/subdir_parameters.hpp"
#include "mamba/core/tasksync.hpp"
#include "mamba/download/mirror_map.hpp"
#include "mamba/download/parameters.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/solver/libsolv/parameters.hpp"
#include "mamba/solver/request.hpp"
#include "mamba/specs/authentication_info.hpp"
#include "mamba/specs/platform.hpp"
#include "mamba/version.hpp"
#define ROOT_ENV_NAME "base"
namespace mamba
{
enum class VerificationLevel
{
Disabled,
Warn,
Enabled
};
struct ValidationParams
{
VerificationLevel safety_checks = VerificationLevel::Warn;
bool extra_safety_checks = false;
bool verify_artifacts = false;
// TODO Uncomment `conda-forge` or whatever trusted_channels when possible
// (i.e server side package signing ready)
// Remove "http://127.0.0.1:8000/get/channel0"
// (should only be used in integration tests,
// this one is for testing with quetz)
std::vector<std::string> trusted_channels = {
/*"conda-forge", */ "http://127.0.0.1:8000/get/channel0"
};
};
enum class ChannelPriority
{
Disabled,
Flexible,
Strict
};
class Logger;
class Context;
struct ContextOptions
{
bool enable_logging = false;
bool enable_signal_handling = false;
};
// Context singleton class
class Context
{
public:
static void use_default_signal_handler(bool val);
struct OutputParams
{
int verbosity{ 0 };
log_level logging_level{ log_level::warn };
bool json{ false };
bool quiet{ false };
std::string log_pattern{ "%^%-9!l%-8n%$ %v" };
std::size_t log_backtrace{ 0 };
};
struct GraphicsParams
{
bool no_progress_bars{ false };
Palette palette;
};
struct SrcParams
{
bool no_rc{ false };
bool no_env{ false };
};
// Configurable
bool experimental = false;
bool experimental_repodata_parsing = true;
bool experimental_matchspec_parsing = false;
bool debug = false;
bool use_uv = false;
// TODO check writable and add other potential dirs
std::vector<fs::u8path> envs_dirs;
std::vector<fs::u8path> pkgs_dirs;
std::optional<std::string> env_lockfile;
bool use_index_cache = false;
std::size_t local_repodata_ttl = 1; // take from header
bool offline = false;
ChannelPriority channel_priority = ChannelPriority::Flexible;
bool auto_activate_base = false;
bool extract_sparse = false;
bool dry_run = false;
bool download_only = false;
bool always_yes = false;
bool register_envs = true;
bool show_anaconda_channel_warnings = true;
// solver options
solver::Request::Flags solver_flags = {};
// add start menu shortcuts on Windows (not implemented on Linux / macOS)
bool shortcuts = true;
// debug helpers
bool keep_temp_files = false;
bool keep_temp_directories = false;
bool change_ps1 = true;
std::string env_prompt = "({default_env}) ";
bool ascii_only = false;
// micromamba only
bool shell_completion = true;
OutputParams output_params;
GraphicsParams graphics_params;
SrcParams src_params;
CommandParams command_params;
ThreadsParams threads_params;
PrefixParams prefix_params;
ValidationParams validation_params;
LinkParams link_params;
download::RemoteFetchParams remote_fetch_params = {
.ssl_verify = { "" },
.ssl_no_revoke = false,
.curl_initialized = false,
.user_agent = { "mamba/" LIBMAMBA_VERSION_STRING },
.connect_timeout_secs = 10.,
.retry_timeout = 2,
.retry_backoff = 3,
.max_retries = 3,
.proxy_servers = {},
};
download::Options download_options() const
{
return {
.download_threads = this->threads_params.download_threads,
.fail_fast = false,
.sort = true,
.verbose = this->output_params.verbosity >= 2,
};
}
SubdirParams subdir_params() const
{
const auto get_local_repodata_ttl = [&]() -> std::optional<std::size_t>
{
// Force the use of index cache by setting TTL to 0
if (this->use_index_cache)
{
return { 0 };
}
// This is legacy where from where 1 meant to read from header
if (this->local_repodata_ttl == 1)
{
return std::nullopt;
}
return { this->local_repodata_ttl };
};
return {
.local_repodata_ttl_s = get_local_repodata_ttl(),
.offline = this->offline,
.repodata_force_use_zst = false // Must override based on ChannelContext
};
}
SubdirDownloadParams subdir_download_params() const
{
return {
.offline = this->offline,
.repodata_check_zst = this->repodata_use_zst,
};
}
TransactionParams transaction_params() const
{
return {
.is_mamba_exe = command_params.is_mamba_exe,
.json_output = output_params.json,
.verbosity = output_params.verbosity,
.shortcuts = shortcuts,
.envs_dirs = envs_dirs,
.platform = platform,
.prefix_params = prefix_params,
.link_params = link_params,
.threads_params = threads_params,
};
}
std::size_t lock_timeout = 0;
bool use_lockfiles = true;
// Conda compat
bool add_pip_as_python_dependency = true;
std::string host_platform = std::string(specs::build_platform_name());
std::string platform = std::string(specs::build_platform_name());
std::vector<std::string> platforms() const;
std::vector<std::string> channels = { "conda-forge" };
std::map<std::string, std::string> custom_channels;
std::map<std::string, std::vector<std::string>> custom_multichannels;
std::vector<std::string> default_channels = {
#ifdef _WIN32
"https://repo.anaconda.com/pkgs/main",
"https://repo.anaconda.com/pkgs/r",
"https://repo.anaconda.com/pkgs/msys2"
#else
"https://repo.anaconda.com/pkgs/main",
"https://repo.anaconda.com/pkgs/r"
#endif
};
std::map<std::string, std::vector<std::string>> mirrored_channels;
std::string channel_alias = "https://conda.anaconda.org";
specs::AuthenticationDataBase& authentication_info();
const specs::AuthenticationDataBase& authentication_info() const;
std::vector<fs::u8path> token_locations{ "~/.continuum/anaconda-client/tokens" };
bool override_channels_enabled = true;
std::vector<std::string> pinned_packages = {};
bool use_only_tar_bz2 = false;
bool repodata_use_zst = true;
std::vector<std::string> repodata_has_zst = { "https://conda.anaconda.org/conda-forge" };
// FIXME: Should not be stored here
// Notice that we cannot build this map directly from mirrored_channels,
// since we need to add a single "mirror" for non mirrored channels
download::mirror_map mirrors;
Context(const Context&) = delete;
Context& operator=(const Context&) = delete;
Context(Context&&) = delete;
Context& operator=(Context&&) = delete;
void debug_print() const;
void dump_backtrace_no_guards();
void set_verbosity(int lvl);
void set_log_level(log_level level);
Context(const ContextOptions& options = {});
~Context();
private:
// Used internally
bool on_ci = false;
void load_authentication_info();
specs::AuthenticationDataBase m_authentication_info;
bool m_authentication_infos_loaded = false;
class ScopedLogger;
std::vector<ScopedLogger> loggers;
std::shared_ptr<Logger> main_logger();
void add_logger(std::shared_ptr<Logger>);
TaskSynchronizer tasksync;
// Enables the provided context setup signal handling.
// This function must be called only for one Context in the lifetime of the program.
void enable_signal_handling();
// Enables the provided context to drive the logging system.
// This function must be called only for one Context in the lifetime of the program.
void enable_logging();
};
} // namespace mamba
#endif // MAMBA_CONTEXT_HPP
|