Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require name or prefix if we are running create with dry-run #13941

Merged
merged 7 commits into from
May 30, 2024

Conversation

jaimergp
Copy link
Contributor

@jaimergp jaimergp commented May 24, 2024

Description

Folks often rely on create --dry-run to run solver diagnostics. For this operation, prefixes or env names are not needed, yet they are still required in the CLI. It's common to see invocations such as:

$ conda create -n unused --dry-run ...

Or the shorthand (with x being the env name):

$ conda create -dnx ...

However it should be perfectly fine to run:

$ conda create --dry-run ...

This is what we see in this PR.

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?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label May 24, 2024
Copy link

codspeed-hq bot commented May 24, 2024

CodSpeed Performance Report

Merging #13941 will not alter performance

Comparing jaimergp:dry-run-create-does-not-need-prefix-name (0fc7f6e) with main (eb45954)

Summary

✅ 21 untouched benchmarks

@jaimergp jaimergp marked this pull request as ready for review May 24, 2024 15:58
@jaimergp jaimergp requested a review from a team as a code owner May 24, 2024 15:58
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.

Just a couple requests for changes. Please let me know if any seem unreasonable. Will be happy to review once more.

from ..gateways.disk.delete import rm_rf
from ..gateways.disk.test import is_conda_environment
from .common import confirm_yn
from .install import install

if not args.name and not args.prefix:
if context.dry_run:
context._argparse_args.prefix = os.path.join(mktemp(), "dry-run-create-env")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
context._argparse_args.prefix = os.path.join(mktemp(), "dry-run-create-env")
args.prefix = os.path.join(mktemp(), "dry-run-create-env")
context.__init__(argparse_args=args)

I think this is slightly better. No need to access a protected property when we can simply re-initialize the object. Performance penalty should be negligible.

Also, Could we make "dry-run-create-env" a constant and define it in conda.base.constants. Not necessary, but would help keep the code a little more organized and provide a central place to look up this value in case it is ever needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure we are not overriding some stuff from os.environ with that call? 🤔 I always get nervous when I reinitialize the context outside of the tests 😬

+1 to the 2nd suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied your suggestions. The new tests seem to be passing locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

No reason to worry about overriding stuff from os.environ. I double checked the code. We just need to make sure we initialize it like we do in conda.cli.main.main_subshell by pass the argparse args:

tests/test_create.py Show resolved Hide resolved
jaimergp and others added 3 commits May 27, 2024 15:38
Co-authored-by: Travis Hathaway <travis.j.hathaway@gmail.com>
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.

🚀

@travishathaway
Copy link
Contributor

Looking good. Thanks for being receptive to my suggestions 😄.

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.

Thanks for doing this work, @jaimergp !

@jezdez jezdez merged commit 7814522 into conda:main May 30, 2024
66 checks passed
@kenodegard kenodegard mentioned this pull request Jul 17, 2024
61 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants