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

keep_trailing_newline and other options missing from Environment.overlay #1645

Closed
Tom-Brouwer opened this issue Apr 1, 2022 · 4 comments · Fixed by #1647
Closed

keep_trailing_newline and other options missing from Environment.overlay #1645

Tom-Brouwer opened this issue Apr 1, 2022 · 4 comments · Fixed by #1647
Milestone

Comments

@Tom-Brouwer
Copy link

I was planning to use the Environment.overlay method in a flask app, to create a new environment with specific environment options that only apply to one endpoint.

However, it seems like some options were not added to the overlay method, when the options were added to jinja (example pull request). In my case this is the 'keep_trailing_newline' option, but also the 'newline_sequence', 'enable_async' options are not available on the overlay method.

Replication

# Note that this is inside a Flask Blueprint
from flask import current_app
jinja_env = current_app.jinja_env.overlay(keep_trailing_newline=True)
# This command gives the error:
# TypeError: Environment.overlay() got an unexpected keyword argument 'keep_trailing_newline'

Expectation

I would have expected to be able to change at least the 'newline_sequence' and 'keep_trailing_newline' options via the overlay method.

Environment

  • Python version: 3.10.2
  • Jinja version: 3.1.0
click==8.0.4
fastjsonschema==2.15.3
Flask==2.0.3
itsdangerous==2.1.2
Jinja2==3.1.0
MarkupSafe==2.1.1
PyYAML==6.0
Werkzeug==2.0.3

Note: If required I can submit a pull-request to add all 3 options to the overlay function, please let me know!

@davidism
Copy link
Member

davidism commented Apr 1, 2022

Happy to review a PR.

@Tom-Brouwer
Copy link
Author

@davidism I'm working on the change, but right now, the tests seem to be broken:

[INFO] Initializing environment for https://github.com/asottile/pyupgrade.
[INFO] Initializing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Initializing environment for https://github.com/asottile/reorder_python_imports:setuptools>60.9.
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/PyCQA/flake8.
[INFO] Initializing environment for https://github.com/PyCQA/flake8:flake8-bugbear.
[INFO] Initializing environment for https://github.com/peterdemin/pip-compile-multi.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/asottile/pyupgrade.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/peterdemin/pip-compile-multi.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
pyupgrade................................................................Passed
Reorder python imports...................................................Passed
black....................................................................Failed
- hook id: black
- exit code: 1

Traceback (most recent call last):
  File "/home/brouwer/.cache/pre-commit/repocablozk4/py_env-python3.10/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/home/brouwer/.cache/pre-commit/repocablozk4/py_env-python3.10/lib/python3.10/site-packages/black/__init__.py", line 1423, in patched_main
    patch_click()
  File "/home/brouwer/.cache/pre-commit/repocablozk4/py_env-python3.10/lib/python3.10/site-packages/black/__init__.py", line 1409, in patch_click
    from click import _unicodefun
ImportError: cannot import name '_unicodefun' from 'click' (/home/brouwer/.cache/pre-commit/repocablozk4/py_env-python3.10/lib/python3.10/site-packages/click/__init__.py)

flake8...................................................................Passed
pip-compile-multi verify.............................(no files to check)Skipped
fix utf-8 byte order marker..............................................Passed
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed

It seems related to this issue, but it looks like the error is in another repo, since the version of 'click' is hardcoded in requirements/dev.txt.

FYI, I followed the steps here: https://github.com/pallets/jinja/blob/main/CONTRIBUTING.rst#first-time-setup to prepare the environment, and I'm using python 3.10.2

@davidism
Copy link
Member

davidism commented Apr 1, 2022

I've pushed an update to the 3.1.x branch (and main, but make bug fixes off the maintenance branch).

@Tom-Brouwer
Copy link
Author

@davidism Great! As requested, here's the pull request for the 3.1.x branch

@davidism davidism added this to the 3.1.2 milestone Apr 4, 2022
@davidism davidism closed this as completed Apr 4, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants