From 17e6b66a77ab0c88eff3bc472f22aa127444caf1 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 14 Mar 2022 23:27:37 -0500 Subject: [PATCH 1/2] test old jinja2 and 3.x --- .github/workflows/ci-tests.yml | 2 ++ CHANGES.rst | 9 +++++++++ src/pyramid_jinja2/filters.py | 7 ++++++- tox.ini | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 2da6f78..6b6f9eb 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -58,6 +58,8 @@ jobs: - "pyramid19" - "pyramid110" - "pyramid20" + - "pyramid110-jinja2legacy" + - "pyramid20-jinja2legacy" name: "Python: py39-${{ matrix.pyramid }}" runs-on: ubuntu-latest steps: diff --git a/CHANGES.rst b/CHANGES.rst index 8206e55..cbdf6a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,12 @@ +unreleased +========== + +- Support Jinja2 >= 3.0. + +- Only import ``jinja2.pass_context`` if available on Jinja2 >= 3.0, otherwise + fallback to ``jinja2.contextfilter``. + See https://github.com/Pylons/pyramid_jinja2/pull/164 + 2.9.1 (2022-03-12) ================== diff --git a/src/pyramid_jinja2/filters.py b/src/pyramid_jinja2/filters.py index 76a4d96..6dbb936 100644 --- a/src/pyramid_jinja2/filters.py +++ b/src/pyramid_jinja2/filters.py @@ -1,7 +1,12 @@ -from jinja2 import pass_context from pyramid.threadlocal import get_current_request from pyramid.url import resource_url, route_path, route_url, static_path, static_url +try: + from jinja2 import pass_context +except ImportError: + # jinja2 < 3.0 fallback + from jinja2 import contextfilter as pass_context + __all__ = [ "resource_url_filter", "model_url_filter", diff --git a/tox.ini b/tox.ini index edf396a..2ebdff5 100644 --- a/tox.ini +++ b/tox.ini @@ -20,6 +20,8 @@ deps = pyramid19: pyramid <= 1.9.99 pyramid110: pyramid <= 1.10.99 pyramid20: pyramid <= 2.0.99 + jinja2legacy: jinja2 < 3.0 + jinja2legacy: markupsafe < 2.0 extras = testing setenv = From 26d0fe484c413cc7d6d4cf7b6b6507a114db7e97 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 14 Mar 2022 23:57:18 -0500 Subject: [PATCH 2/2] fix coverage --- .github/workflows/ci-tests.yml | 8 ++++---- setup.cfg | 2 +- tox.ini | 9 ++------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 6b6f9eb..e9dc484 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -60,18 +60,18 @@ jobs: - "pyramid20" - "pyramid110-jinja2legacy" - "pyramid20-jinja2legacy" - name: "Python: py39-${{ matrix.pyramid }}" + name: "Python: py310-${{ matrix.pyramid }}" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup python uses: actions/setup-python@v2 with: - python-version: "3.9" + python-version: "3.10" architecture: x64 - run: pip install tox - name: Running tox - run: tox -e py39-${{ matrix.pyramid }} + run: tox -e py310-${{ matrix.pyramid }} coverage: runs-on: ubuntu-latest name: Validate coverage @@ -84,7 +84,7 @@ jobs: architecture: x64 - run: pip install tox - - run: tox -e py310-cover,coverage + - run: tox -e py310,py310-jinja2legacy,coverage docs: runs-on: ubuntu-latest name: Build the documentation diff --git a/setup.cfg b/setup.cfg index 471ffaa..617c7b4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,4 +66,4 @@ python_files = test_*.py testpaths = demo tests -addopts = -W always +addopts = -W always --cov diff --git a/tox.ini b/tox.ini index 2ebdff5..5b27f20 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,8 @@ envlist = lint, py37,py38,py39,py310,pypy3, py39-pyramid{13,14,15,16,17,18,110,20}, - py310-cover,coverage, + py39-jinja2legacy, + coverage, docs [testenv] @@ -27,11 +28,6 @@ extras = setenv = COVERAGE_FILE=.coverage.{envname} -[testenv:py310-cover] -commands = - python --version - pytest --cov {posargs:} - [testenv:coverage] commands = coverage combine @@ -41,7 +37,6 @@ deps = coverage setenv = COVERAGE_FILE=.coverage -depends = py310-cover [testenv:docs] whitelist_externals = make