Merge branch '2.10.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 6257019, e74640b · Browse files · 11 files·+171 added−110 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+171 added−110 removed
- tests:+43 added−1 removed
- other:+128 added−109 removed
Provenance
- Commit
13cc9f4- Tree
42f82f0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
6257019- Parent 2
e74640b
11 files changed+171 added−110 removed
modified:docs/api.rst+2 added-2 removed
45 unmodified lines46 template = env.get_template('mytemplate.html')47 48 To render it with some variables, just call the :meth:`render` method::49 50- print template.render(the='variables', go='here')50+ print(template.render(the='variables', go='here'))51 52 Using a template loader rather than passing strings to :class:`Template`53 or :meth:`Environment.from_string` has multiple advantages. Besides being54 a lot easier to use it also enables template inheritance.781 unmodified lines836 837 def is_prime(n):838 if n == 2:839 return True840- for i in xrange(2, int(math.ceil(math.sqrt(n))) + 1):840+ for i in range(2, int(math.ceil(math.sqrt(n))) + 1):841 if n % i == 0:842 return False843 return True844 91 unmodified linesmodified:docs/faq.rst+1 added-2 removed
151 unmodified lines152 153 Python 2.3 is missing a lot of features that are used heavily in Jinja2. This154 decision was made as with the upcoming Python 2.6 and 3.0 versions it becomes155 harder to maintain the code for older Python versions. If you really need156-Python 2.3 support you either have to use `Jinja 1`_ or other templating156+Python 2.3 support you either have to use Jinja 1 or other templating157 engines that still support 2.3.158 159 Python 2.4/2.5/3.1/3.2 support was removed when we switched to supporting160 Python 2 and 3 by the same sourcecode (without using 2to3). It was required to30 unmodified lines191 templates passing information to the parent template. To avoid this192 issue rename the macro or variable in the parent template to have an193 uncommon prefix.194 195-.. _Jinja 1: http://jinja.pocoo.org/1/modified:docs/templates.rst+26 added-3 removed
393 unmodified lines394 this template "extends" another template. When the template system evaluates395 this template, it first locates the parent. The extends tag should be the396 first tag in the template. Everything before it is printed out normally and397 may cause confusion. For details about this behavior and how to take398-advantage of it, see :ref:`null-master-fallback`.398+advantage of it, see :ref:`null-master-fallback`. Also a block will always be399+filled in regardless of whether the surrounding condition is evaluated to be true 400+or false.401 402 The filename of the template depends on the template loader. For example, the403 :class:`FileSystemLoader` allows you to access other templates by giving the404 filename. You can access templates in subdirectories with a slash::208 unmodified lines613 As variables in templates retain their object properties, it is possible to614 iterate over containers like `dict`::615 616 <dl>615- {% for key, value in my_dict.iteritems() %}617+ {% for key, value in my_dict.items() %}618 <dt>{{ key|e }}</dt>619 <dd>{{ value|e }}</dd>620 {% endfor %}621 </dl>615 unmodified lines1237 1238 /1239 Divide two numbers. The return value will be a floating point number.1240 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.1239- (Just like ``from __future__ import division``.)1241 1242 //1243 Divide two numbers and return the truncated integer result.1244 ``{{ 20 // 7 }}`` is ``2``.111 unmodified lines1356 1357 {{ ('[%s]' % page.title) if page.title }}1358 1359 1360+.. _python-methods:1361+1362+Python Methods1363+~~~~~~~~~~~~~~1364+1365+You can also use any of the methods of defined on a variable's type.1366+The value returned from the method invocation is used as the value of the expression.1367+Here is an example that uses methods defined on strings (where ``page.title`` is a string):1368+1369+.. code-block:: text1370+1371+ {{ page.title.capitalize() }}1372+1373+This also works for methods on user-defined types.1374+For example, if variable ``f`` of type ``Foo`` has a method ``bar`` defined on it,1375+you can do the following:1376+1377+.. code-block:: text1378+1379+ {{ f.bar() }}1380+1381+1382 .. _builtin-filters:1383 1384 List of Builtin Filters1385 -----------------------374 unmodified linesmodified:tests/conftest.py+43 added-1 removed
14 unmodified lines15 from jinja2.utils import have_async_gen16 from jinja2 import Environment17 18 19-def pytest_ignore_collect(path, config):19+def pytest_ignore_collect(path):20 if 'async' in path.basename and not have_async_gen:21 return True22 return False23 24 25+def pytest_configure(config):26+ '''Register custom marks for test categories.'''27+ custom_markers = [28+ 'api',29+ 'byte_code_cache',30+ 'core_tags',31+ 'debug',32+ 'escapeUrlizeTarget',33+ 'ext',34+ 'extended',35+ 'filter',36+ 'for_loop',37+ 'helpers',38+ 'if_condition',39+ 'imports',40+ 'includes',41+ 'inheritance',42+ 'lexer',43+ 'lexnparse',44+ 'loaders',45+ 'lowlevel',46+ 'lrucache',47+ 'lstripblocks',48+ 'macros',49+ 'meta',50+ 'moduleloader',51+ 'parser',52+ 'regression',53+ 'sandbox',54+ 'set',55+ 'streaming',56+ 'syntax',57+ 'test_tests',58+ 'tokenstream',59+ 'undefined',60+ 'utils',61+ 'with_',62+ ]63+ for mark in custom_markers:64+ config.addinivalue_line('markers', mark + ': test category')65+66+67 @pytest.fixture68 def env():69 '''returns a new environment.70 '''49 unmodified linesadded:.azure-pipelines.yml+61 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061trigger: - master - '*.x'
variables: vmImage: ubuntu-latest python.version: 3.7 TOXENV: py,coverage-ci hasTestResults: true
strategy: matrix: Python 3.7 Linux: vmImage: ubuntu-latest Python 3.7 Windows: vmImage: windows-latest Python 3.7 Mac: vmImage: macos-latest PyPy 3 Linux: python.version: pypy3 Python 3.6 Linux: python.version: 3.6 Python 3.5 Linux: python.version: 3.5 Python 2.7 Linux: python.version: 2.7 Python 2.7 Windows: python.version: 2.7 vmImage: windows-latest Docs: TOXENV: docs-html hasTestResults: false
pool: vmImage: $[ variables.vmImage ]
steps: - task: UsePythonVersion@0 inputs: versionSpec: $(python.version) displayName: Use Python $(python.version)
- script: pip --disable-pip-version-check install -U tox displayName: Install tox
- script: tox -s false -- --junit-xml=test-results.xml displayName: Run tox
- task: PublishTestResults@2 inputs: testResultsFiles: test-results.xml testRunTitle: $(Agent.JobName) condition: eq(variables['hasTestResults'], 'true') displayName: Publish test results
- task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: Cobertura summaryFileLocation: coverage.xml condition: eq(variables['hasTestResults'], 'true') displayName: Publish coverage resultsdeleted:.coveragerc-11 removed
1-[run]2-branch = True3-source =4- jinja25- tests6-7-[paths]8-source =9- jinja210- .tox/*/lib/python*/site-packages/jinja211- .tox/pypy/site-packages/jinja2deleted:.travis.yml-46 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546dist: xenialsudo: falselanguage: python
python: - 3.7 - 3.6 - 3.5 - 3.4 - 2.7 - pypy3.5-6.0 - pypy2.7-6.0
env: - TOXENV=py,codecov
matrix: include: - python: nightly env: TOXENV=py - python: 3.6 env: TOXENV=docs-html
install: - pip install tox
script: - tox
cache: - pip
branches: only: - master - /^.*-maintenance$/
notifications: email: false irc: channels: - "chat.freenode.net#pocoo" on_success: change on_failure: always use_notice: true skip_join: truemodified:CHANGES.rst+7 added
19 unmodified lines20 .. _#765: https://github.com/pallets/jinja/issues/76521 .. _#977: https://github.com/pallets/jinja/issues/97722 23 24+Version 2.10.225+--------------26+27+_Unreleased_28+29+- Fix Python 3.7 deprecation warnings.30+31 Version 2.10.132 --------------33 34 Released 2019-04-06598 unmodified linesdeleted:Makefile-21 removed
1-test:2- py.test tests --tb=short3-4-develop:5- pip install --editable .6-7-tox-test:8- @tox9-10-release:11- python scripts/make-release.py12-13-upload-docs:14- $(MAKE) -C docs html dirhtml latex15- $(MAKE) -C docs/_build/latex all-pdf16- cd docs/_build/; mv html jinja-docs; zip -r jinja-docs.zip jinja-docs; mv jinja-docs html17- scp -r docs/_build/dirhtml/* flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/18- scp -r docs/_build/latex/Jinja2.pdf flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/jinja-docs.pdf19- scp -r docs/_build/jinja-docs.zip flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/20-21-.PHONY: testmodified:setup.cfg+15 added-4 removed
1-[bdist_wheel]2-universal = 13-1 [metadata]2 license_file = LICENSE3 4+[bdist_wheel]5+universal = true6+7 [tool:pytest]8-minversion = 3.08 testpaths = tests9+10+[coverage:run]11+branch = True12+source =13+ jinja214+ tests15+16+[coverage:paths]17+source =18+ src/jinja219+ .tox/*/lib/python*/site-packages/jinja220+ .tox/*/site-packages/jinja2modified:tox.ini+16 added-20 removed
1 [tox]2 envlist =3- py{37,36,35,34,27,py3,py}3+ py{37,36,35,27,py3,py}4 docs-html5- coverage-report5+ coverage6+skip_missing_interpreters = true7 8 [testenv]8-passenv = LANG9-usedevelop = true9 deps =11- pytest>=310 coverage11+ pytest12+commands = coverage run -p -m pytest --tb=short -Werror --basetemp={envtmpdir} {posargs}13 14-commands = coverage run -p -m pytest {posargs}15-14 [testenv:docs-html]17-deps = sphinx18-commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html15+deps =16+ Sphinx17+ Pallets-Sphinx-Themes18+ sphinx-issues19+commands = sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html20 20-[testenv:docs-linkcheck]21-deps = sphinx22-commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/linkcheck23-24-[testenv:coverage-report]21+[testenv:coverage]22 deps = coverage23 skip_install = true24 commands =25 coverage combine29- coverage report26 coverage html27+ coverage report28 32-[testenv:codecov]33-passenv = CI TRAVIS TRAVIS_*34-deps = codecov29+[testenv:coverage-ci]30+deps = coverage31 skip_install = true32 commands =33 coverage combine38- coverage report39- codecov34+ # Ignoring errors because 2.7.15 and 3.5.5 on Azure can't parse async files.35+ coverage xml --ignore-errors