Skip to content
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

Split selector logic into conda_build.selectors #5500

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion conda_build/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from frozendict import deepfreeze

from . import _load_setup_py_data
from .deprecations import deprecated
from .environ import get_dict as get_environ
from .exceptions import CondaBuildException
from .render import get_env_dependencies
Expand All @@ -39,7 +40,11 @@
import tomli as tomllib

if TYPE_CHECKING:
from typing import IO, Any
from typing import IO, Any, Callable, Sequence

from jinja2 import BaseLoader, Environment

from .config import Config

log = get_logger(__name__)

Expand Down Expand Up @@ -113,6 +118,11 @@ def _return_value(self, value=None):
return value


@deprecated(
"24.11",
"25.1",
addendum="Use `conda_build.jinja_context.FilteredChoiceLoader` instead.",
)
class FilteredLoader(jinja2.BaseLoader):
"""
A pass-through for the given loader, except that the loaded source is
Expand Down Expand Up @@ -142,6 +152,29 @@ def get_source(self, environment, template):
)


class FilteredChoiceLoader(jinja2.ChoiceLoader):
def __init__(self, loaders: Sequence[BaseLoader], config: Config) -> None:
super().__init__(loaders)
self.config = config

def get_source(
self, environment: Environment, template: str
) -> tuple[str, str | None, Callable[[], bool] | None]:
# we have circular imports here. Do a local import
from .metadata import get_selectors, select_lines

contents, filename, uptodate = super().get_source(environment, template)
return (
select_lines(
contents,
get_selectors(self.config),
variants_in_place=bool(self.config.variant),
),
filename,
uptodate,
)


def load_setup_py_data(
m,
setup_file="setup.py",
Expand Down
Loading
Loading