-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add env objects and missing filters
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,29 @@ | ||
from __future__ import annotations | ||
|
||
from rattler_build_conda_compat.jinja.utils import _MissingUndefined | ||
|
||
|
||
def _version_to_build_string(some_string: str | _MissingUndefined) -> str: | ||
""" | ||
Converts some version by removing the . character and returning only the first two elements of the version. | ||
If piped value is undefined, it returns the undefined value as is. | ||
""" | ||
if isinstance(some_string, _MissingUndefined): | ||
inner_value = f"{some_string._undefined_name} | version_to_build_string" # noqa: SLF001 | ||
return f"${{{{ {inner_value} }}}}" | ||
# 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 _bool(value: str) -> bool: | ||
return bool(value) | ||
|
||
|
||
def _split(s: str, sep: str = " ") -> list[str]: | ||
"""Filter that split a string by a separator""" | ||
return s.split(sep) |
This file contains 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 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,11 @@ | ||
from jinja2 import DebugUndefined | ||
|
||
|
||
class _MissingUndefined(DebugUndefined): | ||
def __str__(self) -> str: | ||
""" | ||
By default, `DebugUndefined` return values in the form `{{ value }}`. | ||
`rattler-build` has a different syntax, so we need to override this method, | ||
and return the value in the form `${{ value }}`. | ||
""" | ||
return f"${super().__str__()}" |