激活脚本#

配方允许拥有激活脚本,这些脚本将在环境激活时被 sourcing 或调用。通常建议在可能的情况下避免使用激活脚本,因为人们并不总是以预期的方式激活环境,这些软件包可能会因此行为异常。

在配方中使用它们时,可以随意在配方中将它们命名为 activate.bat、activate.sh、deactivate.bat 和 deactivate.sh。建议已安装的脚本以软件包名称和分隔符 - 为前缀。

以下是一些适用于 Unix 和 Windows 的示例代码,这将使安装过程更容易。

build.sh

# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d.
# This will allow them to be run on environment activation.
for CHANGE in "activate" "deactivate"
do
    mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d"
    cp "${RECIPE_DIR}/${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}_${CHANGE}.sh"
done

build.bat

setlocal EnableDelayedExpansion

:: Copy the [de]activate scripts to %PREFIX%\etc\conda\[de]activate.d.
:: This will allow them to be run on environment activation.
for %%F in (activate deactivate) DO (
    if not exist %PREFIX%\etc\conda\%%F.d mkdir %PREFIX%\etc\conda\%%F.d
    copy %RECIPE_DIR%\%%F.bat %PREFIX%\etc\conda\%%F.d\%PKG_NAME%_%%F.bat
    :: Copy unix shell activation scripts, needed by Windows Bash users
    copy %RECIPE_DIR%\%%F.sh %PREFIX%\etc\conda\%%F.d\%PKG_NAME%_%%F.sh
)