这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@xylar
Copy link
Contributor

@xylar xylar commented Oct 10, 2022

Description

Before this merge, calls to

conda init --no-user

do not have the desired effect of not modifying the user's .bashrc, etc.

See #11948.

This merge fixes that by making sure args.user is now set to False when the --no-user flag is provided, ultimately resulting in no attempt to modify the .bashrc or equivalent.

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?

closes #11948
closes #9739

It is clear from the code that `args.no_user` should have a value
of `True` when the `--no-user` flag is provided, so that the
user's `.bashrc`, etc. is not updated.
@xylar xylar requested a review from a team as a code owner October 10, 2022 22:08
@conda-bot
Copy link
Contributor

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

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. We will ping the bot to refresh the PR status when we have confirmed your signature.

@xylar xylar force-pushed the fix_conda_init_no_user branch from fc13e85 to 3218283 Compare October 10, 2022 22:24
@jezdez jezdez added the duplicate::primary if an issue/PR has duplicates, this is the consolidated, primary issue/PR label Oct 14, 2022
@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

Needs a test.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

@dholth, I would be happy to add a test but I would need some hand-holding as this is my first time attempting to contribute to conda.

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

We will probably be able to merge this. The argument is processed here in https://github.com/conda/conda/blob/main/conda/cli/main_init.py#L34 . There are enough negatives that it takes a while to convince ourselves that the new code is correct. It looks like the flag never worked properly.

        for_user = args.user
        if not (args.install and args.user and args.system):
            for_user = True
        if args.no_user:
            for_user = False

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

It looks like the flag never worked properly.

Yes, I belief that's the case. I did test this locally and it worked as expected.

(In the meantime, I'm working around this by just moving my .bashrc aside, running conda init, and moving my .bashrc back.)

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

Did you figure out why there is an args.user and and args.no_user

    setup_type_group.add_argument(
        "--user",
        action="store_true",
        help="Initialize conda for the current user (default).",
        default=NULL,
    )
    setup_type_group.add_argument(
        "--no-user",
        action="store_false",
        help="Don't initialize conda for the current user (default).",
        default=NULL,
    )

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

I don't believe there is a difference between having --user and not having any flag at all. So I think the --user flag should be removed. But since it isn't causing trouble, I didn't want that to complicate this particular PR.

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

Here's what it "should" look like

    setup_type_group.add_argument(
        "--user",
        action="store_true",
        help="Initialize conda for the current user (default).",
        default=True,
        # suppress help since we want to emphasize --no-user ?
    )
    setup_type_group.add_argument(
        "--no-user",
        dest="user",
        action="store_false",
        help="Don't initialize conda for the current user.",
#        default=NULL, # set by --user flag
    )

and in main_init,

        for_user = args.user
        if not (args.install and args.user and args.system): # why should for_user be True if not all of install, user, system? were we trying to do something "default" if none were set?
            for_user = True
        if args.user == False:
            for_user = False

This is more intuitive to follow through the code but has the
complication that the default mush be handled differently.
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Nov 7, 2022
@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

Here's what it "should" look like

    setup_type_group.add_argument(
        "--user",
        action="store_true",
        help="Initialize conda for the current user (default).",
        default=True,
...

Okay, I'm willing to give this default=True a try. I'll not have a chance to thoroughly test until tomorrow (it's 10 pm where I live).

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

Thanks! We'll get this done carefully.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

Also, happy to squash my commits to keep things cleaner, I just don't want to cause any undue confusion.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

Okay, I couldn't let this go and I did some more testing. The logic works up to this line:

if not (args.install and args.user and args.system):
for_user = True

But then we have:

args.user = False # yay!
args.system = NULL
args.install = NULL

It seems that currently the only way to prevent my .bashrc from being altered is to run:

conda init --no-user --install --system

I can't imagine this is the intended behavior.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

Looking back at the commit history, I think:

if not (args.install and args.user and args.system):
for_user = True

used to make sense when --no-user didn't exist and --user was not the default (it had to be specified). Even then, I think the logic was probably wrong. I think it was probably meant to say, if none of --user, --install and --system is provided, do a user init. But it actually said if all 3 flags are not provided, do a user init. This is odd because --user and --system don't seem to make sense at the same time.

My sense at this point is that this line just doesn't make sense anymore at all and should be removed. I'm going to do that (and include this long explanation).

Looking back at the commit history, I think:
```
        if not (args.install and args.user and args.system):
            for_user = True
```
used to make sense when `--no-user` didn't exist and `--user` was
not the default (it had to be specified).  Even then, I think the
logic was probably wrong.  I think it was probably meant to say,
if none of `--user`, `--install` and `--system` is provided, do a
user init.  But it actually said if all 3 flags are not provided,
do a user init.  This is odd because `--user` and `--system`
don't seem to make sense at the same time.

My sense at this point is that this line just doesn't make sense
anymore at all and should be removed.
@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

With my latest change, I have verified that conda init and conda init --user both produce:

...
no change     /home/xylar/Desktop/mambaforge/etc/profile.d/conda.csh
modified      /home/xylar/.bashrc

but that conda init --no-user does not:

no change     /home/xylar/Desktop/mambaforge/etc/profile.d/conda.csh
No action taken.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

@dholth, please give this another look when you have time.

@dholth
Copy link
Contributor

dholth commented Nov 7, 2022

https://docs.conda.io/projects/conda/en/latest/commands/init.html?highlight=Conda%20init

It makes intuitive sense that --system could disable --user. We just have to replace the old logic.

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

Looks good but this line must be a mistake? We set for_user = True if install is false, or user is false, or system is false

Just saw this comment

It makes intuitive sense that --system could disable --user. We just have to replace the old logic.

Okay, I agree. Let's make this work the way it's supposed to!

@xylar
Copy link
Contributor Author

xylar commented Nov 7, 2022

So if someone specifies both --system and --user, shouldn't there just be an error?

And what is --install supposed to do (I'll try to figure it out)?

@xylar
Copy link
Contributor Author

xylar commented Dec 7, 2022

@dholth, just wondering about the process here. Is there anything more I need to do to see this get merged at some point?

@dholth dholth added the in-progress issue is actively being worked on label Dec 7, 2022
@dholth
Copy link
Contributor

dholth commented Dec 7, 2022

Thanks, I've tagged this appropriately. We will merge it within a couple of weeks +- holidays

Copy link
Contributor

@dholth dholth left a comment

Choose a reason for hiding this comment

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

Thanks so much!

@kenodegard
Copy link
Contributor

Updated to fix the tests/conda_env/test_create.py::IntegrationTests::test_create_update_remote_env_file test failures. Should pass now.

See: https://github.com/conda/conda/actions/runs/3414753536/jobs/6144233243#step:7:709
Fix: #12024

@xylar
Copy link
Contributor Author

xylar commented Dec 13, 2022

🤞🏻

@beeankha beeankha added the source::community catch-all for issues filed by community members label Dec 15, 2022
@beeankha beeankha requested a review from a team December 15, 2022 15:06
@kenodegard kenodegard merged commit 34603d1 into conda:main Dec 15, 2022
@xylar xylar deleted the fix_conda_init_no_user branch February 26, 2023 18:33
xylar added a commit to xylar/mamba that referenced this pull request Feb 26, 2023
This merge makes changes similar to
conda/conda#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:
conda/conda#11948
jonashaag pushed a commit to mamba-org/mamba that referenced this pull request Feb 26, 2023
* Fix `mamba init --no-user`

This merge makes changes similar to
conda/conda#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:
conda/conda#11948

* Fix for conda < 23.1.0

* 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.
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Feb 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 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 duplicate::primary if an issue/PR has duplicates, this is the consolidated, primary issue/PR in-progress issue is actively being worked on locked [bot] locked due to inactivity source::community catch-all for issues filed by community members

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

--no-user flag on conda init does not prevent .bashrc update as expected

6 participants