From 2c8b5c9dc6a2fd103b1170c8069091eee3e9e84f Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Wed, 18 Sep 2024 16:44:03 -0500 Subject: [PATCH 1/5] Remove Jinja2 checks since it is already an explicit dependency --- conda_build/metadata.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 071036bd0c..b32c58d988 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, From 44764e63787e1a92cf0c4a552883a4cf169d798a Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Wed, 18 Sep 2024 16:44:35 -0500 Subject: [PATCH 2/5] Deprecate UnableToParseMissingJinja2 --- conda_build/exceptions.py | 3 +++ 1 file changed, 3 insertions(+) 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( From e0a8ba4e493165911f8aff6388ce8a0936bfb3d7 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 20 Sep 2024 17:26:20 -0500 Subject: [PATCH 3/5] Add news --- news/TEMPLATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/TEMPLATE b/news/TEMPLATE index c09f3e9a4f..2093d8dc7f 100644 --- a/news/TEMPLATE +++ b/news/TEMPLATE @@ -8,7 +8,7 @@ ### Deprecations -* +* Deprecate `conda_build.exceptions.UnableToParseMissingJinja2`. (#5497) ### Docs From 36c27e5425ac36f07b1a4b2cf6c8ebc5593c356f Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 20 Sep 2024 17:28:43 -0500 Subject: [PATCH 4/5] Add test --- tests/test_exceptions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_exceptions.py 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)() From 419a988b79b97b585f0f3c2d1874563ced69fbec Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Mon, 23 Sep 2024 08:43:41 -0500 Subject: [PATCH 5/5] Fix news --- .../5497-deprecate-UnableToParseMissingJinja2 | 19 +++++++++++++++++++ news/TEMPLATE | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 news/5497-deprecate-UnableToParseMissingJinja2 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/news/TEMPLATE b/news/TEMPLATE index 2093d8dc7f..c09f3e9a4f 100644 --- a/news/TEMPLATE +++ b/news/TEMPLATE @@ -8,7 +8,7 @@ ### Deprecations -* Deprecate `conda_build.exceptions.UnableToParseMissingJinja2`. (#5497) +* ### Docs