Skip to content

Conversation

@longtsing
Copy link

Description

This PR adds support for environment cloning functionality to the micromamba create command using the --clone option, providing full compatibility with conda's environment cloning capabilities.

Summary of Changes

This implementation allows users to clone existing conda/mamba environments by specifying an environment name or path with the --clone option. The feature includes:

  • Configuration Integration: Added clone_env configuration option to the mamba configuration system
  • CLI Support: Added --clone command-line option to the create command with proper argument parsing
  • Core Cloning Logic: Implemented environment discovery, validation, and package specification extraction from source environments
  • Error Handling: Comprehensive validation including conflict detection, environment existence checks, and clear error messages
  • Compatibility: Full compatibility with existing create command functionality

Usage Examples

# Clone by environment name
micromamba create -n new_env --clone existing_env

# Clone by absolute path  
micromamba create -n new_env --clone /path/to/environment

# Clone base environment
micromamba create -n new_env --clone base

Implementation Details

  • Files Modified:

    • configuration.cpp - Added clone_env configuration option
    • common_options.cpp - Added --clone CLI option with validation
    • create.cpp - Implemented core cloning logic with environment discovery and package extraction
  • Key Features:

    • Automatic environment path resolution (supports both names and absolute paths)
    • Conflict detection (prevents usage with package specs or --file option)
    • Robust error handling with descriptive messages
    • Reuses existing installation infrastructure for reliability

Type of Change

  • Feature / enhancement

Checklist

  • My code follows the general style and conventions of the codebase, ensuring consistency
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run pre-commit run --all locally in the source folder and confirmed that there are no linter errors.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

Notes

  • This feature maintains backward compatibility with all existing create command functionality
  • The implementation leverages existing mamba infrastructure (PrefixData, EnvironmentsManager) for consistency and reliability
  • Comprehensive error handling ensures clear feedback for invalid scenarios
  • The clone functionality mirrors conda's behavior while maintaining mamba's performance characteristics

@github-actions github-actions bot added the release::enhancements For enhancements PRs or implementing features label Sep 28, 2025
Copy link
Member

@JohanMabille JohanMabille 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 your PR! Could you add some tests to check basic use cases?


// Handle clone environment logic
std::vector<std::string> clone_specs;
if (!clone_env_name.empty())
Copy link
Member

@JohanMabille JohanMabille Oct 2, 2025

Choose a reason for hiding this comment

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

Could you move this code into a dedicated function so that we can write something like

auto clone_specs = get_clone_specs(/* parameters needed */);

The idea is to have the create function "short" and easy to read (it would require some further refactoring, but this is orthogonal to your PR).

auto maybe_source_prefix_data = PrefixData::create(source_prefix, channel_context);
if (!maybe_source_prefix_data)
{
const auto message = "Could not load prefix data from source environment: " + maybe_source_prefix_data.error().what();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const auto message = "Could not load prefix data from source environment: " + maybe_source_prefix_data.error().what();
const auto message = std::string("Could not load prefix data from source environment: ") + maybe_source_prefix_data.error().what();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release::enhancements For enhancements PRs or implementing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants