Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: strip out whitespace added by jinja blocks #14709

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}