-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Separate requirements.txt and explicit env specs #14963
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
Separate requirements.txt and explicit env specs #14963
Conversation
CodSpeed Instrumentation Performance ReportMerging #14963 will not alter performanceComparing Summary
|
5c3f32e
to
f3e2e22
Compare
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
@@ -97,15 +92,20 @@ def can_handle(self) -> bool: | |||
self.msg = f"File {self.filename} does not have a supported extension: {', '.join(self.extensions)}" | |||
return False | |||
|
|||
# Ensure this is not an explicit file. Requirements.txt and explicit files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say in general, the approach of matching just the file extension to check if an env spec plugin can parse an environment spec is not sufficient. I would call this a "greedy plugin". Punting on fixing this issue in this PR since other built in plugins also have this issue. We'll want to tackle that in a more thoughtful way soon.
This PR introduces a cleaner separation between requirements.txt and explicit environment specs: - Creates a dedicated ExplicitSpec class in conda/env/specs/explicit.py - Modifies RequirementsSpec to explicitly reject explicit files - Renames requirements plugin to requirements_txt for clarity - Adds comprehensive tests for both spec types - Removes duplicate ExplicitRequirementsSpec in favor of simpler ExplicitSpec - Updates tests to work with the new Environment-based detection approach Key differences from previous implementation: - ExplicitSpec returns regular Environment instead of ExplicitEnvironment - Explicit detection happens at Environment.dependencies.explicit level - Simpler plugin architecture with separate spec classes - Better separation of concerns between requirements and explicit files
- Remove ExplicitRequirementsSpec import and registration - ExplicitRequirementsSpec is now handled by separate explicit plugin - Keeps only RequirementsSpec registration for requirements.txt files
* Implement explicit environment spec file support based on CEP-23. * Ruff. * Fix year number. * Fix year numbers because we code like it's 2012 * Consolidate explicit environment handling into dedicated module * Ruff. * Return transaction action groups (#14835) * Update conda/env/installers/conda.py Co-authored-by: Jonathan J. Helmus <jjhelmus@gmail.com> * Add type hints to conda installer functions and create explicit package list * Reset removed retry. * refactor: add read_non_comment_lines utility and use it across file reading operations * adding missing future import * Linting fixes. * implement environment export functionality with JSON support as an example - Added a new `_generate_format_help_and_examples` function to dynamically generate help text and examples for export formats. - Enhanced the `configure_parser` function to include a `--format` argument, allowing users to specify the export format. - Implemented environment exporters for JSON and YAML formats, enabling serialization of conda environments to these formats. - Updated the `execute` function to handle different export formats based on user input or file extension. - Modified tests to validate the new JSON export functionality and ensure backward compatibility with YAML exports. * rename supports_filename method to supports for consistency * rename format_name to format * pretty ruff * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test assertion for JSON export success check to be more concise * Add @Property decorator to environment method in YamlFileSpec and EnvironmentSpecBase classes * Fix docstring. * More of the same. * Refactor environment exporter plugins to use forward annotations - Added `from __future__ import annotations` to `json.py` and `yaml.py` for improved type hinting. - Updated the `export` method in `json.py` to use direct type hints instead of string annotations. * Add news. * Seperate requirements.txt and explicit env specs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add news * Complete environment export plugin hook integration - Added missing CondaEnvironmentExporter import - Added get_hook_results overload for environment_exporters - Added environment_exporters to plugin loading - Restored find_exporter_by_format, find_exporter_by_filename, and get_available_export_formats methods This ensures the environment export functionality is fully integrated with the plugin system. * Add support for handling @explicit marker in explicit environments - Updated ExplicitEnvironment to include filename in initialization. - Enhanced ExplicitRequirementsSpec to retain the @explicit marker for dependency detection. - Modified tests to account for the @explicit marker, ensuring correct package counts and assertions. - Improved test clarity by filtering out the @explicit marker when verifying actual package presence. This update ensures that the explicit environment handling is robust and accurately reflects the intended specifications. * Fix requirements_txt plugin after merging PR #14963 - Remove ExplicitRequirementsSpec import and registration - ExplicitRequirementsSpec is now handled by separate explicit plugin - Keeps only RequirementsSpec registration for requirements.txt files * Fix unreachable code in RequirementsSpec._valid_name method - Move error message assignment to proper location in if block - Remove unreachable code after return statements - Method now has logical flow: check name, set error if needed, return result * Fix potential unreachable code in YamlFileSpec.environment property - Add null check for filename in can_handle() to fix type issues - Improve logic flow in environment property to handle edge cases - Keep defensive null check for _environment to prevent runtime errors * Apply pre-commit fixes - Fix end-of-file whitespace in requirements.py - Fix trailing whitespace in yaml_file.py - Apply ruff formatting to modified files - Add missing trailing comma in test file * Remove dynamic help generation that conflicts with lazy plugin evaluation - Remove _generate_format_help_and_examples() function - Use static help text instead of accessing plugin manager during CLI setup - Aligns with PR #14925 lazy evaluation approach to avoid initialization timing issues - Functionality unchanged, only help text is now static instead of dynamic * Revert "Remove dynamic help generation that conflicts with lazy plugin evaluation" This reverts commit b395d88. * Refactor export command help text generation - Reintroduce dynamic help generation for export formats by adding _get_available_export_formats() function. - Replace static help text with dynamic choices for the --format argument using LazyChoicesAction. - Update examples in the epilog to reflect the current usage of the export command. - Aligns with the lazy evaluation approach while maintaining functionality. * Remove merge conflict markers from requirements.py * Remove ExplicitEnvironment class and update tests for explicit environment handling - Deleted the ExplicitEnvironment class from explicit.py as it is no longer needed. - Refactored tests to use the base Environment class for explicit environment handling. - Updated test cases to ensure proper functionality and compliance with explicit environment specifications. - Adjusted mock setups and assertions in the installer tests to reflect changes in environment handling. * Refactor error handling for unknown export formats in CLI - Update the `execute` function to raise `CondaValueError` for unrecognized file extensions without explicit format. - Modify tests to ensure that unknown formats are caught at the argument parsing level, raising `SystemExit` instead of `CondaValueError`. - Adjust test cases to reflect changes in error handling for both known and unknown formats, ensuring proper validation and user feedback. * Enhance error messages for unrecognized export formats in CLI - Update the `execute` function to provide clearer feedback for unrecognized file extensions and unknown formats. - Modify error messages to include supported file extensions and improve user guidance. - Adjust tests to reflect changes in error handling, ensuring that exceptions are raised with updated messages. * Refactor export command to validate format early in CLI execution - Move export format validation to the beginning of the `execute` function to improve performance by failing fast on unsupported formats. - Rearrange the order of operations to ensure environment setup occurs after format validation. - Maintain existing functionality while enhancing the clarity of the export process. * Refactor environment exporter management in plugin manager - Introduced new methods `get_environment_exporters` and `get_environment_exporter_by_format` to streamline the retrieval of environment exporters. - Replaced deprecated methods `find_exporter_by_format` and `find_exporter_by_filename` with more descriptive alternatives `get_environment_exporter` and `detect_environment_exporter`. - Updated the CLI export command to utilize the new methods for improved clarity and maintainability. - Enhanced tests to cover the new method implementations and ensure consistent behavior across different scenarios. * Refactor environment exporter method names for clarity - Renamed the `supports` method to `can_handle` in the `EnvironmentExporter` class to better reflect its purpose. - Updated the `CondaPluginManager` to use the new method name for checking file compatibility. - Adjusted tests to align with the updated method name, ensuring consistent behavior in filename handling. * Implement `can_handle` method in environment exporters - Added the `can_handle` method to the `JSONExporter`, `YAMLExporter`, and a test exporter to check if the exporter can handle a given filename based on its extensions. - Updated the `can_handle` method in the `EnvironmentExporter` class to be abstract, requiring subclasses to implement their own logic for filename handling. - Ensured consistent behavior across different exporter implementations by standardizing the method's functionality. * Implement environment creation and serialization enhancements - Added a new function `_create_environment_from_prefix` to facilitate the creation of `models.Environment` instances directly from a given prefix and arguments. - Introduced a `to_dict` method in the `Environment` class to convert the environment into a dictionary format suitable for serialization, including channels, dependencies, variables, and prefix. - Updated the JSON and YAML exporters to utilize the new `to_dict` method for exporting environment data. - Refactored tests to accommodate changes in environment instantiation and ensure proper functionality of the new serialization methods. * Enhance `can_handle` method in environment exporters to support format validation - Updated the `can_handle` method in `EnvironmentExporter`, `JSONExporter`, and `YAMLExporter` to accept an optional `format` parameter alongside `filename`, allowing for more flexible handling of export requests. - Improved the logic to check both filename extensions and format compatibility, ensuring that exporters can accurately determine their ability to handle various input scenarios. - Refactored tests to validate the new functionality, including combined checks for filename and format support. * Refactor error handling in environment exporters to use CondaValueError - Updated the `export` methods in `JSONExporter`, `YAMLExporter`, and the test exporter to raise `CondaValueError` instead of `ValueError` for unsupported formats. - Adjusted the documentation in `EnvironmentExporter` to reflect the change in the raised exception type. - Modified tests to ensure they correctly assert the new exception type for unsupported formats. * Refactor tests for conda explicit installer to use monkeypatching * Update package specification format in environment export - Changed the package specification format in `_create_environment_from_prefix` to use '==' for version and build separation, aligning with canonical format. - Updated tests to validate the new format, ensuring correct assertions for dependencies in both YAML and JSON exports. * Refactor environment creation to utilize prefix data for variable extraction - Updated the `_create_environment_from_prefix` function to extract environment variables directly from `PrefixData`, enhancing the environment creation process. - Removed redundant prefix data retrieval and streamlined the logic for reading installed packages. - Ensured that the environment variables are now included in the created `models.Environment` instance. * Refactor `can_handle` method in JSONExporter for improved readability - Simplified the logic in the `can_handle` method by consolidating format and filename checks into a more concise structure. - Enhanced readability while maintaining the same functionality for determining if the exporter can handle the provided filename and format. * Update docstring to showcase a TOMLExporter * Refactor `can_handle` method in YAMLExporter for improved clarity - Simplified the logic in the `can_handle` method by consolidating format and filename checks into a more concise structure. - Enhanced readability while maintaining the same functionality for determining if the exporter can handle the provided filename and format. * Refactor error handling in environment specifications to use CondaValueError - Updated the error handling in ExplicitSpec, RequirementsSpec, and YamlFileSpec classes to raise CondaValueError instead of ValueError when no filename is provided or when the environment cannot be loaded. - Enhanced consistency in exception handling across different specification classes. * Apply suggestions from code review Co-authored-by: jaimergp <jaimergp@users.noreply.github.com> * Remove JSON support from YamlFileSpec extensions and update debug logging for YAML loading failures. * Refactor environment export functionality and improve plugin manager - Updated the `to_dict` method in the Environment model for better serialization. - Refactored environment exporter retrieval methods in the plugin manager for clarity. - Enhanced JSON and YAML exporters to transform the Environment model correctly. - Fixed minor issues in test cases related to JSON loading and exporter retrieval. * Enhance environment export functionality and introduce explicit exporter - Improved the environment export process by adding support for an explicit format. - Updated the plugin manager to detect exporters based on exact filename matching. - Refactored the JSON and YAML exporters to utilize a shared method for converting the Environment model. - Added a new explicit environment exporter for better handling of explicit package specifications. - Enhanced tests to cover new functionality and ensure backward compatibility with existing formats. * Refactor environment creation and export functionality - Introduced a new class method `from_prefix` in the Environment model to streamline the creation of Environment instances from existing conda prefixes. - Removed the `_create_environment_from_prefix` function from the main export module, consolidating environment creation logic within the Environment class. - Enhanced the `_get_available_export_formats` function to retrieve available export formats using the plugin manager. - Updated the `execute` function to utilize the new `from_prefix` method for creating environments, improving code clarity and maintainability. * Remove unused import of MatchSpec in environment.py to improve code clarity. * Refactor imports in plugin manager and YAML exporter - Removed redundant imports of `os` in `manager.py` and `yaml.py` to enhance code clarity. - Updated test cases to eliminate unnecessary imports, streamlining the test environment. * Update explicit environment exporter and enhance tests - Modified the explicit environment exporter to clarify the conversion from requested packages to explicit format. - Improved test cases for built-in environment exporters, adding dedicated tests for YAML and JSON formats. - Ensured that package specifications in the explicit format are not commented out, maintaining their installable status. * Add news. * Fix linting. * Update conda/plugins/types.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Refactor environment export format retrieval - Simplified the retrieval of available export formats by introducing a new method in the plugin manager to get a mapping of format names to exporters. - Updated the `_get_available_export_formats` function to utilize this new method for improved clarity and efficiency. - Refactored the `execute` function to consistently use the context's plugin manager for environment exporter retrieval, enhancing code maintainability. - Adjusted tests to reflect changes in the plugin manager's interface and ensure dynamic alias resolution works correctly. * Refactor environment exporters to use callable export functions - Updated the environment exporter structure to utilize callable functions for exporting environments instead of class-based handlers. - Simplified the export process in `main_export.py` by directly calling the export functions. - Enhanced the `CondaEnvironmentExporter` type to include aliases and export functions. - Improved the explicit, JSON, and YAML exporters to follow the new structure, ensuring consistency across formats. - Added comprehensive tests for the new exporter functionality, verifying correct behavior and output formats. * Enhance explicit environment exporter to include platform and version information - Updated the explicit environment exporter to append platform and created-by information to the export output. - Modified the export command in the comments to reflect the correct usage of `conda create`. - Added tests to verify the inclusion of platform and created-by details in the exported result. * Updated the `execute` function to directly use `context.target_prefix` instead of calling `determine_target_prefix` * Refactor TOML export functionality in environment exporters - Removed the class-based `TOMLExporter` and replaced it with a callable `export_toml` function for exporting environments to TOML format. - Updated the `conda_environment_exporters` hook to yield the new `export_toml` function with appropriate metadata. - Simplified the export process by directly converting the environment to a TOML document using `tomlkit`. * Refactor export format retrieval in `execute` function - Updated the `execute` function to use `_get_available_export_formats()` for retrieving available export formats, improving clarity and maintainability. - Enhanced tests to ensure consistency between CLI choices and error messages regarding available formats, verifying that both canonical names and user-friendly aliases are correctly represented. * Refactor environment export functionality to use a standard utility - Removed the `to_yaml_dict` method from the `Environment` class and replaced it with a new utility function `to_dict` in the `standard` module for consistent environment export to YAML and JSON formats. - Updated the `export_toml` function to utilize the new `to_dict` utility for converting environments. - Removed the JSON and YAML exporter plugins, consolidating their functionality into the new standard exporter. - Adjusted tests to load the new standard exporter instead of the removed JSON and YAML plugins. * Enhance environment export functionality with new requirements format - Introduced a new requirements environment exporter that adheres to CEP 23, allowing for flexible package specifications without the @explicit marker. - Updated the explicit environment exporter to handle explicit packages with URLs, ensuring compliance with CEP 23. - Modified the Environment class to support both requested and explicit packages during export. - Enhanced tests to validate the functionality of both explicit and requirements exporters, ensuring proper error handling and output formats. - Updated plugin manager to include the new requirements exporter alongside existing exporters. * Fix formatting issues in requirements exporter and update test for explicit package handling * Refactor environment export format constants and update usage in main_export.py - Introduced constants for environment export formats in the standard plugin module to improve maintainability and readability. - Updated the `execute` function in `main_export.py` to utilize these constants instead of hardcoded strings for environment export formats, ensuring consistency across the codebase. * - Added a new `environment_yml` module to support exporting environments in both YAML and JSON formats, enhancing flexibility in environment management. - Introduced a `requirements_txt` module for exporting environments in a requirements format compliant with CEP 23, allowing for more versatile package specifications. - Updated the main export functionality to utilize the new exporters and adjusted the plugin manager to include them. - Refactored existing code to improve maintainability and consistency across environment export formats. * Simplified the creation of EnvironmentConfig by removing error handling for context validation, directly using from_context(). - Updated test for export override channels to ensure an ArgumentError is raised when no channels are specified with --override-channels. * Refactor package population logic in Environment class - Simplified the population of requested and explicit packages in the Environment class by ensuring explicit_packages are always populated from prefix data. - Updated logic to create MatchSpecs for requested_packages based on the presence of history. - Added integration tests to verify the correct semantics of package population, ensuring explicit_packages remain consistent across different command-line options while requested_packages reflect the specified options. * Enhance environment exporter with alias normalization and conflict detection - Implemented alias normalization in the CondaEnvironmentExporter to ensure aliases are stored in lowercase and stripped of whitespace. - Added conflict detection in the CondaPluginManager to raise an error if multiple plugins use the same format name or alias, improving plugin management integrity. - Introduced tests to verify alias normalization and conflict detection functionality, ensuring robustness in plugin behavior. * Remove deprecated get_environment_exporter method and related tests from CondaPluginManager and test_environment_export.py. This cleanup enhances code maintainability by eliminating unused functionality. * Refactor and enhance tests for built-in environment exporters - Consolidated tests for YAML and JSON exporters into a single parameterized test to improve code clarity and reduce duplication. - Added error handling tests for exporters with incompatible environment data, ensuring appropriate exceptions are raised. - Verified that all built-in exporters define their expected aliases and that alias resolution works correctly, enhancing the robustness of the plugin management system. * Refactor and enhance tests for environment export formats - Consolidated tests for exporting environments in YAML and JSON formats into parameterized tests to improve clarity and reduce duplication. - Added tests for structured file extension detection and error handling for unsupported formats and empty environments. - Ensured that appropriate exceptions are raised for invalid export formats and file extensions, enhancing the robustness of the export functionality. * Refactor test for export format consistency - Removed outdated comments in the test for export format consistency to enhance clarity and focus on relevant assertions. - Ensured that the test continues to verify the presence of both canonical names and user-friendly aliases in the available export formats. * Add EnvironmentExporterNotDetected exception and enhance exporter detection logic - Introduced a new exception, EnvironmentExporterNotDetected, to provide clearer error messages when no environment exporter is found for a given filename. - Updated the detect_environment_exporter method to raise this exception with detailed information about available formats and supported filenames. - Refactored the main_export.py logic to streamline exporter detection and improve error handling. - Enhanced tests to verify the correct raising of the new exception for unrecognized filenames, ensuring robustness in the export functionality. * Extend docs. * Improve error messaging for unsupported export formats in main_export.py - Replaced the previous method of listing available formats with a more user-friendly dashlist format for better readability. - Removed early validation of export formats to streamline the execution flow while maintaining error handling integrity. * Refactor available export formats retrieval in main_export.py - Removed the _get_available_export_formats function and replaced it with a lambda function for direct retrieval of sorted export formats. - Updated error messaging to utilize the new retrieval method, ensuring consistency and clarity in available format listings. * Updated the test for export format consistency to use the plugin manager as the single source of truth for available formats. * Refactor package specification handling in conda models - Introduced `exact_spec` and `version_spec` properties in `PackageRecord` to standardize the representation of package specifications. - Updated `main_compare.py` and `environment.py` to utilize the new properties for improved clarity in package comparisons and environment handling. - Added comprehensive tests for the new properties to ensure correct functionality and consistency across package records. * Update conda/plugins/manager.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Enhance environment exporter retrieval and error handling - Updated the `get_environment_exporter_by_format` method in CondaPluginManager to raise a `CondaValueError` with a detailed message when an unknown export format is requested. - Removed redundant error handling in `main_export.py` to streamline the execution flow. - Adjusted tests to verify that the appropriate exceptions are raised for unsupported formats, ensuring robust error handling in the exporter detection logic. * Enhance error handling for environment exporter format conflicts - Updated the `get_environment_exporters` method in `CondaPluginManager` to detect and report conflicts when multiple plugins use the same format name or alias. - Introduced detailed error messages that list conflicting plugins, improving clarity for users encountering format name conflicts. - Streamlined the conflict detection logic to ensure robust handling of environment exporter formats. * Fix whitespace. * Refactor URL handling in explicit environment exporter - Updated the logic for exporting explicit package URLs to use existing URLs or construct them from channel metadata. - Improved error handling to raise a `CondaValueError` when package URLs are not available, ensuring clearer feedback for users. - Streamlined the code by removing redundant checks and simplifying the URL construction process. * Refactor package specification handling across modules - Updated package specification methods in `PackageRecord` to use a unified format with single equals (name=version=build) instead of double equals. - Modified various modules including `main_compare.py`, `main_list.py`, and `env.py` to utilize the new specification methods for improved consistency. - Enhanced tests to validate the new specification format and ensure compliance with expected output across different scenarios. * Update tests for environment export format to reflect changes in package specification handling * Add LazyChoicesAction enhancements and tests - Introduced a `choices` property to dynamically evaluate choices for help generation and validation in `LazyChoicesAction`. - Implemented a setter for `choices` that ignores attempts to set static choices, ensuring dynamic behavior. - Updated tests for `LazyChoicesAction` to cover initialization, choice evaluation, error handling, and integration with `ArgumentParser`. - Added comprehensive test cases for valid and invalid choices, including integration with realistic export formats and solver choices. * Update error messages in EnvironmentExporterNotDetected for clarity * Improve YAML export error handling in environment exporter - Added specific exception handling for YAML errors during environment export. - Updated the error message to include details from the YAMLError, providing clearer feedback when export fails. * Update conda/plugins/manager.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Enhance JSON export handling for backwards compatibility - Updated the logic in `main_export.py` to ensure that the `--json` flag behaves correctly when used without a specified format or file, maintaining backwards compatibility. - Added tests to verify the expected behavior of the `--json` flag in various scenarios, including precedence over the `--format` option and handling of file outputs. - Improved error handling for cases where the environment exporter is not detected when using the `--json` flag with unrecognized file extensions. * Add channel extraction from installed packages in environment export - Implemented logic to extract channels from installed packages unless the `--ignore-channels` flag is set. - Updated tests to verify that the export command correctly includes or excludes channels based on the flag. - Ensured that the exported environment YAML contains the appropriate channels, enhancing the export functionality. * Remove the `to_dict` method from the `Environment` class, simplifying the codebase by eliminating unused serialization logic. This change streamlines the environment model and prepares for future enhancements. * Remove unneeded whitespace. * Update error messages in CLI tests for environment specifier and solver choices - Modified error messages in tests for invalid choices of `--environment-specifier` and `--solver` to enhance clarity and consistency. - Ensured that the updated messages provide more precise feedback for users encountering these errors. * Enhance LazyChoicesAction with caching for choices evaluation - Implemented caching for the `choices` property in `LazyChoicesAction` to improve performance by avoiding repeated calls to the choices function. - Updated the test for `choices` property to verify that the function is only called once due to caching, ensuring efficient behavior during multiple accesses. * Add package categorization methods to PrefixData Provides get_conda_packages(), get_python_packages(), and get_packages_by_type() methods for clean separation of conda and python (pip) packages. Each method returns alphabetically sorted packages for consistent export ordering. Addresses export package ordering requirements. * Add conda_env_form() method to MatchSpec Provides proper conda environment export format (name=version=build) without channel prefixes or .* patterns. Ensures consistent YAML export formatting that matches conda's historical behavior. Fixes --from-history and --no-builds format issues. * Fix conda export YAML format consistency - Use alphabetically sorted packages from PrefixData methods - Apply correct spec format: name=version=build (single equals) - Handle --no-builds with clean name=version format (no .* suffix) - Preserve --from-history bracket format for version constraints - Fix --override-channels to exclude default channels properly - Use external_packages for pip dependencies instead of requested_packages Resolves all YAML export format discrepancies with released conda. * Update legacy environment functions for consistency Refactor from_environment() to use new PrefixData package categorization methods. Maintains backward compatibility while ensuring consistent behavior with Environment.from_prefix(). Fixes channel priority ordering (insert vs append). * Add comprehensive tests for export format fixes Tests cover all review issues: - Package alphabetical ordering - --from-history bracket format - --no-builds clean format (no .* suffix) - Pip dependencies in YAML/JSON exports - --override-channels behavior - --json flag backward compatibility Uses pytest best practices with fixtures and parameterization. * Improve PrefixData tests and fix test data deletion - Add tests for new package categorization methods - Add test requiring Python package detection - Fix test_pip_interop mock to prevent test data file deletion - Use pytest-mock plugin instead of unittest.mock - Remove unused variables and improve test clarity Ensures robust testing without side effects. * Lint fixes. * Minor tweaks. * Enhance environment export functionality to include pip dependencies - Updated the export process to append external packages (e.g., pip dependencies) when present. - Added integration tests to ensure proper inclusion of pip dependencies in both YAML and JSON export formats. - Cleared prefix data cache before export to ensure accurate results. Improves the robustness of environment exports by ensuring all relevant dependencies are captured. * Refactor tests to enhance pip package handling and reliability - Updated tests to use 'flask' as a reliable pip package for integration tests, ensuring consistent behavior in conda's test suite. - Improved assertions to verify the inclusion of pip packages and their dependencies in the environment. - Enhanced test descriptions for clarity and context. These changes improve the robustness and reliability of package extraction tests, particularly in mixed conda and pip environments. * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Update comment in environment.py for clarity on history package handling * Refactor package extraction methods in PrefixData - Removed the deprecated get_packages_by_type method, streamlining the package retrieval process. - Updated related methods to directly call get_conda_packages and get_python_packages. - Adjusted tests to reflect the changes in package extraction behavior, ensuring consistency and reliability. These changes enhance code clarity and maintainability by simplifying the package extraction logic. * Update test for environment export to verify additional channels - Changed the default channel from 'defaults' to 'conda-forge' in the export test. - Added an assertion to confirm that 'conda-forge' is included in the exported channels. These updates enhance the test's coverage of channel handling in environment exports. * Update test_get_packages_behavior_with_interoperability to remove unused parameter - Removed the unused 'test_recipes_channel' parameter from the test function. - This change simplifies the test signature and improves clarity. Enhances the maintainability of the test code by eliminating unnecessary parameters. * Lint fixes. * Apply suggestions from code review Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Apply suggestions from code review Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Refactor channel extraction logic in Environment class - Improved clarity by restructuring comments and code related to channel extraction from installed conda packages. - Ensured that the behavior of --override-channels and --ignore-channels flags is independent in the export process, validated through new tests. This enhances maintainability and correctness in environment export functionality. * Update conda/plugins/environment_exporters/explicit.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Add validation checks for explicit format export in environment exporter - Implemented error handling for exporting environments with external packages (pip) and incomplete requested packages. - Added a new test to verify that appropriate errors are raised when invalid environments are exported in explicit format. This improves the robustness of the environment export functionality by ensuring that only valid environments can be exported in explicit format. * Fix attribute access in environment exporter for explicit format - Corrected the attribute access method for `base_url` and `subdir` in the export_explicit function to use `getattr` instead of `getatter`. - This change improves the reliability of the environment export functionality by ensuring proper attribute retrieval from package objects. * Remove unused channel arguments from execute function in main_export.py * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Fix typo. * Enhance environment export functionality by overriding channel configuration - Added logic to override the environment's channel config when --override-channels is used with explicit channels, ensuring only requested channels appear in the exported environment file. - Removed unused `override_channels` parameter from the Environment class constructor for clarity and maintainability. * Update conda/models/environment.py Co-authored-by: Ken Odegard <kodegard@anaconda.com> * Add channels parameter to execute function in main_export.py - Included the channels argument in the execute function to enhance the environment export process. - This change ensures that the specified channels are considered during the export, improving the accuracy of the exported environment file. * Remove docs changes to separate branch * Remove redundant channel override logic from execute function in main_export.py to streamline the environment export process. * Update test cases to use colorama instead of flask - Replaced instances of the flask package with colorama in test_create.py, test_main_export.py, and test_prefix_data.py to ensure consistency in testing. - Adjusted assertions and comments accordingly to reflect the change in the test package. * Update news/14886-environment-export-plugin-hooks Co-authored-by: Ken Odegard <kodegard@anaconda.com> --------- Co-authored-by: Sophia Castellarin <scastellarin@quansight.com> Co-authored-by: Jonathan J. Helmus <jjhelmus@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: jaimergp <jaimergp@users.noreply.github.com> Co-authored-by: Ken Odegard <kodegard@anaconda.com>
Description
This PR introduces an env spec to represent an explicit environment. An explicit environment is one that lists out the full set of dependencies for an environment as a set of records. It is unrelated to a requirements.txt environment spec. However, both these specs might share a
.txt
file extension.A user can export an explicit environment by running
conda list --explicit
. This will produce a file like:Fixes #14684 (comment)
Checklist - did you ...
news
directory (using the template) for the next release's release notes?