-
Notifications
You must be signed in to change notification settings - Fork 90
Adapt version migrator for recipe.yaml #2883
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| from .build_number import DEFAULT_BUILD_PATTERNS, update_build_number # noqa | ||
| from .version import update_version # noqa | ||
| from .build_number import ( | ||
| DEFAULT_BUILD_PATTERNS as DEFAULT_BUILD_PATTERNS, | ||
| ) | ||
| from .build_number import ( | ||
| update_build_number_meta_yaml as update_build_number_meta_yaml, | ||
| ) | ||
| from .build_number import ( | ||
| update_build_number_recipe_yaml as update_build_number_recipe_yaml, | ||
| ) | ||
|
|
||
| # noqa | ||
| from .version import update_recipe_yaml_version, update_version # noqa |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import re | ||
| from typing import Callable | ||
|
|
||
| import yaml | ||
|
|
||
| DEFAULT_BUILD_PATTERNS = ( | ||
| (re.compile(r"(\s*?)number:\s*([0-9]+)"), "number: {}"), | ||
|
|
@@ -13,7 +16,11 @@ | |
| ) | ||
|
|
||
|
|
||
| def update_build_number(raw_meta_yaml, new_build_number, build_patterns=None): | ||
| def update_build_number_meta_yaml( | ||
| raw_meta_yaml: str, | ||
| new_build_number: Callable[[str], str] | str, | ||
| build_patterns=None, | ||
| ): | ||
| """Update the build number for a recipe. | ||
|
|
||
| Parameters | ||
|
|
@@ -51,3 +58,28 @@ def update_build_number(raw_meta_yaml, new_build_number, build_patterns=None): | |
| raw_meta_yaml = "\n".join(lines) + "\n" | ||
|
|
||
| return raw_meta_yaml | ||
|
|
||
|
|
||
| def update_build_number_recipe_yaml( | ||
| raw_recipe_yaml: str, new_build_number: Callable[[str], str] | str | ||
| ): | ||
| def replace_build_number(recipe, first_key, second_key): | ||
| if first := recipe.get(first_key): | ||
| if second_key in first and isinstance(first[second_key], int): | ||
| if callable(new_build_number): | ||
| first[second_key] = new_build_number(first[second_key]) | ||
| else: | ||
| first[second_key] = new_build_number | ||
|
|
||
| recipe = yaml.safe_load(raw_recipe_yaml) | ||
|
|
||
| cases = [ | ||
| ("build", "number"), | ||
| ("context", "build_number"), | ||
| ("context", "build"), | ||
| ] | ||
|
|
||
| for case in cases: | ||
| replace_build_number(recipe, *case) | ||
|
|
||
| return yaml.dump(recipe, sort_keys=False) | ||
|
Contributor
Author
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.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -379,7 +379,9 @@ def _try_to_update_version(cmeta: Any, src: str, hash_type: str): | |
| return updated_version, errors | ||
|
|
||
|
|
||
| def update_version(raw_meta_yaml, version, hash_type="sha256"): | ||
Hofer-Julian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def update_version( | ||
| raw_meta_yaml: str, version: str, hash_type: str = "sha256" | ||
| ) -> tuple[str | None, set[str]]: | ||
| """Update the version in a recipe. | ||
|
|
||
| Parameters | ||
|
|
@@ -395,7 +397,7 @@ def update_version(raw_meta_yaml, version, hash_type="sha256"): | |
| ------- | ||
| updated_meta_yaml : str or None | ||
| The updated meta.yaml. Will be None if there is an error. | ||
| errors : str of str | ||
| errors : set of str | ||
| A set of strings giving any errors found when updating the | ||
| version. The set will be empty if there were no errors. | ||
| """ | ||
|
|
@@ -527,3 +529,28 @@ def update_version(raw_meta_yaml, version, hash_type="sha256"): | |
| else: | ||
| logger.critical("Recipe did not change in version migration!") | ||
| return None, errors | ||
|
|
||
|
|
||
| def update_recipe_yaml_version( | ||
| raw_recipe_yaml: str, version: str, hash_type: str = "sha256" | ||
| ) -> tuple[str | None, set[str]]: | ||
| """Update the version in a recipe. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| raw_recipe_yaml : str | ||
| The recipe meta.yaml as a string. | ||
| version : str | ||
| The version of the recipe. | ||
| hash_type : str, optional | ||
| The kind of hash used on the source. Default is sha256. | ||
|
|
||
| Returns | ||
| ------- | ||
| updated_recipe_yaml : str or None | ||
| The updated meta.yaml. Will be None if there is an error. | ||
| errors : set of str | ||
| A set of strings giving any errors found when updating the | ||
| version. The set will be empty if there were no errors. | ||
| """ | ||
| raise NotImplementedError() | ||
|
Contributor
Author
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. This still needs to be implemented. |
||
Uh oh!
There was an error while loading. Please reload this page.