From 655e5bccdf5dc7163be02eb722ed3247aa191f63 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Thu, 3 Oct 2024 09:25:11 -0500 Subject: [PATCH] Remove `jinja2` checks since it is already an explicit dependency (#5497) * Remove Jinja2 checks since it is already an explicit dependency * Deprecate UnableToParseMissingJinja2 * Add news * Add test * Fix news --------- Co-authored-by: Bianca Henderson --- conda_build/exceptions.py | 3 +++ conda_build/metadata.py | 20 +----------------- .../5497-deprecate-UnableToParseMissingJinja2 | 19 +++++++++++++++++ tests/test_exceptions.py | 21 +++++++++++++++++++ 4 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 news/5497-deprecate-UnableToParseMissingJinja2 create mode 100644 tests/test_exceptions.py diff --git a/conda_build/exceptions.py b/conda_build/exceptions.py index c815b401a7..e8f51137e8 100644 --- a/conda_build/exceptions.py +++ b/conda_build/exceptions.py @@ -4,6 +4,8 @@ from conda import CondaError +from .deprecations import deprecated + SEPARATOR = "-" * 70 indent = lambda s: textwrap.fill(textwrap.dedent(s)) @@ -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( diff --git a/conda_build/metadata.py b/conda_build/metadata.py index b744a8b3c9..bb5f4607bb 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -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 @@ -30,7 +31,6 @@ DependencyNeedsBuildingError, RecipeError, UnableToParse, - UnableToParseMissingJinja2, ) from .features import feature_list from .license_family import ensure_valid_license_family @@ -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) @@ -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, diff --git a/news/5497-deprecate-UnableToParseMissingJinja2 b/news/5497-deprecate-UnableToParseMissingJinja2 new file mode 100644 index 0000000000..2093d8dc7f --- /dev/null +++ b/news/5497-deprecate-UnableToParseMissingJinja2 @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* Deprecate `conda_build.exceptions.UnableToParseMissingJinja2`. (#5497) + +### Docs + +* + +### Other + +* diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000000..c8ec13356d --- /dev/null +++ b/tests/test_exceptions.py @@ -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)()