-
Notifications
You must be signed in to change notification settings - Fork 97
Add a migrator for moving from cross to native linux_aarch64 builds
#6251
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
Open
mgorny
wants to merge
2
commits into
conda-forge:main
Choose a base branch
from
mgorny:cross-to-native
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from conda_forge_tick.contexts import ClonedFeedstockContext, FeedstockContext | ||
| from conda_forge_tick.migrators.core import Migrator | ||
| from conda_forge_tick.migrators_types import ( | ||
| AttrsTypedDict, | ||
| CondaForgeYamlContents, | ||
| MigrationUidTypedDict, | ||
| ) | ||
| from conda_forge_tick.utils import ( | ||
| yaml_safe_dump, | ||
| yaml_safe_load, | ||
| ) | ||
|
|
||
|
|
||
| class CrossToNativeMigrator(Migrator): | ||
| name = "Cross-to-native Migrator" | ||
| rerender = True | ||
| migrator_version = 1 | ||
|
|
||
| # platforms to migrate | ||
| _platforms = {"linux_aarch64"} | ||
| # build platforms where default = github_actions | ||
| _gha_platforms = {"linux_64"} | ||
|
|
||
| def _migrate_platform(self, platform: str, cfyaml: CondaForgeYamlContents) -> bool: | ||
| build_platform = cfyaml.get("build_platform", {}).get(platform) | ||
| if build_platform is None: | ||
| return False | ||
| provider = cfyaml.get("provider", {}).get(build_platform, "default") | ||
| return provider == "github_actions" or ( | ||
| provider == "default" and build_platform in self._gha_platforms | ||
| ) | ||
|
|
||
| def filter_not_in_migration( | ||
| self, attrs: AttrsTypedDict, not_bad_str_start: str = "" | ||
| ) -> bool: | ||
| if super().filter_not_in_migration(attrs, not_bad_str_start): | ||
| return True | ||
|
|
||
| # TODO: check if there are any relevant cross-targets | ||
| cfyaml = attrs.get("conda-forge.yml", {}) | ||
| for platform in self._platforms: | ||
| if self._migrate_platform(platform, cfyaml): | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def migrate( | ||
| self, recipe_dir: str, attrs: AttrsTypedDict, **kwargs: Any | ||
| ) -> MigrationUidTypedDict: | ||
| # Only v0 recipes are supported, the handful of v1 recipes is not worth the complexity. | ||
| recipe_file = next( | ||
| filter( | ||
| lambda x: x.exists(), | ||
| (Path(recipe_dir) / "recipe.yaml", Path(recipe_dir) / "meta.yaml"), | ||
| ) | ||
| ) | ||
| self.set_build_number(recipe_file) | ||
|
|
||
| cfyaml_path = Path(recipe_dir) / "../conda-forge.yml" | ||
| with open(cfyaml_path) as fp: | ||
| cfyaml = yaml_safe_load(fp) | ||
|
|
||
| for platform in self._platforms: | ||
| if not self._migrate_platform(platform, cfyaml): | ||
| continue | ||
|
|
||
| del cfyaml["build_platform"][platform] | ||
| cfyaml.setdefault("provider", {})[platform] = "default" | ||
|
|
||
| with open(cfyaml_path, "w") as fp: | ||
| yaml_safe_dump(cfyaml, fp) | ||
| return self.migrator_uid(attrs) | ||
|
|
||
| def pr_body( | ||
| self, feedstock_ctx: ClonedFeedstockContext, add_label_text: bool = True | ||
| ) -> str: | ||
| body = super().pr_body(feedstock_ctx) | ||
| body = body.format( | ||
| f"""\ | ||
| GitHub Actions provide native runners for {", ".join(self._platforms)} builds. | ||
| This migrator will attempt to switch from cross-compilation to native build. | ||
| """ | ||
| ) | ||
| return body | ||
|
|
||
| def commit_message(self, feedstock_ctx: FeedstockContext) -> str: | ||
| return "Migrate cross-compilation to native build" | ||
|
|
||
| def pr_title(self, feedstock_ctx: FeedstockContext) -> str: | ||
| return "Migrate cross-compilation to native build" | ||
|
|
||
| def remote_branch(self, feedstock_ctx: FeedstockContext) -> str: | ||
| return f"cross-to-native-{self.migrator_version}" | ||
|
|
||
| def migrator_uid(self, attrs: AttrsTypedDict) -> MigrationUidTypedDict: | ||
| if self.name is None: | ||
| raise ValueError("name is None") | ||
| n = super().migrator_uid(attrs) | ||
| n["name"] = self.name | ||
| return n | ||
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,123 @@ | ||
| import networkx as nx | ||
| import pytest | ||
| from test_migrators import run_test_migration | ||
|
|
||
| from conda_forge_tick.migrators import CrossToNativeMigrator | ||
|
|
||
| TOTAL_GRAPH = nx.DiGraph() | ||
| TOTAL_GRAPH.graph["outputs_lut"] = {} | ||
| cross_to_native_migrator = CrossToNativeMigrator(total_graph=TOTAL_GRAPH) | ||
|
|
||
|
|
||
| TEST_YAML = """\ | ||
| {% set version = "1.2.3" %} | ||
| {% set build = @BUILD@ %} | ||
|
|
||
| package: | ||
| name: test | ||
| version: {{ version }} | ||
|
|
||
| build: | ||
| number: {{ build }} | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("provider", [None, "default", "github_actions"]) | ||
| def test_cross_to_native(tmp_path, provider: str | None): | ||
| """Test successfully migrating cross to native.""" | ||
| input_yaml = """\ | ||
| build_platform: | ||
| linux_aarch64: linux_64 | ||
| linux_ppc64le: linux_64 | ||
| osx_arm64: osx_64 | ||
| win_arm64: win_64 | ||
| """ | ||
| if provider is not None: | ||
| input_yaml += f"""\ | ||
| provider: | ||
| linux_64: {provider} | ||
| """ | ||
|
|
||
| cfyaml = tmp_path / "conda-forge.yml" | ||
| cfyaml.write_text(input_yaml) | ||
|
|
||
| run_test_migration( | ||
| m=cross_to_native_migrator, | ||
| inp=TEST_YAML.replace("@BUILD@", "1"), | ||
| output=TEST_YAML.replace("@BUILD@", "2"), | ||
| prb="GitHub Actions provide native runners for linux_aarch64 builds", | ||
| kwargs={}, | ||
| mr_out={ | ||
| "migrator_name": "CrossToNativeMigrator", | ||
| "migrator_version": 1, | ||
| "name": "Cross-to-native Migrator", | ||
| }, | ||
| tmp_path=tmp_path, | ||
| ) | ||
|
|
||
| expected_providers = "" | ||
| if provider is not None: | ||
| expected_providers += f" linux_64: {provider}\n" | ||
|
|
||
| assert ( | ||
| cfyaml.read_text() | ||
| == f"""\ | ||
| build_platform: | ||
| linux_ppc64le: linux_64 | ||
| osx_arm64: osx_64 | ||
| win_arm64: win_64 | ||
| provider: | ||
| {expected_providers}\ | ||
| linux_aarch64: default | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("provider_platform", ["linux_64", "linux_aarch64"]) | ||
| def test_no_cross(tmp_path, provider_platform: str): | ||
| """Test package with no aarch64 build and with native aarch64 build.""" | ||
| input_yaml = f"""\ | ||
| provider: | ||
| {provider_platform}: default | ||
| """ | ||
|
|
||
| cfyaml = tmp_path / "conda-forge.yml" | ||
| cfyaml.write_text(input_yaml) | ||
|
|
||
| run_test_migration( | ||
| m=cross_to_native_migrator, | ||
| inp=TEST_YAML.replace("@BUILD@", "1"), | ||
| output="", | ||
| prb=None, | ||
| kwargs={}, | ||
| mr_out=None, | ||
| tmp_path=tmp_path, | ||
| should_filter=True, | ||
| ) | ||
|
|
||
|
|
||
| def test_azure(tmp_path): | ||
| """Test package using non-GHA runner.""" | ||
| input_yaml = """\ | ||
| build_platform: | ||
| linux_aarch64: linux_64 | ||
| linux_ppc64le: linux_64 | ||
| osx_arm64: osx_64 | ||
| win_arm64: win_64 | ||
| provider: | ||
| linux_64: azure | ||
| """ | ||
|
|
||
| cfyaml = tmp_path / "conda-forge.yml" | ||
| cfyaml.write_text(input_yaml) | ||
|
|
||
| run_test_migration( | ||
| m=cross_to_native_migrator, | ||
| inp=TEST_YAML.replace("@BUILD@", "1"), | ||
| output="", | ||
| prb=None, | ||
| kwargs={}, | ||
| mr_out=None, | ||
| tmp_path=tmp_path, | ||
| should_filter=True, | ||
| ) |
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.