Skip to content

Commit

Permalink
Remove jinja2 checks since it is already an explicit dependency (#5497
Browse files Browse the repository at this point in the history
)

* Remove Jinja2 checks since it is already an explicit dependency

* Deprecate UnableToParseMissingJinja2

* Add news

* Add test

* Fix news

---------

Co-authored-by: Bianca Henderson <bhenderson@anaconda.com>
  • Loading branch information
kenodegard and beeankha authored Oct 3, 2024
1 parent 0ef3749 commit 655e5bc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
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)()

0 comments on commit 655e5bc

Please sign in to comment.