conda 在没有 .condarc 的情况下从哪里获取默认配置值?

Where does conda get the default configuration values without a `.condarc`?

我去寻找一些 conda 设置。 (如果你一定要知道,这与搞乱我的 bash$PS1 有关 - 决定是使用 conda 的配置还是环境变量。)为了找到设置,指令是查看 .condarc。要查找 .condarc,我被指示使用 conda config --show-sources。我这样做了,结果是:

(base) [bballdave025@MYMACHINE ~]$ conda config --show-sources

(base) [bballdave025@MYMACHINE ~]$

即它是空白的。浏览 some conda documentation(以及它建议浏览的路径)也没有产生任何 .condarc。我在其他地方进行了自己的搜索,但仍然一无所获。 没关系 - 我可以没有 .condarc(而且我知道我可以创建一个,通过 touch $HOME/.condarc 或通过 conda config --set changeps1 False - 或任何 conda config --set <param-name> <value>).

但是,当我查看配置参数(设置或默认值)时,我 肯定 看到了一些值。用于查看这些值的一些命令是 conda infoconda config --showconda config --describe。在我提出我的主要问题后,我将提供这些命令的详细信息。

这个问题几乎可以肯定是学术性的,但我不知道这让我发疯:这些价值观来自世界何处?它们必须来自 某处。我想它是某种文件,无论是本地的还是在线的,无论是基于文本的还是纯二进制的。我没有运气找到来源;显然,它不在任何 .condarc 中,但它也不在我搜索过的其他任何地方。 conda 从哪里提取这些值?

此 post 的其余部分包含情况的详细信息以及我试图找到答案的尝试。真正的基础都在post以上这一点。另一条快速说明:由于它们可能会有用,因此有关我的系统和 conda info 的信息位于此 post.

的最后

显示情况的命令

这里有一些命令可以显示缺少 .condarc 和显示 parameters/settings.

的默认值

重复,

(base) [bballdave025@MYMACHINE ~]$ conda config --show-sources

returns 没什么 - 可能是一个空字符串,但我认为没什么。

.condarc 文件的其他搜索表明,in-conda 设置不可能来自名称如 "*condarc*" 的任何文件。您可以查看 查找 "*condarc*" 文件 部分了解详细信息。

以下是我查看设置的方式。

(base) [bballdave025@MYMACHINE ~]$ conda config --show | head
add_anaconda_token: True
add_pip_as_python_dependency: True
aggressive_update_packages:
  - ca-certificates
  - certifi
  - openssl
allow_conda_downgrades: False
allow_cycles: True
allow_non_channel_urls: False
allow_softlinks: False

(base) [bballdave025@MYMACHINE ~]$ conda config --show | grep -i -C2 ps1
auto_update_conda: True
bld_path:
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: flexible

其他命令似乎证实了这一点:

(base) [bballdave025@MYMACHINE ~]$ conda info -a > tmpf && head -n 6 tmpf && rm tmpf

     active environment : base
    active env location : /home/bballdave025/anaconda3
            shell level : 1
       user config file : /home/bballdave025/.condarc
 populated config files :
(base) [bballdave025@MYMACHINE ~]$ conda config --describe | awk '/changeps1/' RS=  # Note the blank at the end
# # changeps1 (bool)
# #   When using activate, change the command prompt ($PS1) to include the
# #   activated environment.
# #
# changeps1: true

(base) [bballdave025@MYMACHINE ~]$ conda config --describe | awk '/env_prompt/' RS=  # Note the blank at the end
# # env_prompt (str)
# #   Template for prompt modification based on the active environment.
# #   Currently supported template variables are '{prefix}', '{name}', and
# #   '{default_env}'. '{prefix}' is the absolute path to the active
# #   environment. '{name}' is the basename of the active environment
# #   prefix. '{default_env}' holds the value of '{name}' if the active
# #   environment is a conda named environment ('-n' flag), or otherwise
# #   holds the value of '{prefix}'. Templating uses python's str.format()
# #   method.
# #
# env_prompt: '({default_env}) '

正在查找`"*condarc*"` 文件

长输入,准备 copy/paste。您可能只想前往输出部分。

find $HOME -type f -iname "*condarc*" -print0 | \
  xargs -I'{}' -0 \
    bash -c \
'orig="{}"; fname="${orig}"; '\
'dashes="----------------------------------"; '\
'echo "${dashes}"; echo "For file: '"'"'${fname}'"'"'"; '\
'echo "-----"; '\
'if ! grep -q "root_dir" "${fname}"; then '\
'  echo "   No '"'"'root_dir'"'"' in file; "'\
'"most likely invalid as a settings \`condarc\`"; '\
'  if grep -q proxy <(echo "${fname}"); then '\
'    echo "    There is a '"'"'proxy'"'"' in the filename, "'\
'"so it is not a huge surprise."; '\
'  fi; '\
'else '\
'  echo "   '"'"'root_dir'"'"' in file; "'\
'"could possibly be valid as a settings \`condarc\`"; '\
'fi; '\
'if grep -q changeps1 "${fname}" ; then '\
'  echo " From the file:"; '\
'  grep_str=$(grep changeps1 "${fname}"); '\
'  echo "${grep_str}"; '\
'  echo " From \`conda config --show | grep changeps1\`"; '\
'  condaconf_str=$(conda config --show | grep changeps1); '\
'  echo "${condaconf_str}"; '\
'    if [ "${grep_str}" = "${condaconf_str}" ]; then '\
'      echo "   The strings are equivalent, therefore the "'\
'"settings are equivalent."; '\
'      echo "   The in-conda settings could have come "'\
'"from this file."; '\
'    else '\
'      echo "   The strings - and therefore the settings - are "'\
'"not equivalent."; '\
'      echo "   The in-conda settings could not have come "'\
'"from this file."; '\
'      if grep -q test <(echo "${fname}"); then '\
'        echo "    There is a '"'"'test'"'"' in the file path, "'\
'"so it is not a huge surprise."; '\
'      fi; '\
'    fi; '\
'else '\
'  echo "   No '"'"'changeps1'"'"' found in file."; '\
'  echo "   The in-conda settings could not have come "'\
'"from this file."; '\
'fi; '\
'echo "${dashes}"; echo;';

显示没有 condarc 文件的长输出可能已用于当前的 conda 设置。

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/condarc'
-----
   'root_dir' in file; could possibly be valid as a settings `condarc`
 From the file:
changeps1: False
 From `conda config --show | grep changeps1`
changeps1: True
   The strings - and therefore the settings - are not equivalent.
   The in-conda settings could not have come from this file.
    There is a 'test' in the file path, so it is not a huge surprise.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxybad'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.11.0-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxygood'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxybad'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/integration/proxy/condarc.proxygood'
-----
   No 'root_dir' in file; most likely invalid as a settings `condarc`
    There is a 'proxy' in the filename, so it is not a huge surprise.
   No 'changeps1' found in file.
   The in-conda settings could not have come from this file.
----------------------------------

----------------------------------
For file: '/home/bballdave025/anaconda3/pkgs/conda-4.10.3-py39h06a4308_0/info/test/tests/condarc'
-----
   'root_dir' in file; could possibly be valid as a settings `condarc`
 From the file:
changeps1: False
 From `conda config --show | grep changeps1`
changeps1: True
   The strings - and therefore the settings - are not equivalent.
   The in-conda settings could not have come from this file.
    There is a 'test' in the file path, so it is not a huge surprise.
----------------------------------

我正在 运行 进行系统范围的搜索(即来自 /,除了排除像 /dev/ 这样的东西,这可能会搞砸这样的搜索) .基本上,除了 find $HOME 将更改为 sudo find / 并在末尾添加 2>/dev/null 之外,一切都将相同。我还将 运行 系统范围 grep changeps1。我怀疑我会找到任何东西,但值得一试。我将对我发现的内容进行编辑。

编辑:答案在我需要完成其中任何一个搜索之前就出现了。


系统信息和 Conda 信息

这是我的系统信息:

     (base) [bballdave025@MYMACHINE ~]$ uname -a
     Linux MYMACHINE 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 8 21:51:17 EST 
     2021 x86_64 x86_64 x86_64 GNU/Linux

所以,我 运行宁 RHEL 8 - Red Hat。

这是我的 conda 信息:

(base) [bballdave025@MYMACHINE ~]$ conda info

     active environment : base
    active env location : /home/bballdave025/anaconda3
            shell level : 1
       user config file : /home/bballdave025/.condarc
 populated config files :
          conda version : 4.11.0
    conda-build version : 3.21.5
         python version : 3.9.7.final.0
       virtual packages : __linux=4.18.0=0
                          __glibc=2.28=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/bballdave025/anaconda3  (writable)
      conda av data dir : /home/bballdave025/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/bballdave025/anaconda3/pkgs
                          /home/bballdave025/.conda/pkgs
       envs directories : /home/bballdave025/anaconda3/envs
                          /home/bballdave025/.conda/envs
               platform : linux-64
             user-agent : conda/4.11.0 requests/2.26.0 CPython/3.9.7 Linux/4.18.0-348.7.1.el8_5.x86_64 rhel/8.5 glibc/2.28
                UID:GID : 1001:1001
             netrc file : None
           offline mode : False

如果没有 .condarc 个来源,Conda 会回退到 hardcoded in the conda.base.context.Context class 个值。这是一个相关的片段:

class Context(Configuration):

    add_pip_as_python_dependency = ParameterLoader(PrimitiveParameter(True))
    allow_conda_downgrades = ParameterLoader(PrimitiveParameter(False))
    # allow cyclical dependencies, or raise
    allow_cycles = ParameterLoader(PrimitiveParameter(True))
    allow_softlinks = ParameterLoader(PrimitiveParameter(False))
    auto_update_conda = ParameterLoader(PrimitiveParameter(True), aliases=('self_update',))
    auto_activate_base = ParameterLoader(PrimitiveParameter(True))
    auto_stack = ParameterLoader(PrimitiveParameter(0))
    notify_outdated_conda = ParameterLoader(PrimitiveParameter(True))
    clobber = ParameterLoader(PrimitiveParameter(False))
    changeps1 = ParameterLoader(PrimitiveParameter(True))
    env_prompt = ParameterLoader(PrimitiveParameter("({default_env}) "))
    # ...