context#

Conda's global configuration object.

The context aggregates all configuration files, environment variables, and command line arguments into one global stateful object to be used across all of conda.

Classes#

Functions#

user_data_dir(→ conda.common.path.PathType)

mockable_context_envs_dirs(...)

channel_alias_validation(→ str | Literal[True])

default_python_default(→ str)

default_python_validation(→ str | Literal[True])

list_fields_validation(→ str | Literal[True])

ssl_verify_validation(→ str | Literal[True])

reset_context(→ Context)

fresh_context(→ collections.abc.Iterator[Context])

stack_context(→ None)

stack_context_default(→ None)

replace_context(→ None)

replace_context_default(→ None)

env_name(→ conda.common.path.PathType | str | None)

locate_prefix_by_name(→ conda.common.path.PathType)

Find the location of a prefix given a conda env name. If the location does not exist, an

validate_channels(→ tuple[str, ...])

Validate if the given channel URLs are allowed based on the context's allowlist

determine_target_prefix(→ conda.common.path.PathType)

Get the prefix to operate in. The prefix may not yet exist.

Attributes#

_platform_map#
non_x86_machines#
_arch_names#
_win_sysconfig_map#
user_rc_path: conda.common.path.PathType = b'.'#
sys_rc_path: conda.common.path.PathType#
user_data_dir(appname: str | None = None, appauthor: str | None | Literal[False] = None, version: str | None = None, roaming: bool = False) → conda.common.path.PathType#
mockable_context_envs_dirs(root_writable: bool, root_prefix: conda.common.path.PathType, _envs_dirs: conda.common.path.PathsType) → tuple[conda.common.path.PathType, ...]#
channel_alias_validation(value: str) → str | Literal[True]#
default_python_default() → str#
default_python_validation(value: str) → str | Literal[True]#
list_fields_validation(value: collections.abc.Iterable[str]) → str | Literal[True]#
ssl_verify_validation(value: str) → str | Literal[True]#
class Context(search_path: conda.common.path.PathsType | None = None, argparse_args: argparse.Namespace | None = None, **kwargs)#

Bases: conda.common.configuration.Configuration

add_pip_as_python_dependency#
allow_conda_downgrades#
allow_cycles#
auto_update_conda#
auto_activate#
_default_activation_env#
auto_stack#
notify_outdated_conda#
clobber#
changeps1#
env_prompt#
environment_specifier#
_create_default_packages#
register_envs#
protect_frozen_envs#
default_python#
download_only#
enable_private_envs#
force_32bit#
non_admin_enabled#
prefix_data_interoperability#
_default_threads#
_repodata_threads#
_fetch_threads#
_verify_threads#
_execute_threads#
_aggressive_update_packages#
safety_checks#
extra_safety_checks#
_signing_metadata_url_base#
path_conflict#
pinned_packages#
exclude_newer#
exclude_newer_package#
disallowed_packages#
rollback_enabled#
track_features#
use_index_cache#
separate_format_cache#
_root_prefix#
_envs_dirs#
_pkgs_dirs#
_subdir#
_subdirs#
_export_platforms#
local_repodata_ttl#
ssl_verify#
client_ssl_cert#
client_ssl_cert_key#
proxy_servers#
remote_connect_timeout_secs#
remote_read_timeout_secs#
remote_max_retries#
remote_backoff_factor#
add_anaconda_token#
allow_non_channel_urls#
_channel_alias#
channel_priority#
_channels#
channel_settings#
_custom_channels#
_custom_multichannels#
_default_channels#
_migrated_channel_aliases#
migrated_custom_channels#
override_channels_enabled#
show_channel_urls#
use_local#
allowlist_channels#
denylist_channels#
repodata_fns#
_use_only_tar_bz2#
always_copy#
always_yes#
_debug#
_trace#
_dev#
dry_run#
_error_upload_url#
force#
json#
_console#
list_fields#
offline#
quiet#
ignore_pinned#
_report_errors#
shortcuts#
number_channel_notices#
shortcuts_only#
_verbosity#
_experimental#
preview#
no_lock#
repodata_use_zst#
repodata_use_shards#
envvars_force_uppercase#
deps_modifier#
update_modifier#
sat_solver#
solver_ignore_timestamps#
solver#
force_remove#
force_reinstall#
target_prefix_override#
unsatisfiable_hints#
unsatisfiable_hints_check_depth#
bld_path#
anaconda_upload#
_croot#
_conda_build#
_override_virtual_packages#
no_plugins#
post_build_validation() → list[conda.common.configuration.ValidationError]#
property plugin_manager: conda.plugins.manager.CondaPluginManager#

This is the preferred way of accessing the PluginManager object for this application and is located here to avoid problems with cyclical imports elsewhere in the code.

property plugins: conda.plugins.config.PluginConfig#

Preferred way of accessing settings introduced by the settings plugin hook

property exclude_newer_policy: conda.core.exclude_newer.ExcludeNewerPolicy#

Resolved policy for excluding newly indexed package records.

property dev: bool#
property experimental: str#
property error_upload_url: str#
property report_errors: str#
property conda_build_local_paths: tuple[conda.common.path.PathType, ...]#
property conda_build_local_urls: tuple[str, ...]#
property croot: conda.common.path.PathType#

This is where source caches and work folders live

property local_build_root: conda.common.path.PathType#
property conda_build: dict[str, Any]#
property arch_name: str#
property platform: str#
property default_threads: int | None#
property repodata_threads: int | None#
property fetch_threads: int | None#

If both are not overriden (0), return experimentally-determined value of 5

property verify_threads: int | None#
property execute_threads: int | None#
property subdir: str#
_native_subdir() → str#
property subdirs: tuple[str, str]#
known_subdirs() → frozenset[str]#
property export_platforms: tuple[str, ...]#
property bits: int#
root_writable() → bool#
property envs_dirs: tuple[conda.common.path.PathType, ...]#
property pkgs_dirs: tuple[conda.common.path.PathType, ...]#
trash_dir() → conda.common.path.PathType#
property default_prefix: conda.common.path.PathType#
property active_prefix: conda.common.path.PathType#
property shlvl: int#
property aggressive_update_packages: tuple[conda.models.match_spec.MatchSpec, ...]#
property target_prefix: conda.common.path.PathType#
root_prefix() → conda.common.path.PathType#
property conda_prefix: conda.common.path.PathType#
property av_data_dir: conda.common.path.PathType#

Where critical artifact verification data (e.g., various public keys) can be found.

property signing_metadata_url_base: str | None#

Base URL for artifact verification signing metadata (*.root.json, key_mgr.json).

property conda_exe_vars_dict: dict[str, str | None]#

The vars can refer to each other if necessary since the dict is ordered. None means unset it.

channel_alias() → conda.models.channel.Channel#
property migrated_channel_aliases: tuple[conda.models.channel.Channel, ...]#
property prefix_specified: bool#
default_channels() → list[conda.models.channel.Channel]#
custom_multichannels() → dict[str, tuple[conda.models.channel.Channel, ...]]#
custom_channels() → dict[str, conda.models.channel.Channel]#
property channels: tuple[str, ...]#
property config_files: tuple[conda.common.path.PathType, ...]#
property use_only_tar_bz2: bool#
property binstar_upload: bool | None#
property trace: bool#

Alias for context.verbosity >=4.

property debug: bool#

Alias for context.verbosity >=3.

property info: bool#

Alias for context.verbosity >=2.

property verbose: bool#

Alias for context.verbosity >=1.

property verbosity: int#

Verbosity level.

For cleaner and readable code it is preferable to use the following alias properties:

context.trace context.debug context.info context.verbose context.log_level

property log_level: int#

Map context.verbosity to logging level.

preview_enabled(value: str) → bool#

Return True if the given preview feature label is enabled by the user.

property override_virtual_packages: dict[str, str | None]#

Remove any dunders in the virtual_package name keys

solver_user_agent() → str#
user_agent() → str#
_override(key: str, value: Any) → collections.abc.Iterator[None]#

Temporarily override an attribute on the context.

Uses __dict__ directly because ParameterLoader (and other non-data descriptors used by the context) have no __set__: a plain setattr would shadow the descriptor permanently in __dict__ and reset_context() could not restore it.

Caches derived from context values (memoizedproperty results and the registered reset callbacks, such as the Channel.from_value cache) are invalidated on entry and again on exit, so that values computed before the override do not mask it and values computed during it do not outlive it.

requests_version() → str#
python_implementation_name_version() → tuple[str, str]#
platform_system_release() → tuple[str, str]#
os_distribution_name_version() → tuple[str, str]#
libc_family_version() → tuple[str | None, str | None]#
property console: str#
property default_activation_env: str#
property create_default_packages: tuple[str, ...]#

Returns a list of create_default_packages, removing any explicit packages.

property default_activation_prefix: pathlib.Path#

Return the prefix of the default_activation_env.

If the default_activation_env is an environment name, get the corresponding prefix; otherwise it is already a prefix, so just return it.

Returns:

Prefix of the default_activation_env

property environment_context_keys: list[str]#
property environment_settings: dict[str, Any]#

Returns a dict of environment related settings

category_map: ClassVar[dict[str, tuple[str, ...]]]#
get_descriptions() → dict[str, str]#
description_map() → dict[str, str]#
reset_context(search_path: conda.common.path.PathsType = SEARCH_PATH, argparse_args: argparse.Namespace | None = None) → Context#
fresh_context(env: dict[str, str] | None = None, search_path: conda.common.path.PathsType = SEARCH_PATH, argparse_args: argparse.Namespace | None = None, **kwargs) → collections.abc.Iterator[Context]#
class ContextStackObject(search_path: conda.common.path.PathsType = SEARCH_PATH, argparse_args: argparse.Namespace | None = None)#
set_value(search_path: conda.common.path.PathsType = SEARCH_PATH, argparse_args: argparse.Namespace | None = None) → None#
apply()#
class ContextStack#
_stack#
_stack_idx = 0#
_last_search_path = None#
_last_argparse_args = None#
push(search_path: conda.common.path.PathsType, argparse_args: argparse.Namespace | None) → None#
apply()#
pop()#
replace(search_path: conda.common.path.PathsType, argparse_args: argparse.Namespace | None) → None#
context_stack#
stack_context(pushing: bool, search_path: conda.common.path.PathsType = SEARCH_PATH, argparse_args: argparse.Namespace | None = None) → None#
stack_context_default(pushing: bool, argparse_args: argparse.Namespace | None = None) → None#
replace_context(pushing: bool | None = None, search_path: collections.abc.Iterable[str] = SEARCH_PATH, argparse_args: argparse.Namespace | None = None) → None#
replace_context_default(pushing: bool | None = None, argparse_args: argparse.Namespace | None = None) → None#
conda_tests_ctxt_mgmt_def_pol#
env_name(prefix: conda.common.path.PathType) → conda.common.path.PathType | str | None#
locate_prefix_by_name(name: str, envs_dirs: conda.common.path.PathsType | None = None) → conda.common.path.PathType#

Find the location of a prefix given a conda env name. If the location does not exist, an error is raised.

validate_channels(channels: collections.abc.Iterator[str]) → tuple[str, ...]#

Validate if the given channel URLs are allowed based on the context's allowlist and denylist configurations.

Parameters:

channels -- A list of channels (either URLs or names) to validate.

Raises:
determine_target_prefix(ctx: Context, args: argparse.Namespace | None = None) → conda.common.path.PathType#

Get the prefix to operate in. The prefix may not yet exist.

Parameters:
  • ctx -- the context of conda

  • args -- the argparse args from the command line

Returns:

Path to the target environment prefix.

Raises:

CondaEnvironmentNotFoundError -- If the prefix is invalid.

context#