-
Notifications
You must be signed in to change notification settings - Fork 177
Provide metadata to easily protect environments #1149
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d315f8b
Implement frozen environment version validation and testing
Jrice1317 ae8fd52
Add metadata for frozen environments in schema
Jrice1317 f256750
Update schema for frozen environment metadata
Jrice1317 0c0646b
Write frozen files and implement installer support
Jrice1317 a3a3442
Refactor test for cleaner conflict validation
Jrice1317 52df9a4
Update news file
Jrice1317 7023b01
Apply pre-commit fixes
Jrice1317 952f910
Remove duplication
Jrice1317 a1c85a8
Add some type annotations per review suggestion
Jrice1317 cb50798
Apply suggestion from code review
Jrice1317 7bea797
Merge branch 'metadata' of https://github.com/Jrice1317/constructor i…
Jrice1317 35cedb8
Pre-commit fixes
Jrice1317 527a2b0
Replace sys exit with runtime error
Jrice1317 c61bebf
Add type annotations
Jrice1317 32b3430
Apply suggestions from code review
Jrice1317 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -105,6 +105,69 @@ def _win_install_needs_python_exe(conda_exe: str, conda_exe_type: StandaloneExe | |||||
| return results.returncode == 2 | ||||||
|
|
||||||
|
|
||||||
| # Validate frozen environments | ||||||
| def validate_frozen_envs(info, exe_type, exe_version) -> bool: | ||||||
|
Jrice1317 marked this conversation as resolved.
Outdated
|
||||||
| """Validate frozen environments. | ||||||
|
|
||||||
| Checks: | ||||||
| - No conflicts between freeze_base/freeze_env and extra_files for same environment | ||||||
| - Conda-standalone version if frozen environments exist | ||||||
| """ | ||||||
|
|
||||||
| def get_frozen_env(path) -> str | None: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(I'm assuming it's of type |
||||||
| """Extract environment name from frozen marker destination path. | ||||||
|
|
||||||
| Returns: | ||||||
| Environment name if frozen marker found in the path, otherwise None. | ||||||
| """ | ||||||
| parts = Path(path).parts | ||||||
| if parts == ("conda-meta", "frozen"): | ||||||
| return "base" | ||||||
| if len(parts) == 4 and parts[0] == "envs" and parts[-2:] == ("conda-meta", "frozen"): | ||||||
| return parts[1] | ||||||
| return None | ||||||
|
|
||||||
| # Collect environments using freeze_base/freeze_env | ||||||
| frozen_envs = set() | ||||||
| if info.get("freeze_base", {}).get("conda") is not None: | ||||||
|
Jrice1317 marked this conversation as resolved.
|
||||||
| frozen_envs.add("base") | ||||||
| for env_name, env_config in info.get("extra_envs", {}).items(): | ||||||
| if env_config.get("freeze_env", {}).get("conda") is not None: | ||||||
| frozen_envs.add(env_name) | ||||||
|
|
||||||
| # Collect environments using extra_files frozen markers | ||||||
| frozen_envs_extra_files = set() | ||||||
| paths = [] | ||||||
| for file in info.get("extra_files", ()): | ||||||
| if isinstance(file, dict): | ||||||
| paths.extend(file.values()) | ||||||
| elif isinstance(file, str): | ||||||
| paths.append(file) | ||||||
|
|
||||||
| for path in paths: | ||||||
| if env := get_frozen_env(path): | ||||||
| frozen_envs_extra_files.add(env) | ||||||
|
|
||||||
| if not frozen_envs and not frozen_envs_extra_files: | ||||||
| return | ||||||
|
|
||||||
| # Check for conflicts with extra_files | ||||||
| if common_envs := frozen_envs.intersection(frozen_envs_extra_files): | ||||||
| raise RuntimeError( | ||||||
| f"Frozen marker files found from both " | ||||||
| f"'freeze_base / freeze_env' and 'extra_files' for the following environments: {', '.join(sorted(common_envs))}" | ||||||
| ) | ||||||
|
|
||||||
| # Conda-standalone version validation | ||||||
| if exe_type == StandaloneExe.CONDA and check_version( | ||||||
| exe_version, min_version="25.5.0", max_version="25.7.0" | ||||||
| ): | ||||||
| sys.exit( | ||||||
| "Error: conda-standalone 25.5.x has known issues with frozen environments. " | ||||||
| "Please use conda-standalone 25.7.0 or newer." | ||||||
| ) | ||||||
|
Jrice1317 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
|
|
||||||
| def main_build( | ||||||
| dir_path, | ||||||
| output_dir=".", | ||||||
|
|
@@ -194,30 +257,7 @@ def main_build( | |||||
| if isinstance(info[key], str): | ||||||
| info[key] = list(yield_lines(join(dir_path, info[key]))) | ||||||
|
|
||||||
| def has_frozen_file(extra_files: list[str | dict[str, str]]) -> bool: | ||||||
| def is_conda_meta_frozen(path_str: str) -> bool: | ||||||
| path = Path(path_str) | ||||||
| return path.parts == ("conda-meta", "frozen") or ( | ||||||
| len(path.parts) == 4 | ||||||
| and path.parts[0] == "envs" | ||||||
| and path.parts[-2:] == ("conda-meta", "frozen") | ||||||
| ) | ||||||
|
|
||||||
| for file in extra_files: | ||||||
| if isinstance(file, str) and is_conda_meta_frozen(file): | ||||||
| return True | ||||||
| elif isinstance(file, dict) and any(is_conda_meta_frozen(val) for val in file.values()): | ||||||
| return True | ||||||
| return False | ||||||
|
|
||||||
| if ( | ||||||
| has_frozen_file(info.get("extra_files", [])) | ||||||
| and exe_type == StandaloneExe.CONDA | ||||||
| and check_version(exe_version, min_version="25.5.0", max_version="25.7.0") | ||||||
| ): | ||||||
| sys.exit( | ||||||
| "Error: handling conda-meta/frozen marker files requires conda-standalone newer than 25.7.x" | ||||||
| ) | ||||||
| validate_frozen_envs(info, exe_type, exe_version) | ||||||
|
|
||||||
| # normalize paths to be copied; if they are relative, they must be to | ||||||
| # construct.yaml's parent (dir_path) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,7 @@ def write_files(info: dict, workspace: str): | |
|
|
||
| - `conda-meta/initial-state.explicit.txt`: Lockfile to provision the base environment. | ||
| - `conda-meta/history`: Prepared history file with the right requested specs in input file. | ||
| - `conda-meta/frozen`: Frozen marker file used to protect conda environment state. | ||
| - `pkgs/urls` and `pkgs/urls.txt`: Direct URLs of packages used, with and without MD5 hashes. | ||
| - `pkgs/cache/*.json`: Trimmed repodata to mock offline channels in use. | ||
| - `pkgs/channels.txt`: Channels in use. | ||
|
|
@@ -199,6 +200,9 @@ def write_files(info: dict, workspace: str): | |
| # (list of specs/dists to install) | ||
| write_initial_state_explicit_txt(info, join(workspace, "conda-meta"), final_urls_md5s) | ||
|
|
||
| # base environment frozen marker files | ||
| write_frozen(info.get("freeze_base"), join(workspace, "conda-meta")) | ||
|
|
||
| for fn in files: | ||
| os.chmod(join(workspace, fn), 0o664) | ||
|
|
||
|
|
@@ -218,6 +222,8 @@ def write_files(info: dict, workspace: str): | |
| write_channels_txt(info, env_pkgs, env_config) | ||
| # shortcuts | ||
| write_shortcuts_txt(info, env_pkgs, env_config) | ||
| # frozen marker file | ||
| write_frozen(env_config.get("freeze_env"), env_conda_meta) | ||
|
|
||
|
|
||
| def write_conda_meta(info, dst_dir, final_urls_md5s, user_requested_specs=None): | ||
|
|
@@ -244,6 +250,14 @@ def write_conda_meta(info, dst_dir, final_urls_md5s, user_requested_specs=None): | |
| fh.write("\n".join(builder)) | ||
|
|
||
|
|
||
| def write_frozen(freeze_info, dst_dir): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any type annotations needed? |
||
| if not freeze_info or "conda" not in freeze_info: | ||
| return | ||
| frozen_path = join(dst_dir, "frozen") | ||
| with open(frozen_path, "w") as ff: | ||
| json.dump(freeze_info["conda"], ff) | ||
|
|
||
|
|
||
| def write_repodata_record(info, dst_dir): | ||
| all_dists = info["_dists"].copy() | ||
| for env_data in info.get("_extra_envs_info", {}).values(): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {} | ||
| {"message": "This env is frozen via extra_files."} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ### Enhancements | ||
|
|
||
| * Add support for installing [protected conda environments](https://conda.org/learn/ceps/cep-0022#specification). (#1149) | ||
|
Jrice1317 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### Bug fixes | ||
|
|
||
| * <news item> | ||
|
|
||
| ### Deprecations | ||
|
|
||
| * <news item> | ||
|
|
||
| ### Docs | ||
|
|
||
| * <news item> | ||
|
|
||
| ### Other | ||
|
|
||
| * <news item> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.