Skip to content

Commit

Permalink
feat: add has_recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Apr 18, 2024
1 parent a5d1cdd commit 4147314
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/rattler_build_conda_compat/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fnmatch
from logging import getLogger
import os
from pathlib import Path
from typing import Iterable


Expand Down Expand Up @@ -158,3 +159,21 @@ def find_recipe(path):
raise OSError(
"More than one meta files ({}) found in {}".format(", ".join(VALID_METAS), path)
)


def has_recipe(recipe_dir: Path) -> bool:
"""
verify if recipe_dir contains recipe.yaml
it is used to detect whetever old or recipe should be used
"""
try:
recipe_path = find_recipe(recipe_dir)
if recipe_path:
return True
return False
except OSError:
return False
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ def unix_namespace():
namespace = {"linux-64": True, "unix": True}

return namespace


@pytest.fixture
def recipe_dir(tmpdir):
py_recipe = Path("tests/data/py_recipe.yaml").read_text()
recipe_dir = tmpdir / "recipe"
mkdir(recipe_dir)

(recipe_dir / "recipe.yaml").write_text(py_recipe, encoding="utf8")

yield recipe_dir


@pytest.fixture
def old_recipe_dir(tmpdir):
recipe_dir = tmpdir / "recipe"
mkdir(recipe_dir)

meta = Path(recipe_dir / "meta.yaml")
meta.touch()

yield recipe_dir
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rattler_build_conda_compat.utils import has_recipe


def test_recipe_is_present(recipe_dir):
assert has_recipe(recipe_dir)


def test_recipe_is_absent(old_recipe_dir):
assert has_recipe(old_recipe_dir) is False

0 comments on commit 4147314

Please sign in to comment.