maint: Factorize common parts of the install, update and remove paths - #4215
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4215 +/- ##
==========================================
+ Coverage 52.75% 53.55% +0.79%
==========================================
Files 239 239
Lines 29270 29264 -6
Branches 3121 3106 -15
==========================================
+ Hits 15441 15671 +230
+ Misses 13826 13590 -236
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
980a131 to
f9373bb
Compare
f9373bb to
0b050c7
Compare
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
0b050c7 to
334fde6
Compare
install, update and remove paths
00f2192 to
69562c5
Compare
install, update and remove pathsinstall, update and remove paths
jjerphan
left a comment
There was a problem hiding this comment.
Comments for reviewers.
| add_pins_to_request(request, ctx, prefix_data, raw_specs, no_pin, no_py_pin); | ||
| request.flags = ctx.solver_flags; |
There was a problem hiding this comment.
request.flags = ctx.solver_flags
was moved at the end of add_pins_to_request.
| add_pins_to_request( | ||
| request, | ||
| ctx, | ||
| ctx.pinned_packages, | ||
| ctx.solver_flags, | ||
| prefix_data, | ||
| raw_update_specs, | ||
| /* no_pin= */ config.at("no_pin").value<bool>(), | ||
| /* no_py_pin = */ config.at("no_py_pin").value<bool>() | ||
| no_pin, | ||
| no_py_pin | ||
| ); | ||
|
|
||
| request.flags = ctx.solver_flags; |
There was a problem hiding this comment.
request.flags = ctx.solver_flags
was moved at the end of add_pins_to_request.
| ); | ||
| } | ||
| } | ||
| request.flags = solver_flags; |
There was a problem hiding this comment.
This was consistently used after add_pins_to_request, so I just made it part of this function.
| void add_pins_to_request( | ||
| solver::Request& request, | ||
| const Context& ctx, | ||
| PrefixData& prefix_data, | ||
| std::vector<std::string> specs, | ||
| bool no_pin, | ||
| bool no_py_pin | ||
| ); |
There was a problem hiding this comment.
Moved to libmamba/include/mamba/api/utils.hpp as it is also use in libmamba/src/api/update.cpp
There was a problem hiding this comment.
This is theoretically a backward incompatible change since utils.hpp is in the src folder (and we don't want to change that).
One way to avoid code duplication is to keep this declaration and ave the implementation in install.cpp forward the call to the new function in utils.hpp.
There was a problem hiding this comment.
Yes, I know; but I wondered whether any other projects use those headers (it does not seem to be the case); we can keep the declaration here; and the definition in the install.cpp translation unit.
There was a problem hiding this comment.
That's something we cannot really know until someone comes and complains about the breakage, so let's be conservative here.
| void print_activation_message(const Context& ctx) | ||
| { | ||
| // Check that the target prefix is not active before printing the activation message | ||
| if (util::get_env("CONDA_PREFIX") != ctx.prefix_params.target_prefix) | ||
| { | ||
| // Get the name of the executable used directly from the command. | ||
| const auto executable = get_self_exe_path().stem().string(); | ||
|
|
||
| // Get the name of the environment | ||
| const auto environment = env_name( | ||
| ctx.envs_dirs, | ||
| ctx.prefix_params.root_prefix, | ||
| ctx.prefix_params.target_prefix | ||
| ); | ||
|
|
||
| Console::stream() << "\nTo activate this environment, use:\n\n" | ||
| " " | ||
| << executable << " activate " << environment | ||
| << "\n\n" | ||
| "Or to execute a single command in this environment, use:\n\n" | ||
| " " | ||
| << executable | ||
| << " run " | ||
| // Use -n or -p depending on if the env_name is a full prefix or | ||
| // just a name. | ||
| << (environment == ctx.prefix_params.target_prefix ? "-p " : "-n ") | ||
| << environment << " mycommand\n"; | ||
| } | ||
| } |
| void add_pins_to_request( | ||
| solver::Request& request, | ||
| const Context& ctx, | ||
| PrefixData& prefix_data, | ||
| std::vector<std::string> specs, | ||
| bool no_pin, | ||
| bool no_py_pin | ||
| ); |
There was a problem hiding this comment.
This is theoretically a backward incompatible change since utils.hpp is in the src folder (and we don't want to change that).
One way to avoid code duplication is to keep this declaration and ave the implementation in install.cpp forward the call to the new function in utils.hpp.
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Johan Mabille <johan.mabille@gmail.com>
Description
I would like to introduce a proper retry mechanism for #4214 like what exists for
install_specs_impl.I have seen that there's a lot of duplications and inconsistency between this paths, so this first corrects it.
Type of Change
Checklist
pre-commit run --alllocally in the source folder and confirmed that there are no linter errors.