Skip to content

Commit

Permalink
chore: strip out whitespace added by jinja blocks (pypi#14709)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Oct 10, 2023
1 parent 238e21f commit 8949061
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ def __init__(self):
assert configurator_obj.add_settings.calls == [
pretend.call({"jinja2.newstyle": True}),
pretend.call({"jinja2.i18n.domain": "messages"}),
pretend.call({"jinja2.lstrip_blocks": True}),
pretend.call({"jinja2.trim_blocks": True}),
pretend.call({"retry.attempts": 3}),
pretend.call(
{
Expand All @@ -413,7 +415,7 @@ def __init__(self):
),
pretend.call({"http": {"verify": "/etc/ssl/certs/"}}),
]
add_settings_dict = configurator_obj.add_settings.calls[3].args[0]
add_settings_dict = configurator_obj.add_settings.calls[5].args[0]
assert add_settings_dict["tm.manager_hook"](pretend.stub()) is transaction_manager
assert configurator_obj.add_tween.calls == [
pretend.call("warehouse.config.require_https_tween_factory"),
Expand Down
4 changes: 4 additions & 0 deletions warehouse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ def configure(settings=None):
# Our translation strings are all in the "messages" domain
config.add_settings({"jinja2.i18n.domain": "messages"})

# Trim the Jinja blocks from the output, it's extra whitespace.
config.add_settings({"jinja2.lstrip_blocks": True})
config.add_settings({"jinja2.trim_blocks": True})

# We also want to use Jinja2 for .html templates as well, because we just
# assume that all templates will be using Jinja.
config.add_jinja2_renderer(".html")
Expand Down
7 changes: 3 additions & 4 deletions warehouse/templates/robots.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Sitemap: {{ request.route_url("index.sitemap.xml") }}

User-agent: *
{%- if request.registry.settings.get("warehouse.domain") != "pypi.org" %}
{% if request.registry.settings.get("warehouse.domain") != "pypi.org" %}
Disallow: /
{%- else %}
{% else %}
Disallow: /simple/
Disallow: /packages/
Disallow: /_includes/
Disallow: /pypi/*/json
Disallow: /pypi/*/*/json
Disallow: /pypi*?
Disallow: /search*
{%- endif %}

{% endif %}

0 comments on commit 8949061

Please sign in to comment.