Skip to content

Commit

Permalink
feat: add support to run build for recipes with linux-aarch64 additio…
Browse files Browse the repository at this point in the history
…nal-platforms (#923)

This patches add support in bioconda-utils to run on linux-arm if the
following is added to the recipe:
```yaml
extra:
  additional-platforms:
    - linux-aarch64
```

- Add a `check_native_platform_skippable` to checkout should we skip the
recipes in current nativei platform
- Add `extra_additional_platforms` property to recipe object
- Add UT to test above function
```
py.test --durations=0 test/test_utils.py::test_native_platform_skipping
py.test --durations=0 test/test_recipe.py::test_recipe_extra_additional_platforms
```
- E2E test
```
bioconda-utils build recipes config.yml --git-range origin/master HEAD
bioconda-utils build recipes config.yml --git-range origin/master HEAD --force
```
- Fix test trigger by adding `fetch-depth`

related: bioconda/bioconda-recipes#40550

---------

Signed-off-by: Yikun Jiang <[email protected]>
  • Loading branch information
Yikun authored Oct 14, 2023
1 parent e8e60a3 commit 55671f7
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/GithubActionTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: set path
run: echo "/opt/mambaforge/bin" >> $GITHUB_PATH
Expand Down Expand Up @@ -52,6 +54,8 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: set path
run: echo "/opt/mambaforge/bin" >> $GITHUB_PATH
Expand Down
26 changes: 26 additions & 0 deletions bioconda_utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . import upload
from . import lint
from . import graph
from . import recipe as _recipe

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -259,6 +260,26 @@ def get_subdags(dag, n_workers, worker_offset):
return subdags


def do_not_consider_for_additional_platform(recipe_folder: str, recipe: str, platform: str):
"""
Given a recipe, check this recipe should skip in current platform or not.
Arguments:
recipe_folder: Directory containing possibly many, and possibly nested, recipes.
recipe: Relative path to recipe
platform: current native platform
Returns:
Return True if current native platform are not included in recipe's additional platforms (no need to build).
"""
recipe_obj = _recipe.Recipe.from_file(recipe_folder, recipe)
# On linux-aarch64 env, only build recipe with linux-aarch64 extra_additional_platforms
if platform == "linux-aarch64":
if "linux-aarch64" not in recipe_obj.extra_additional_platforms:
return True
return False


def build_recipes(recipe_folder: str, config_path: str, recipes: List[str],
mulled_test: bool = True, testonly: bool = False,
force: bool = False,
Expand Down Expand Up @@ -356,6 +377,11 @@ def build_recipes(recipe_folder: str, config_path: str, recipes: List[str],
failed_uploads = []

for recipe, name in recipes:
platform = utils.RepoData().native_platform()
if not force and do_not_consider_for_additional_platform(recipe_folder, recipe, platform):
logger.info("BUILD SKIP: skipping %s for additional platform %s", recipe, platform)
continue

if name in skip_dependent:
logger.info('BUILD SKIP: skipping %s because it depends on %s '
'which had a failed build.',
Expand Down
7 changes: 7 additions & 0 deletions bioconda_utils/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ def maintainers(self):
return utils.ensure_list(self.meta['extra']['recipe-maintainers'])
return []

@property
def extra_additional_platforms(self) -> list:
"""The extra additional-platforms list"""
if 'extra' in self.meta and 'additional-platforms' in self.meta['extra']:
return list(self.meta["extra"]["additional-platforms"])
return []

@property
def name(self) -> str:
"""The name of the toplevel package built by this recipe"""
Expand Down
12 changes: 12 additions & 0 deletions test/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ def test_recipe_package_names(recipe):
assert recipe.package_names == expected


@with_recipes
def test_recipe_extra_additional_platforms(recipe):
assert recipe.extra_additional_platforms == []
recipe.meta_yaml += [
'extra:',
' additional-platforms:',
' - linux-aarch64'
]
recipe.render()
assert recipe.extra_additional_platforms == ["linux-aarch64"]


@with_recipes
def test_get_deps_dict(recipe):
recipe.meta_yaml.extend([
Expand Down
36 changes: 36 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,42 @@ def test_load_meta_skipping():
assert utils.load_all_meta(recipe) == []


def test_native_platform_skipping():
expections = [
# Don't skip linux-x86 for any recipes
["one", "linux", False],
["two", "linux", False],
# Skip recipe without linux aarch64 enable on linux-aarch64 platform
["one", "linux-aarch64", True],
# Don't skip recipe with linux aarch64 enable on linux-aarch64 platform
["two", "linux-aarch64", False],
]
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
two:
meta.yaml: |
package:
name: one
version: "0.1"
extra:
additional-platforms:
- linux-aarch64
""", from_string=True)
r.write_recipes()
# Make sure RepoData singleton init
utils.RepoData.register_config(config_fixture)
for recipe_name, platform, result in expections:
recipe_folder = os.path.dirname(r.recipe_dirs[recipe_name])
assert build.do_not_consider_for_additional_platform(recipe_folder,
r.recipe_dirs[recipe_name],
platform) == result


def test_variants():
"""
Multiple variants should return multiple metadata
Expand Down

0 comments on commit 55671f7

Please sign in to comment.