-
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 10 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 |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class _StubEnv: | ||
"""A class to represent the env object used in rattler-build recipe.""" | ||
|
||
def get(self, env_var: str, default: str | None = None) -> str: | ||
if default: | ||
return f"""${{{{ env.get("{env_var}", default="{default}") }}}}""" | ||
|
||
return f"""${{{{ env.get("{env_var}")}}}}""" | ||
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. If I understand correctly, this just returns the jinja string as is? Fine with me. 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. made them all to return just the simple string |
||
|
||
def exists(self, env_var: str) -> str: | ||
return f"""${{{{ env.exists("{env_var}") }}}}""" | ||
|
||
|
||
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]}" | ||
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. I am not sure I understand the difference. Here you return simple string, but in other functions you return 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. made them all to return just the simple string |
||
|
||
|
||
def _stub_match(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002 | ||
return f"match {args[0]}" | ||
|
||
|
||
def _stub_is_unix(platform: str) -> str: | ||
return f"${{{{ is_unix {platform} }}}}" | ||
|
||
|
||
def _stub_is_win(platform: str) -> str: | ||
return f"${{{{ is_win {platform} }}}}" | ||
|
||
|
||
def _stub_is_linux(platform: str) -> str: | ||
return f"${{{{ is_linux {platform} }}}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from jinja2 import DebugUndefined | ||
|
||
|
||
class _MissingUndefined(DebugUndefined): | ||
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. Cant this error be returned by the functions to the user? In that case I think this thing shouldnt be private. 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. I think you should in that case also either not put it in the 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. This error is not returned to the user ( jinja is raising directly jinja2.Undefined ) and it's something specific for our error handling - that's why I would prefer to keep private |
||
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__()}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,145 @@ | ||
# serializer version: 1 | ||
# name: test_render_recipe_with_context | ||
''' | ||
about: | ||
description: '# Mamba, the Fast Cross-Platform Package Manager | ||
|
||
${{ env.get("MY_ENV_VAR")}} | ||
|
||
${{ env.get("MY_ENV_VAR", default="default_value") }} | ||
|
||
${{ env.exists("MY_ENV_VAR") }} | ||
|
||
' | ||
homepage: https://github.com/mamba-org/mamba | ||
license: BSD-3-Clause | ||
license_family: BSD | ||
license_file: LICENSE | ||
repository: https://github.com/mamba-org/mamba | ||
summary: A fast drop-in alternative to conda, using libsolv for dependency resolution | ||
build: | ||
string: ${{ blas_variant }}${{ hash }}_foo-bla | ||
number: '2' | ||
context: | ||
name: foo | ||
name_version: foo-bla | ||
version: bla | ||
package: | ||
name: foo | ||
version: bla | ||
build_number: '2' | ||
libmamba_version: 1.5.8 | ||
libmambapy_version: 1.5.8 | ||
mamba_version: 1.5.8 | ||
name: mamba | ||
release: 2024.03.25 | ||
outputs: | ||
- build: | ||
script: | ||
- build_mamba.sh | ||
- '' | ||
package: | ||
name: libmamba | ||
version: 1.5.8 | ||
requirements: | ||
build: | ||
- cxx_compiler_stub | ||
- cmake | ||
- ninja | ||
- '' | ||
host: | ||
- libsolv >=0.7.23 | ||
- libcurl >=8.4.0 | ||
- fmt | ||
- '' | ||
ignore_run_exports: | ||
by_name: | ||
- spdlog | ||
- python | ||
run: | ||
- libsolv >=0.7.23 | ||
run_exports: | ||
- subpackage_pin libmamba | ||
tests: | ||
- script: | ||
- else: | ||
- if not exist %LIBRARY_PREFIX%\include\mamba\version.hpp (exit 1) | ||
if: unix | ||
then: | ||
- test -d ${PREFIX}/include/mamba | ||
- build: | ||
script: | ||
- build_mamba.sh | ||
- '' | ||
package: | ||
name: libmambapy | ||
version: 1.5.8 | ||
requirements: | ||
build: | ||
- cxx_compiler_stub | ||
- cmake | ||
- ninja | ||
- if: build_platform != target_platform | ||
then: | ||
- python | ||
- cross-python_linux-64 | ||
- pybind11 | ||
- pybind11-abi | ||
host: | ||
- python | ||
- nlohmann_json | ||
- subpackage_pin libmamba | ||
ignore_run_exports: | ||
by_name: | ||
- spdlog | ||
run: | ||
- python | ||
- subpackage_pin libmamba | ||
run_exports: | ||
- subpackage_pin libmambapy | ||
tests: | ||
- python: | ||
imports: | ||
- libmambapy | ||
- libmambapy.bindings | ||
- script: | ||
- python -c "import libmambapy._version; assert libmambapy._version.__version__ | ||
== '1.5.8'" | ||
- build: | ||
python: | ||
entry_points: | ||
- mamba = mamba.mamba:main | ||
script: | ||
- build_mamba.sh | ||
- '' | ||
- '' | ||
string: py${{ python | version_to_build_string }}h${{ hash }}_2 | ||
package: | ||
name: mamba | ||
version: 1.5.8 | ||
requirements: | ||
build: | ||
- if: build_platform != target_platform | ||
then: | ||
- python | ||
- cross-python_linux-64 | ||
run: | ||
- python | ||
- conda >=23.9,<24 | ||
- subpackage_pin libmambapy | ||
tests: | ||
- python: | ||
imports: | ||
- mamba | ||
- script: | ||
- mamba --help | ||
- python -c "import mamba._version; assert mamba._version.__version__ == '1.5.8'" | ||
- if: linux | ||
then: | ||
- test -f ${PREFIX}/etc/profile.d/mamba.sh | ||
- mamba create -n test_py2 python=2.7 --dry-run | ||
- mamba install xtensor xsimd -c conda-forge --dry-run | ||
- if: unix | ||
then: | ||
- test -f ${PREFIX}/condabin/mamba | ||
recipe: | ||
name: mamba-split | ||
source: | ||
sha256: 6ddaf4b0758eb7ca1250f427bc40c2c3ede43257a60bac54e4320a4de66759a6 | ||
url: https://github.com/mamba-org/mamba/archive/refs/tags/2024.03.25.tar.gz | ||
|
||
''' | ||
# --- |
This file was deleted.
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 actually don't know if this is implemented in Python Jinja or not. Is it missing from Python jinja?
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.
It was missing from python jinja