Skip to content

Commit

Permalink
Merge pull request #162 from olemoign/lint
Browse files Browse the repository at this point in the history
More linting.
  • Loading branch information
mmerickel authored Nov 28, 2021
2 parents 47e7327 + a45aa26 commit 2a016f7
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 108 deletions.
14 changes: 7 additions & 7 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Backward Incompatible Changes

The fix is to include ``pyramid_jinja2``::

config.include('pyramid_jinja2')
config.include("pyramid_jinja2")

2.2 (2014-05-30)
================
Expand All @@ -128,7 +128,7 @@ Backward Incompatible Changes
only automatic search path left is the one added by the default ``.jinja2``
renderer created when including ``pyramid_jinja2``. [mmerickel]

- Adjust the ``config.include('pyramid_jinja2')`` to add any packages from
- Adjust the ``config.include("pyramid_jinja2")`` to add any packages from
``jinja2.directories`` **before** the default search path at the base of
the app. Previously there was no way to override that search path.
[mmerickel]
Expand All @@ -137,9 +137,9 @@ Backward Incompatible Changes
==================

- The path of the child template is always considered when inheriting from
a base template. Therefore when doing ``render('templates/foo.jinja2')``
and ``foo.jinja2`` has an ``{% extends 'base.jinja2' %}``, the template
will be searched for as ``'templates/base.jinja2'`` on the search path.
a base template. Therefore when doing ``render("templates/foo.jinja2")``
and ``foo.jinja2`` has an ``{% extends "base.jinja2" %}``, the template
will be searched for as ``"templates/base.jinja2"`` on the search path.
Previously the path of the child template was ignored when doing the
lookup for the base, causing some very subtle and unrecoverable lookup
errors when the child template was found relative to the caller instead
Expand All @@ -153,7 +153,7 @@ Backward Incompatible Changes
==================

- #86: Fix a regression caused by the new support for extending a template
relative to itself. Using ``{% extends 'some_asset:spec.jinja2' %}`` was
relative to itself. Using ``{% extends "some_asset:spec.jinja2" %}`` was
no longer working and is now fixed. [mmerickel]


Expand Down Expand Up @@ -260,7 +260,7 @@ Backward Incompatible Changes
of the pyramid application.
[Domen Kozar]

- Add `jinja2.globals` setting to add global objects into
- Add `jinja2.globals` setting to add global objects into
the template context
[Eugene Fominykh]

Expand Down
4 changes: 2 additions & 2 deletions demo/helloworld.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<fieldset>
<legend>I18N Demo</legend>
<dl>
<dt>No Translation (english)</dt>
<dt>No Translation (english)</dt>
<dd>Hello World</dd>
<dt>Translated using Pyramid directly</dt>
<dd>{{pyramid_translated}}</dd>
<dd>{{ pyramid_translated }}</dd>
<dt>Translated using Jinja2</dt>
<dd>{% trans %}Hello World{% endtrans %}</dd>
</dl>
Expand Down
42 changes: 20 additions & 22 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# If your extensions are in another directory, add it here. If the
# directory is relative to the documentation root, use os.path.abspath to
# make it absolute, like shown here.
# sys.path.append(os.path.abspath('some/directory'))
# sys.path.append(os.path.abspath("some/directory"))

import datetime
import pkg_resources
import pylons_sphinx_themes
import sys
import os

# General configuration
# ---------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -44,15 +44,13 @@
# other places throughout the built documents.
#
# The short X.Y version.
import pkg_resources

version = pkg_resources.get_distribution(project).version
# The full version, including alpha/beta/rc tags.
release = version

# There are two options for replacing |today|: either, you set today to
# some non-false value, then it is used:
# today = ''
# today = ""
# Else, today_fmt is used as the format for a strftime call.
today_fmt = "%B %d, %Y"

Expand All @@ -71,7 +69,7 @@
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
# If true, "()" will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
Expand All @@ -83,7 +81,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
# pygments_style = 'sphinx'
# pygments_style = "sphinx"


# Options for HTML output
Expand All @@ -100,7 +98,7 @@
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
# html_style = 'repoze.css'
# html_style = "repoze.css"

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
Expand All @@ -112,7 +110,7 @@

# The name of an image file (within the static path) to place at the top of
# the sidebar.
# html_logo = '.static/logo_hi.gif'
# html_logo = ".static/logo_hi.gif"

# The name of an image file (within the static path) to use as favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or
Expand All @@ -123,9 +121,9 @@
# here, relative to this directory. They are copied after the builtin
# static files, so a file named "default.css" will overwrite the builtin
# "default.css".
# html_static_path = ['_static']
# html_static_path = ["_static"]

# If not '', a 'Last updated on:' timestamp is inserted at every page
# If not "", a "Last updated on:" timestamp is inserted at every page
# bottom, using the given strftime format.
html_last_updated_fmt = "%b %d, %Y"

Expand Down Expand Up @@ -164,17 +162,17 @@
# If true, an OpenSearch description file will be output, and all pages
# will contain a <link> tag referring to it. The value of this option must
# be the base URL from which the finished HTML is served.
# html_use_opensearch = ''
# html_use_opensearch = ""

# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = ''
# html_file_suffix = ""

# Output file base name for HTML help builder.
htmlhelp_basename = "atemplatedoc"

# for cross referencing documentations
intersphinx_mapping = {
"jinja2": ("http://jinja.pocoo.org/docs/", None),
"jinja2": ("https://jinja.palletsprojects.com/en/latest/", None),
"pyramid": ("https://docs.pylonsproject.org/projects/pyramid/en/latest/", None),
"pyramid_zcml": (
"https://docs.pylonsproject.org/projects/pyramid_zcml/en/latest/",
Expand All @@ -187,11 +185,11 @@
# Options for LaTeX output
# ------------------------

# The paper size ('letter' or 'a4').
# latex_paper_size = 'letter'
# The paper size ("letter" or "a4").
# latex_paper_size = "letter"

# The font size ('10pt', '11pt' or '12pt').
# latex_font_size = '10pt'
# The font size ("10pt", "11pt" or "12pt").
# latex_font_size = "10pt"

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
Expand All @@ -208,14 +206,14 @@

# The name of an image file (relative to this directory) to place at the
# top of the title page.
# latex_logo = '.static/logo_hi.gif'
# latex_logo = ".static/logo_hi.gif"

# For "manual" documents, if this is true, then toplevel headings are
# parts, not chapters.
# latex_use_parts = False

# Additional stuff for the LaTeX preamble.
# latex_preamble = ''
# latex_preamble = ""

# Documents to append as an appendix to all manuals.
# latex_appendices = []
Expand Down
47 changes: 24 additions & 23 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ All are completely equivalent:
.. code-block:: python
config = Configurator()
config.include('pyramid_jinja2')
config.include("pyramid_jinja2")
#) Add ``pyramid_jinja2`` to the list of your ``pyramid.includes`` in your
:file:`.ini` settings file.
Expand Down Expand Up @@ -123,9 +123,9 @@ Here's an example view configuration which uses an :term:`asset specification`:
.. code-block:: python
:linenos:
@view_config(renderer='mypackage:templates/foo.jinja2')
@view_config(renderer="mypackage:templates/foo.jinja2")
def hello_world(request):
return {'a': 1}
return {"a": 1}
Asset specifications have some significant benefits in Pyramid, as they can be
fully overridden. An add-on package can ship with code that renders using
Expand All @@ -146,9 +146,9 @@ Let's look at an example:
.. code-block:: python
:linenos:
@view_config(renderer='templates/mytemplate.jinja2')
@view_config(renderer="templates/mytemplate.jinja2")
def my_view(request):
return {'foo': 1, 'bar': 2}
return {"foo": 1, "bar": 2}
Imagine that the above code is in a ``myapp.admin.views`` module. The template
would be relative to that module on the filesystem, as shown below:
Expand Down Expand Up @@ -176,8 +176,9 @@ entire ``templates`` folder, may be overridden.
.. code-block:: python
config.override_asset(
to_override='myapp.admin.views:templates/mytemplate.jinja2',
override_with='yourapp:templates/sometemplate.jinja2')
to_override="myapp.admin.views:templates/mytemplate.jinja2",
override_with="yourapp:templates/sometemplate.jinja2",
)
See :ref:`pyramid:overriding_assets_section` for more information.

Expand All @@ -195,9 +196,9 @@ follows:

.. code-block:: python
@view_config(renderer='mytemplate.jinja2')
@view_config(renderer="mytemplate.jinja2")
def my_view(request):
return {'foo': 1, 'bar': 2}
return {"foo": 1, "bar": 2}
If ``mytemplate.jinja2`` is not found in the same directory as the module,
then it will be searched for on the search path. We are now dependent on our
Expand Down Expand Up @@ -235,8 +236,8 @@ template names found on the search path. The search path will always be
consulted if a template cannot be found relative to the parent
template. For example, if you had a template named ``templates/child.jinja2``
that wanted to extend ``templates/base.jinja2``, then it could use
``{% extends 'base.jinja2' %}`` and locate the file relative to itself.
Alternatively it could use ``{% extends 'templates/base.jinja2' %}`` to find
``{% extends "base.jinja2" %}`` and locate the file relative to itself.
Alternatively it could use ``{% extends "templates/base.jinja2" %}`` to find
the template in a ``templates`` sub-folder rooted on the search path. The
template-relative option will always override the search path.

Expand Down Expand Up @@ -284,8 +285,8 @@ extensions using the :func:`pyramid_jinja2.add_jinja2_renderer` directive.

.. code-block:: python
config.include('pyramid_jinja2')
config.add_jinja2_renderer('.html')
config.include("pyramid_jinja2")
config.add_jinja2_renderer(".html")
It would now be possible to use templates named ``foo.html`` and
``foo.jinja2``. Each renderer extension will use its own
Expand All @@ -295,9 +296,9 @@ runtime using the ``name`` parameter to the other directives such as

.. code-block:: python
config.include('pyramid_jinja2')
config.add_jinja2_renderer('.html')
config.add_jinja2_search_path('myapp:templates', name='.html')
config.include("pyramid_jinja2")
config.add_jinja2_renderer(".html")
config.add_jinja2_search_path("myapp:templates", name=".html")
It is also possible to set up different renderers that use different search
paths, configuration settings, and environments if necessary. This technique
Expand All @@ -310,13 +311,13 @@ at a different group of settings.
.. code-block:: python
settings = {
'jinja2.directories': 'myapp:html_templates',
'mail.jinja2.directories': 'myapp:email_templates',
"jinja2.directories": "myapp:html_templates",
"mail.jinja2.directories": "myapp:email_templates",
}
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.add_jinja2_renderer('.email', settings_prefix='mail.jinja2.')
config.include("pyramid_jinja2")
config.add_jinja2_renderer(".email", settings_prefix="mail.jinja2.")
Now ``foo.email`` will be rendered using the ``mail.jinja2.*`` settings.

Expand Down Expand Up @@ -398,7 +399,7 @@ Possible values: ``true`` or ``false``.
practice in a web setting where we want to prevent XSS attacks from
rendering unsanitized user-generated content. To turn off escaping
on a case-by-case basis, you may use the ``safe`` filter such as
``{{ html_blob | safe }}``.
``{{ html_blob|safe }}``.


.. _setting_reload_templates:
Expand Down Expand Up @@ -765,8 +766,8 @@ sent with each request and set the appropriate language. For example:
request = event.request
# set locale depending on browser settings
settings = request.registry.settings
locale = settings.get('pyramid.default_locale_name', 'en')
available = [loc['code'] for loc in AVAILABLE_LOCALES]
locale = settings.get("pyramid.default_locale_name", "en")
available = [loc["code"] for loc in AVAILABLE_LOCALES]
if request.accept_language:
accepted = request.accept_language
locale = accepted.best_match(available, locale)
Expand Down
8 changes: 4 additions & 4 deletions src/pyramid_jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def resource_url_filter(ctx, model, *elements, **kw):
Example::
<a href="{{'my_traversable_object'|resource_url}}">
<a href="{{ "my_traversable_object"|resource_url }}">
See my object
</a>
You can also specify optional view name attached at the end of a path::
<a href="{{'my_traversable_object'|resource_url('edit')}}">
<a href="{{ "my_traversable_object"|resource_url("edit") }}">
Edit my object
</a>
Expand Down Expand Up @@ -65,7 +65,7 @@ def route_url_filter(ctx, route_name, *elements, **kw):
Example::
<a href="{{'login'|route_url}}">
<a href="{{ "login"|route_url }}">
Sign in
</a>
Expand All @@ -90,7 +90,7 @@ def static_url_filter(ctx, path, **kw):
Example::
<link rel="stylesheet" href="{{'yourapp:static/css/style.css'|static_url}}" />
<link rel="stylesheet" href="{{ "yourapp:static/css/style.css"|static_url }}" />
"""
request = ctx.get("request") or get_current_request()
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/baz1/middle.jinja2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% extends 'base.jinja2' %}
{% extends "base.jinja2" %}
2 changes: 1 addition & 1 deletion tests/templates/baz1/mytemplate.jinja2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends 'middle.jinja2' %}
{% extends "middle.jinja2" %}
{% block baz1_body %}baz1 body{% endblock baz1_body %}
2 changes: 1 addition & 1 deletion tests/templates/baz2/mytemplate.jinja2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends 'base.jinja2' %}
{% extends "base.jinja2" %}
{% block baz2_body %}baz2 body{% endblock baz2_body %}
4 changes: 2 additions & 2 deletions tests/templates/deep/leaf.jinja2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends 'base.jinja2' %}
{% include 'sub/nav.jinja2' %}
{% extends "base.jinja2" %}
{% include "sub/nav.jinja2" %}
{% block content %}deep-leaf{% endblock %}
2 changes: 1 addition & 1 deletion tests/templates/deep/sub/base.jinja2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends '../base.jinja2' %}
{% extends "../base.jinja2" %}
{% block content %}sub-base {% block subcontent %}{% endblock %}{% endblock %}
2 changes: 1 addition & 1 deletion tests/templates/deep/sub/leaf.jinja2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends 'base.jinja2' %}
{% extends "base.jinja2" %}
{% block subcontent %}sub-leaf{% endblock%}
2 changes: 1 addition & 1 deletion tests/templates/deep/sub/nav.jinja2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sub-nav

{% include '../forms.jinja2' %}
{% include "../forms.jinja2" %}
Loading

0 comments on commit 2a016f7

Please sign in to comment.