Skip to content

Conversation

13rac1
Copy link
Contributor

@13rac1 13rac1 commented Oct 9, 2023

Description

Add two mock entries to the configure_parser_init() so the activate and deactivate shell commands are displayed in the --help.

Before:

$ conda --help
...
commands:
  The following built-in and plugins subcommands are available.

  COMMAND
    clean             Remove unused packages and caches.
    compare           Compare packages between conda environments.
    config            Modify configuration values in .condarc.
    content-trust     See `conda content-trust --help`.
    create            Create a new conda environment from a list of specified packages.
    doctor            Display a health report for your environment.
    env               See `conda env --help`.
    info              Display information about current conda install.
    init              Initialize conda for shell interaction.
    install           Install a list of packages into a specified conda environment.
    list              List installed packages in a conda environment.
    notices           Retrieve latest channel notifications.
    pack              See `conda pack --help`.
    package           Create low-level conda packages. (EXPERIMENTAL)
    remove (uninstall)
                      Remove a list of packages from a specified conda environment.
    rename            Rename an existing environment.
    repoquery         Advanced search for repodata.
    run               Run an executable in a conda environment.
    search            Search for packages and display associated information using the MatchSpec format.
    server            See `conda server --help`.
    update (upgrade)  Update conda packages to the latest compatible version.
    verify            See `conda verify --help`.

After:

$ conda --help
...
commands:
  The following built-in and plugins subcommands are available.

  COMMAND
    activate          Activate a conda environment.
    clean             Remove unused packages and caches.
    compare           Compare packages between conda environments.
    config            Modify configuration values in .condarc.
    content-trust     See `conda content-trust --help`.
    create            Create a new conda environment from a list of specified packages.
    deactivate        Deactivate the current active conda environment.
    doctor            Display a health report for your environment.
    env               See `conda env --help`.
    info              Display information about current conda install.
    init              Initialize conda for shell interaction.
    install           Install a list of packages into a specified conda environment.
    list              List installed packages in a conda environment.
    notices           Retrieve latest channel notifications.
    pack              See `conda pack --help`.
    package           Create low-level conda packages. (EXPERIMENTAL)
    remove (uninstall)
                      Remove a list of packages from a specified conda environment.
    rename            Rename an existing environment.
    repoquery         Advanced search for repodata.
    run               Run an executable in a conda environment.
    search            Search for packages and display associated information using the MatchSpec format.
    server            See `conda server --help`.
    update (upgrade)  Update conda packages to the latest compatible version.
    verify            See `conda verify --help`.

This is arguably a hack, but is the correct way to resolve the issue according to #6353. I'm not 100% if they should be listed in BUILTIN_COMMANDS, but it seems right to me.

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@13rac1 13rac1 requested a review from a team as a code owner October 9, 2023 21:56
@conda-bot
Copy link
Contributor

We require contributors to sign our Contributor License Agreement and we don't have one on file for @13rac1.

In order for us to review and merge your code, please e-sign the Contributor License Agreement PDF. We then need to manually verify your signature, merge the PR (conda/infrastructure#831), and ping the bot to refresh the PR.

@13rac1
Copy link
Contributor Author

13rac1 commented Oct 9, 2023

FYI I have signed the CLA

@beeankha
Copy link
Member

@conda-bot check

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Oct 10, 2023
Copy link
Member

@beeankha beeankha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @13rac1 , thank you so much for creating this PR!

Something that needs to be addressed before this can be merged is that if someone has conda installed but conda init hasn't been run (you can run $ unset conda to recreate this scenario), then a very confusing error pops up and conda doesn't get properly activated:

> unset conda
> conda activate

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/Users/biancahenderson/Documents/GitHub/conda/conda/exception_handler.py", line 17, in __call__
        return func(*args, **kwargs)
      File "/Users/biancahenderson/Documents/GitHub/conda/conda/cli/main.py", line 83, in main_subshell
        exit_code = do_call(args, parser)
      File "/Users/biancahenderson/Documents/GitHub/conda/conda/cli/conda_argparse.py", line 159, in do_call
        relative_mod, func_name = args.func.rsplit(".", 1)
    AttributeError: 'Namespace' object has no attribute 'func'

In order to avoid this, a dummy/mock "execute" function for both activate and deactivate should be added, most likely in /conda/conda/cli/conda_argparse.py, with instructions for the user to run conda init in order to improve the user experience and avoid possible confusion.

@13rac1
Copy link
Contributor Author

13rac1 commented Oct 11, 2023

You're welcome!

Haha, it's never easy is it?

These mock execute functions cannot go in /conda/conda/cli/conda_argparse.py, because the do_call() method expects to import a module in line 159:

else:
# let's call the subcommand the old-fashioned way via the assigned func..
relative_mod, func_name = args.func.rsplit(".", 1)
# func_name should always be 'execute'
module = import_module(relative_mod, "conda.cli")
command = relative_mod.replace(".main_", "")
context.plugin_manager.invoke_pre_commands(command)
result = getattr(module, func_name)(args, parser)
context.plugin_manager.invoke_post_commands(command)

I could hack something into main_init.py, but it is best to just "do it right." I propose we add tiny main_mock_activate.py and main_mock_deactivate.py files, so # func_name should always be 'execute' can remain correct. Is that a reasonable plan?

@beeankha beeankha dismissed their stale review October 12, 2023 19:28

Changes have been addressed

@dholth
Copy link
Contributor

dholth commented Oct 13, 2023

Make this command return a nonzero shell error code.

@13rac1
Copy link
Contributor Author

13rac1 commented Oct 13, 2023

@dholth That is a good point!

@beeankha beeankha added source::community catch-all for issues filed by community members type::feature request for a new feature or capability labels Oct 13, 2023
@dholth
Copy link
Contributor

dholth commented Oct 18, 2023

Fixes #6353

@dholth dholth linked an issue Oct 18, 2023 that may be closed by this pull request
beeankha
beeankha previously approved these changes Oct 19, 2023
Copy link
Member

@beeankha beeankha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution, @13rac1 !

@13rac1
Copy link
Contributor Author

13rac1 commented Oct 19, 2023

You're welcome. Thanks! @beeankha @kenodegard @dholth

Copy link
Contributor

@travishathaway travishathaway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@13rac1,

Thanks for this pull request! I just have a couple of recommendations that I would like to see added before I give my approval. Please let me know if you have any questions.

@13rac1
Copy link
Contributor Author

13rac1 commented Oct 21, 2023

@travishathaway No questions, makes sense. This is the difference in output:

# before
(base) test_user@f00a24b80e33:/opt/conda-src$ conda activate
ERROR: Run 'conda init' before 'conda activate'
(base) test_user@f00a24b80e33:/opt/conda-src$ 

#after
(base) test_user@f00a24b80e33:/opt/conda-src$ conda activate

CondaError: Run 'conda init' before 'conda activate'
(base) test_user@f00a24b80e33:/opt/conda-src$ 

@13rac1 13rac1 requested a review from travishathaway October 21, 2023 16:30
13rac1 and others added 3 commits October 23, 2023 08:35
Add two mock entries to the `configure_parser_init()` so the `activate`
and `deactivate` shell commands are displayed in the --help.

Fixes #6353
Adds mock implementations of the activate and deactivate shell commands
which run only when conda has not been initialized.
@beeankha beeankha enabled auto-merge (squash) October 24, 2023 14:09
@beeankha beeankha merged commit 136f2c4 into conda:main Oct 24, 2023
@13rac1 13rac1 deleted the activate-to-help branch October 24, 2023 18:45
@13rac1
Copy link
Contributor Author

13rac1 commented Oct 24, 2023

:shipit: Awesome! Thank you

@kenodegard kenodegard mentioned this pull request Dec 1, 2023
44 tasks
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Oct 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed [bot] added once the contributor has signed the CLA locked [bot] locked due to inactivity source::community catch-all for issues filed by community members type::feature request for a new feature or capability
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

conda --help does not show conda activate and conda deactivate info
6 participants