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

Mamba 2.0 name fixes #3225

Merged
merged 16 commits into from
Mar 14, 2024
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
6 changes: 3 additions & 3 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ find_package(Python3 COMPONENTS Interpreter)

set(
SHELL_SCRIPTS
micromamba.sh
micromamba.csh
micromamba.bat
mamba.sh
mamba.csh
mamba.bat
activate.bat
_mamba_activate.bat
mamba_hook.bat
Expand Down
13 changes: 7 additions & 6 deletions libmamba/data/Mamba.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (-not $MambaModuleArgs.ContainsKey('ChangePs1')) {
function Enter-MambaEnvironment {
begin {
$activateCommand = (& $Env:MAMBA_EXE shell activate -s powershell $Args | Out-String);
Write-Verbose "[micromamba shell activate --shell powershell $Args]`n$activateCommand";
Write-Verbose "[mamba shell activate --shell powershell $Args]`n$activateCommand";
Invoke-Expression -Command $activateCommand;
}

Expand Down Expand Up @@ -58,7 +58,7 @@ function Exit-MambaEnvironment {
if ($deactivateCommand.Trim().Length -eq 0) {
return;
}
Write-Verbose "[micromamba shell deactivate --shell powershell]`n$deactivateCommand";
Write-Verbose "[mamba shell deactivate --shell powershell]`n$deactivateCommand";
Invoke-Expression -Command $deactivateCommand;
}
process {}
Expand Down Expand Up @@ -117,7 +117,7 @@ function Invoke-Mamba() {
{
$activateCommand = (& $Env:MAMBA_EXE shell reactivate -s powershell | Out-String);
if ($activateCommand) {
Write-Verbose "[micromamba shell reactivate --shell powershell]`n$activateCommand";
Write-Verbose "[mamba shell reactivate --shell powershell]`n$activateCommand";
Invoke-Expression -Command $activateCommand;
}
}
Expand All @@ -128,7 +128,7 @@ function Invoke-Mamba() {

## TAB COMPLETION ##############################################################

$MicromambaAutocompleteScriptblock = {
$MambaAutocompleteScriptblock = {
param($wordToComplete, $commandAst, $cursorPosition)
$RemainingArgs = $commandAst.ToString().Split()
$OneRemainingArgs = $RemainingArgs[1..$RemainingArgs.Length]
Expand Down Expand Up @@ -171,8 +171,9 @@ if ($MambaModuleArgs.ChangePs1) {

## ALIASES #####################################################################

New-Alias micromamba Invoke-Mamba -Force
Register-ArgumentCompleter -Native -CommandName micromamba -ScriptBlock $MicromambaAutocompleteScriptblock
$__mamba_name = [System.IO.Path]::GetFileNameWithoutExtension((Split-Path -Leaf $Env:MAMBA_EXE));
New-Alias -Name $__mamba_name -Value Invoke-Mamba -Force
Register-ArgumentCompleter -Native -CommandName $__mamba_name -ScriptBlock $MambaAutocompleteScriptblock

## EXPORTS ###################################################################

Expand Down
2 changes: 1 addition & 1 deletion libmamba/data/_mamba_activate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@REM This is the standard user case. This script is run in root\condabin.
@REM FOR %%A IN ("%~dp0.") DO @SET _sysp=%%~dpA
@REM IF NOT EXIST "!_sysp!\Scripts\micromamba.exe" @SET "_sysp=!_sysp!..\"
@REM IF NOT EXIST "!_sysp!\Scripts\mamba.exe" @SET "_sysp=!_sysp!..\"

@FOR %%A in ("%TMP%") do @SET TMP=%%~sA
@REM It seems that it is not possible to have "CONDA_EXE=Something With Spaces"
Expand Down
13 changes: 12 additions & 1 deletion libmamba/data/activate.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
@REM Copyright (C) 2021 QuantStack
@REM SPDX-License-Identifier: BSD-3-Clause

@CALL "%~dp0..\condabin\mamba_hook.bat"
micromamba activate %*

@REM Replaced by mamba executable with the MAMBA_EXE variable pointing to the correct location.
__MAMBA_INSERT_MAMBA_EXE__

@REM We need to know the name of the executable, either mamba or micromamba
@REM Get the base filename of MAMBA_EXE
@FOR %%A in ("%MAMBA_EXE%") do set "__mamba_filename=%%~nxA"
@REM Remove .exe extension from the filename
@SET "__mamba_name=!__mamba_filename:%~x1=!"

!__mamba_name! activate %*
2 changes: 2 additions & 0 deletions libmamba/data/micromamba.bat → libmamba/data/mamba.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@REM Copyright (C) 2012 Anaconda, Inc
@REM SPDX-License-Identifier: BSD-3-Clause

@REM Replaced by mamba executable with the MAMBA_EXE and MAMBA_ROOT_PREFIX variable pointing
@REM to the correct locations.
__MAMBA_INSERT_MAMBA_EXE__
__MAMBA_INSERT_ROOT_PREFIX__

Expand Down
12 changes: 11 additions & 1 deletion libmamba/data/micromamba.csh → libmamba/data/mamba.csh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ alias __mamba_xctivate '\\
__mamba_hashr\\
'

alias micromamba '\\
alias __mamba_wrap '\\
switch ("${1}")\\
case activate | reactivate | deactivate:\\
__mamba_xctivate "\!*"\\
Expand All @@ -41,6 +41,16 @@ alias micromamba '\\
endsw\\
'

set __exe_name=(`basename $MAMBA_EXE`)
set __exe_name = (${__exe_name}:q.)
if ("$__exe_name" == "micromamba") then
alias mamba __mamba_wrap
else if ("$__exe_name" == "mamba") then
alias micromamba __mamba_wrap
else
echo "Error unknow MAMBA_EXE: \"$MAMBA_EXE\", filename must be mamba or micromamba" >&2
endif

if (! $?CONDA_SHLVL) then
setenv CONDA_SHLVL 0
# In dev-mode MAMBA_EXE is python.exe and on Windows
Expand Down
37 changes: 22 additions & 15 deletions libmamba/data/micromamba.sh → libmamba/data/mamba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause

__mamba_exe() (
"$MAMBA_EXE" "${@}"
"${MAMBA_EXE}" "${@}"
)

__mamba_hashr() {
Expand All @@ -16,13 +16,13 @@ __mamba_hashr() {
}

__mamba_xctivate() {
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __mamba_exe shell "${@}" --shell bash)" || \return
\eval "${ask_conda}"
\local ask_mamba
ask_mamba="$(PS1="${PS1:-}" __mamba_exe shell "${@}" --shell bash)" || \return
\eval "${ask_mamba}"
__mamba_hashr
}

micromamba() {
__mamba_wrap() {
\local cmd="${1-__missing__}"
case "${cmd}" in
activate|reactivate|deactivate)
Expand All @@ -36,8 +36,8 @@ micromamba() {
__mamba_exe "${@}" || \return

# remove leftover backup file on Windows
if [ -f "$MAMBA_EXE.bkup" ]; then
rm -f "$MAMBA_EXE.bkup"
if [ -f "${MAMBA_EXE}.bkup" ]; then
rm -f "${MAMBA_EXE}.bkup"
fi
;;
*)
Expand All @@ -46,16 +46,23 @@ micromamba() {
esac
}


# We need to define a function with the same name as the executable to be called by the user.
# There is no way to register it dynamically without relying on hacks or eval.
__exe_name="$(basename "${MAMBA_EXE}")"
__exe_name="${__exe_name%.*}"
if [[ "${__exe_name}" == "micromamba" ]]; then
micromamba() { __mamba_wrap "${@}"; }
elif [[ "${__exe_name}" == "mamba" ]]; then
mamba() { __mamba_wrap "${@}"; }
else
echo "Error unknow MAMBA_EXE: \"${MAMBA_EXE}\", filename must be mamba or micromamba" 1>&2
fi


if [ -z "${CONDA_SHLVL+x}" ]; then
\export CONDA_SHLVL=0
# In dev-mode MAMBA_EXE is python.exe and on Windows
# it is in a different relative location to condabin.
if [ -n "${_CE_CONDA+x}" ] && [ -n "${WINDIR+x}" ]; then
PATH="${MAMBA_ROOT_PREFIX}/condabin:${PATH}"
else
PATH="${MAMBA_ROOT_PREFIX}/condabin:${PATH}"
fi
\export PATH
\export PATH="${MAMBA_ROOT_PREFIX}/condabin:${PATH}"

# We're not allowing PS1 to be unbound. It must at least be set.
# However, we're not exporting it, which can cause problems when starting a second shell
Expand Down
11 changes: 9 additions & 2 deletions libmamba/data/mamba_hook.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
@FOR %%F in ("%~dp0") do @SET "__mambabin_dir=%%~dpF"
@SET "__mambabin_dir=%__mambabin_dir:~0,-1%"
@SET "PATH=%__mambabin_dir%;%PATH%"
@SET "MAMBA_BAT=%__mambabin_dir%\micromamba.bat"
@SET "MAMBA_BAT=%__mambabin_dir%\mamba.bat"
@FOR %%F in ("%__mambabin_dir%") do @SET "__mamba_root=%%~dpF"
__MAMBA_INSERT_MAMBA_EXE__
@SET __mambabin_dir=
@SET __mamba_root=

@DOSKEY micromamba="%MAMBA_BAT%" $*
@REM We need to define an alias with the same name as the executable to be called by the user.
@REM Get the base filename of MAMBA_EXE
@FOR %%A in ("%MAMBA_EXE%") do set "__mamba_filename=%%~nxA"
@REM Remove .exe extension from the filename
@SET "__mamba_name=!__mamba_filename:%~x1=!"
@REM Define correct alias depending on the executable name
@set "__mamba_cmd=call ""%MAMBA_BAT%"" $*"
@DOSKEY !__mamba_name!=!__mamba_cmd!

@SET CONDA_SHLVL=0
3 changes: 2 additions & 1 deletion libmamba/include/mamba/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ namespace mamba
std::string caller_version{ "" };
std::string conda_version{ "3.8.0" };
std::string current_command{ "mamba" };
bool is_micromamba{ false };
/** Is the Context used in a mamba or mamba executable (instead of a lib). */
bool is_mamba_exe{ false };
};

struct ThreadsParams
Expand Down
4 changes: 3 additions & 1 deletion libmamba/include/mamba/core/package_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ namespace mamba
// Determine the kind of command line to run to extract subprocesses.
enum class extract_subproc_mode
{
/** An external binary packaged with `libmamba` to launch as a subprocess. */
mamba_package,
micromamba,
/** The mamba or micromamba executable calling itself. */
mamba_exe,
};

struct ExtractOptions
Expand Down
10 changes: 5 additions & 5 deletions libmamba/include/mamba/core/shell_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#define MAMBA_CORE_SHELL_INIT

#include <string>
#include <string_view>
#include <vector>

#include "mamba/fs/filesystem.hpp"

extern const char data_micromamba_sh[];
extern const char data_micromamba_csh[];
extern const char data_micromamba_bat[];
extern const char data_mamba_sh[];
extern const char data_mamba_csh[];
extern const char data_mamba_bat[];
extern const char data_activate_bat[];
extern const char data__mamba_activate_bat[];
extern const char data_mamba_hook_bat[];
Expand All @@ -38,14 +39,13 @@ namespace mamba
);
#endif

fs::u8path get_self_exe_path();
std::string get_hook_contents(const Context& context, const std::string& shell);

// this function calls cygpath to convert win path to unix
std::string native_path_to_unix(const std::string& path, bool is_a_path_env = false);

std::string
rcfile_content(const fs::u8path& env_prefix, const std::string& shell, const fs::u8path& mamba_exe);
rcfile_content(const fs::u8path& env_prefix, std::string_view shell, const fs::u8path& mamba_exe);

std::string
xonsh_content(const fs::u8path& env_prefix, const std::string& shell, const fs::u8path& mamba_exe);
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ namespace mamba

struct WrappedCallOptions
{
bool is_micromamba = false;
bool is_mamba_exe = false;
bool dev_mode = false;
bool debug_wrapper_scripts = false;

Expand Down
Loading
Loading