Skip to content

Commit

Permalink
misc: make stub behave the same
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Aug 1, 2024
1 parent 6cb46fe commit e5d46fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/rattler_build_conda_compat/jinja/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def _version_to_build_string(some_string: str | _MissingUndefined) -> str:
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} }}}}"
return f"{some_string._undefined_name}_version_to_build_string" # noqa: SLF001
# 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
Expand Down
17 changes: 7 additions & 10 deletions src/rattler_build_conda_compat/jinja/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
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}")}}}}"""
def get(self, env_var: str, _default: str | None = None) -> str:
return f"""env_"{env_var}" """

def exists(self, env_var: str) -> str:
return f"""${{{{ env.exists("{env_var}") }}}}"""
return f"""env_exists_"{env_var}" """


def _stub_compatible_pin(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002
return f"${{{{ compatible_pin {args[0]} }}}}"
return f"compatible_pin {args[0]}"


def _stub_subpackage_pin(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002
Expand All @@ -27,12 +24,12 @@ def _stub_match(*args, **kwargs) -> str: # noqa: ARG001, ANN003, ANN002


def _stub_is_unix(platform: str) -> str:
return f"${{{{ is_unix {platform} }}}}"
return f"is_unix {platform}"


def _stub_is_win(platform: str) -> str:
return f"${{{{ is_win {platform} }}}}"
return f"is_win {platform}"


def _stub_is_linux(platform: str) -> str:
return f"${{{{ is_linux {platform} }}}}"
return f"is_linux {platform}"
8 changes: 4 additions & 4 deletions tests/__snapshots__/test_jinja.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
about:
description: '# Mamba, the Fast Cross-Platform Package Manager

${{ env.get("MY_ENV_VAR")}}
env_"MY_ENV_VAR

${{ env.get("MY_ENV_VAR", default="default_value") }}
env_"MY_ENV_VAR

${{ env.exists("MY_ENV_VAR") }}
env_exists_"MY_ENV_VAR

'
homepage: https://github.com/mamba-org/mamba
Expand Down Expand Up @@ -106,7 +106,7 @@
- build_mamba.sh
- ''
- ''
string: py${{ python | version_to_build_string }}h${{ hash }}_2
string: pypython_version_to_build_stringh${{ hash }}_2
package:
name: mamba
version: 1.5.8
Expand Down
2 changes: 1 addition & 1 deletion tests/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def test_version_to_build_string() -> None:
assert _version_to_build_string("1.2") == "12"
assert _version_to_build_string("nothing") == "nothing"
some_undefined = _MissingUndefined(name="python")
assert _version_to_build_string(some_undefined) == "${{ python | version_to_build_string }}"
assert _version_to_build_string(some_undefined) == "python_version_to_build_string"

0 comments on commit e5d46fd

Please sign in to comment.