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

Conversation

@FelisNivalis
Copy link
Contributor

@FelisNivalis FelisNivalis commented Sep 30, 2022

active_prefix returns empty string instead of None when no active env

Description

Got errors when trying to rename an environment with no active environments

    Traceback (most recent call last):
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1129, in __call__
        return func(*args, **kwargs)
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/cli/main.py", line 86, in main_subshell
        exit_code = do_call(args, p)
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 93, in do_call
        return getattr(module, func_name)(args, parser)
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/cli/main_rename.py", line 53, in execute
        source = validate_src(args.name, args.prefix)
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/cli/main_rename.py", line 28, in validate_src
        if common.is_active_prefix(prefix):
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/cli/common.py", line 87, in is_active_prefix
        paths_equal(prefix, context.active_prefix)
      File "/home/.../miniconda3/lib/python3.9/site-packages/conda/common/path.py", line 57, in paths_equal
        return abspath(path1) == abspath(path2)
      File "/home/.../miniconda3/lib/python3.9/posixpath.py", line 375, in abspath
        path = os.fspath(path)
    TypeError: expected str, bytes or os.PathLike object, not NoneType

So basically when no active env, context.active_prefix returned a None, which further caused os.fspath to raise an error.

I just fixed it in a simplest way so that context.active_prefix always returns a string, but if, for example, None means something special for active_prefix, we can try to figure out another way.

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?

@FelisNivalis FelisNivalis requested a review from a team as a code owner September 30, 2022 19:12
@conda-bot
Copy link
Contributor

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

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.

@jezdez
Copy link
Member

jezdez commented Oct 5, 2022

@conda-bot check

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Oct 5, 2022
jezdez
jezdez previously approved these changes Oct 13, 2022
`active_prefix` returns empty string instead of `None` when no active env
…o detect cases where there isn't an active env
@beeankha
Copy link
Member

Hi @FelisNivalis , thank you for your contribution! We really appreciate you taking the time to submit this suggested fix.

The active_prefix() method in the Context class (which you made code changes for in this pull request) always expects the root prefix to have a value instead of '' or None, so that's something we would not like to alter; additionally, the Context object affects many other parts of the codebase, so changing it should generally be avoided since there will definitely be some unforeseeable consequences.

Additionally, changing the active_prefix() method and attempting a rename while conda is deactivated means that there is no straightforward way to explicitly prevent conda users from inadvertently renaming their base environment. We need to avoid this scenario since renaming base irreparably breaks conda.

The more ideal path forward may be to alter the is_active_prefix() function in common.py to detect whether or not a prefix is active and return False if there isn't one. This will ensure that the TypeError you were seeing previously will not surface during an attempted rename, and that an environment can get successfully renamed even when conda is not active.

I've pushed a new commit to this pull request; if you agree to this change, we'll go forward with this PR and keep your name attached to it as a contributor since you so kindly found this bug and submitted a fix. Please let us know your thoughts!

@beeankha beeankha added source::community catch-all for issues filed by community members cli pertains to the CLI interface labels Jan 25, 2023
@beeankha beeankha assigned FelisNivalis and beeankha and unassigned beeankha Jan 25, 2023
@beeankha beeankha force-pushed the patch-1 branch 5 times, most recently from f4ce38c to 18ce5e1 Compare January 25, 2023 23:32
@jezdez jezdez merged commit 5a9deaf into conda:main Jan 31, 2023
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Feb 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 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 cli pertains to the CLI interface 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.

6 participants