diff --git a/mamba/mamba/mamba.py b/mamba/mamba/mamba.py index 7ecc8fa13f..7c7f92de85 100644 --- a/mamba/mamba/mamba.py +++ b/mamba/mamba/mamba.py @@ -19,7 +19,7 @@ ensure_name_or_prefix, specs_from_url, ) -from conda.cli.install import check_prefix, clone, get_revision, print_activate +from conda.cli.install import check_prefix, clone, get_revision from conda.cli.main import generate_parser, init_loggers from conda.common.compat import on_win from conda.common.path import paths_equal @@ -50,7 +50,13 @@ from mamba import repoquery as repoquery_api from mamba.linking import handle_txn from mamba.mamba_shell_init import shell_init -from mamba.utils import get_installed_jsonfile, init_api_context, load_channels, to_txn +from mamba.utils import ( + get_installed_jsonfile, + init_api_context, + load_channels, + print_activate, + to_txn, +) if sys.version_info < (3, 2): sys.stdout = codecs.lookup("utf-8")[-1](sys.stdout) @@ -898,10 +904,8 @@ def main(*args, **kwargs): if "activate" in sys.argv or "deactivate" in sys.argv: print( - f"Run 'mamba init' to be able to run mamba activate/deactivate\n" - f"and start a new shell session. Or use conda to activate/deactivate.\n" - f"\n" - f" $ conda {' '.join(sys.argv[1:])}\n", + "Run 'mamba init' to be able to run mamba activate/deactivate\n" + "and start a new shell session. Or use conda to activate/deactivate.\n", file=sys.stderr, ) return sys.exit(-1) diff --git a/mamba/mamba/utils.py b/mamba/mamba/utils.py index d558e29370..4d70e51dee 100644 --- a/mamba/mamba/utils.py +++ b/mamba/mamba/utils.py @@ -430,3 +430,14 @@ def to_txn( prefix, final_precs, ) + + +def print_activate(env_name_or_prefix): # pragma: no cover + if not context.quiet and not context.json: + message = ( + "\nTo activate this environment, use\n\n" + f" $ mamba activate {env_name_or_prefix}\n\n" + "To deactivate an active environment, use\n\n" + " $ mamba deactivate\n" + ) + print(message) # TODO: use logger