Skip to content

Commit

Permalink
add recipe.contains
Browse files Browse the repository at this point in the history
  • Loading branch information
cbouss committed Jun 2, 2023
1 parent 01ef349 commit af7bc03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: percy
version: 0.0.2
version: 0.0.3

source:
path: ../
Expand Down
29 changes: 29 additions & 0 deletions percy/render/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,35 @@ def get(self, path: str, default: Any = KeyError) -> Any:
return default
return res

def contains(self, path: str, value: str, default: Any = KeyError) -> bool:
"""Check if a value (string or list) contains a string
>>> recipe.contains('build/script', 'pip')
True
The **path** is a ``/`` separated list of dictionary keys to
be walked in the recipe meta data. Numeric sections in the path
access list elements. Using ``0`` in the path will get the first
element in a list or the contents directly if there is no list.
I.e., `source/0/url` will always get the first url, whether or
not the source section is a list.
Args:
path: Path through YAML
value: The string to match
default: If not KeyError, this value will be returned
if the path does not exist in the recipe
Returns:
Value match (bool).
Raises:
KeyError if no default given and the path does not exist.
"""
res = self.get(path, default)
if isinstance(res, str):
return value in res
if isinstance(res, list):
for r in res:
if value in r:
return True
return False


class Dep:
"""A dependency
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "percy"
version = "0.0.2"
version = "0.0.3"
authors = [
{ name="Anaconda, Inc.", email="distribution_team@anaconda.com" },
]
Expand Down

0 comments on commit af7bc03

Please sign in to comment.