From 02f2910853ed046c3a09e33b881a1aa02e85c030 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sun, 26 Feb 2023 12:30:20 -0700 Subject: [PATCH 1/3] Fix `mamba init --no-user` This merge makes changes similar to https://github.com/conda/conda/pull/11949 to fix `mamba init` so that the `--no-user` flag actually has the intended effect of not changing a user's `.bashrc` or equivalent. Without this change, `--no-user` has no effect as was previously the case in conda, see: https://github.com/conda/conda/issues/11948 --- mamba/mamba/mamba_shell_init.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mamba/mamba/mamba_shell_init.py b/mamba/mamba/mamba_shell_init.py index 03f22e94bf..15bcbddfb7 100644 --- a/mamba/mamba/mamba_shell_init.py +++ b/mamba/mamba/mamba_shell_init.py @@ -81,12 +81,7 @@ def shell_init(args): return initialize_dev(shell) else: - for_user = args.user - if not (args.install and args.user and args.system): - for_user = True - # no_user removed in Conda 23.1.0, see https://github.com/mamba-org/mamba/issues/2248 - if hasattr(args, "no_user") and args.no_user: - for_user = False + for_user = args.user and not args.system anaconda_prompt = on_win and args.anaconda_prompt exit_code = initialize( From bff2ce98248ffc5706c30253780aa6adcd204bac Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sun, 26 Feb 2023 13:13:34 -0700 Subject: [PATCH 2/3] Fix for conda < 23.1.0 --- mamba/mamba/mamba_shell_init.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mamba/mamba/mamba_shell_init.py b/mamba/mamba/mamba_shell_init.py index 15bcbddfb7..af3b6e414e 100644 --- a/mamba/mamba/mamba_shell_init.py +++ b/mamba/mamba/mamba_shell_init.py @@ -81,7 +81,13 @@ def shell_init(args): return initialize_dev(shell) else: - for_user = args.user and not args.system + if hasattr(args, "no_user"): + # this seems to be conda < 23.1.0 + # the `no_user` flag, if set, gets erroneously set to False + for_user = (args.no_user != False and args.user != False and + not args.system) + else: + for_user = args.user and not args.system anaconda_prompt = on_win and args.anaconda_prompt exit_code = initialize( From a1b3b32c60a9af360aaf36f9972c9ebbd104ae0e Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sun, 26 Feb 2023 13:47:52 -0700 Subject: [PATCH 3/3] Revert back to old code when `args.no_user` present This is still broken with the `--no-user`, as noted, but at least newer versions of conda (>=23.1.0) will work as expected. --- mamba/mamba/mamba_shell_init.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mamba/mamba/mamba_shell_init.py b/mamba/mamba/mamba_shell_init.py index af3b6e414e..47ecf75596 100644 --- a/mamba/mamba/mamba_shell_init.py +++ b/mamba/mamba/mamba_shell_init.py @@ -83,9 +83,14 @@ def shell_init(args): else: if hasattr(args, "no_user"): # this seems to be conda < 23.1.0 - # the `no_user` flag, if set, gets erroneously set to False - for_user = (args.no_user != False and args.user != False and - not args.system) + # Here, we use the old behavior even though the --no-user flag + # doesn't behave as desired, see: + # https://github.com/conda/conda/issues/11948 + for_user = args.user + if not (args.install and args.user and args.system): + for_user = True + if args.no_user: + for_user = False else: for_user = args.user and not args.system