-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: omit also jinja functions #37
Changes from 3 commits
3cd3fc6
73b16fa
05639ce
a47231a
af23b01
0def0e1
91085d1
bff5681
c4532f9
6cb46fe
e5d46fd
e95ef4a
479fc6c
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 |
---|---|---|
|
@@ -27,7 +27,28 @@ def jinja_env() -> jinja2.Environment: | |
""" | ||
Create a `rattler-build` specific Jinja2 environment with modified syntax. | ||
""" | ||
return jinja2.Environment( | ||
|
||
def stub_compatible_pin(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002 | ||
return f"compatible_pin {args[0]}" | ||
|
||
def stub_subpackage_pin(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002 | ||
return f"subpackage_pin {args[0]}" | ||
|
||
def version_to_build_string(some_string: str) -> str: | ||
"""Converts some version by removing the . character and returning only the first two elements of the version)""" | ||
# We first split the string by whitespace and take the first part | ||
split = some_string.split()[0] if some_string.split() else some_string | ||
# We then split the string by . and take the first two parts | ||
parts = split.split(".") | ||
major = parts[0] if len(parts) > 0 else "" | ||
minor = parts[1] if len(parts) > 1 else "" | ||
return f"{major}{minor}" | ||
|
||
def split_filter(s: str, sep: str = " ") -> list[str]: | ||
"""Filter that split a string by a separator""" | ||
return s.split(sep) | ||
|
||
env = jinja2.Environment( | ||
variable_start_string="${{", | ||
variable_end_string="}}", | ||
trim_blocks=True, | ||
|
@@ -36,6 +57,26 @@ def jinja_env() -> jinja2.Environment: | |
undefined=_MissingUndefined, | ||
) | ||
|
||
# inject rattler-build recipe functions in jinja environment | ||
env.globals.update( | ||
{ | ||
"compiler": lambda x: x + "_compiler_stub", | ||
"stdlib": lambda x: x + "_stdlib_stub", | ||
"pin_subpackage": stub_subpackage_pin, | ||
"pin_compatible": stub_compatible_pin, | ||
"cdt": lambda *args, **kwargs: "cdt_stub", # noqa: ARG005 | ||
} | ||
) | ||
|
||
# inject rattler-build recipe filters in jinja environment | ||
env.filters.update( | ||
{ | ||
"version_to_buildstring": version_to_build_string, | ||
"split": split_filter, | ||
} | ||
) | ||
return env | ||
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. Do we also need to add some stub functions for 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. All the more reason tho have an actual recipe that contains some of these corner cases. 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. that's true , added mamba_recipe as a test one |
||
|
||
|
||
def load_recipe_context(context: dict[str, str], jinja_env: jinja2.Environment) -> dict[str, str]: | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
context: | ||
name: "foo" | ||
version: "bla" | ||
version: "1.2.3" | ||
name_version: ${{ name }}-${{ version }} | ||
cuda_version: ${{ hash }}_cuda_${{ version | version_to_buildstring }} | ||
split_version: ${{ version | split('.') | join(';') }} | ||
|
||
package: | ||
name: ${{ name }} | ||
version: ${{ version }} | ||
func_result: ${{ compiler('c') }} | ||
|
||
build: | ||
string: ${{ blas_variant }}${{ hash }}_${{ name_version }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine that it would be useful to add a test for this implementation too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added!