Skip to content

Commit

Permalink
Merge pull request #164 from Pylons/jinja2-fallback
Browse files Browse the repository at this point in the history
test old jinja2 and 3.x
  • Loading branch information
digitalresistor authored Mar 15, 2022
2 parents eed807a + 26d0fe4 commit b16e54d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ jobs:
- "pyramid19"
- "pyramid110"
- "pyramid20"
name: "Python: py39-${{ matrix.pyramid }}"
- "pyramid110-jinja2legacy"
- "pyramid20-jinja2legacy"
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
Expand All @@ -82,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
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
==================

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ python_files = test_*.py
testpaths =
demo
tests
addopts = -W always
addopts = -W always --cov
7 changes: 6 additions & 1 deletion src/pyramid_jinja2/filters.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 4 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -20,16 +21,13 @@ 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 =
COVERAGE_FILE=.coverage.{envname}

[testenv:py310-cover]
commands =
python --version
pytest --cov {posargs:}

[testenv:coverage]
commands =
coverage combine
Expand All @@ -39,7 +37,6 @@ deps =
coverage
setenv =
COVERAGE_FILE=.coverage
depends = py310-cover

[testenv:docs]
whitelist_externals = make
Expand Down

0 comments on commit b16e54d

Please sign in to comment.