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

Remove jinja2 checks since it is already an explicit dependency #5497

Merged
merged 10 commits into from
Oct 3, 2024
3 changes: 3 additions & 0 deletions conda_build/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from conda import CondaError

from .deprecations import deprecated

SEPARATOR = "-" * 70

indent = lambda s: textwrap.fill(textwrap.dedent(s))
Expand Down Expand Up @@ -44,6 +46,7 @@ def indented_exception(self):
return f"Error Message:\n--> {indent(orig)}\n\n"


@deprecated("24.11", "25.1")
class UnableToParseMissingJinja2(UnableToParse):
def error_body(self):
return "\n".join(
Expand Down
20 changes: 1 addition & 19 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from os.path import isdir, isfile, join
from typing import TYPE_CHECKING, NamedTuple, overload

import jinja2
import yaml
from bs4 import UnicodeDammit
from conda.base.context import locate_prefix_by_name
Expand All @@ -30,7 +31,6 @@
DependencyNeedsBuildingError,
RecipeError,
UnableToParse,
UnableToParseMissingJinja2,
)
from .features import feature_list
from .license_family import ensure_valid_license_family
Expand Down Expand Up @@ -358,13 +358,6 @@ def yamlize(data):
try:
return yaml.load(data, Loader=StringifyNumbersLoader)
except yaml.error.YAMLError as e:
if "{{" in data:
try:
import jinja2

jinja2 # Avoid pyflakes failure: 'jinja2' imported but unused
except ImportError:
raise UnableToParseMissingJinja2(original=e)
print("Problematic recipe:", file=sys.stderr)
print(data, file=sys.stderr)
raise UnableToParse(original=e)
Expand Down Expand Up @@ -1918,17 +1911,6 @@ def _get_contents(
permit_undefined_jinja: If True, *any* use of undefined jinja variables will
evaluate to an emtpy string, without emitting an error.
"""
try:
import jinja2
except ImportError:
print("There was an error importing jinja2.", file=sys.stderr)
print(
"Please run `conda install jinja2` to enable jinja template support",
file=sys.stderr,
) # noqa
with open(self.meta_path) as fd:
return fd.read()

from .jinja_context import (
FilteredLoader,
UndefinedNeverFail,
Expand Down
19 changes: 19 additions & 0 deletions news/5497-deprecate-UnableToParseMissingJinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### Deprecations

* Deprecate `conda_build.exceptions.UnableToParseMissingJinja2`. (#5497)

### Docs

* <news item>

### Other

* <news item>
21 changes: 21 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

from contextlib import nullcontext

import pytest

from conda_build import exceptions


@pytest.mark.parametrize(
"function,raises",
[
("UnableToParseMissingJinja2", TypeError),
],
)
def test_deprecations(function: str, raises: type[Exception] | None) -> None:
raises_context = pytest.raises(raises) if raises else nullcontext()
with pytest.deprecated_call(), raises_context:
getattr(exceptions, function)()
Loading