Skip to content

Commit

Permalink
bump werkzeug 2.3.7
Browse files Browse the repository at this point in the history
use importlib.metadata.version
  • Loading branch information
davidism committed Aug 21, 2023
1 parent 0273664 commit 9f95502
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Version 2.3.3
Unreleased

- Python 3.12 compatibility.
- Require Werkzeug >= 2.3.6.
- Require Werkzeug >= 2.3.7.
- Use ``flit_core`` instead of ``setuptools`` as build backend.
- Refactor how an app's root and instance paths are determined. :issue:`5160`

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"Werkzeug>=2.3.6",
"Werkzeug>=2.3.7",
"Jinja2>=3.1.2",
"itsdangerous>=2.1.2",
"click>=8.1.3",
Expand Down
2 changes: 1 addition & 1 deletion requirements/tests-pallets-min.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Werkzeug==2.3.6
Werkzeug==2.3.7
Jinja2==3.1.2
MarkupSafe==2.1.1
itsdangerous==2.1.2
Expand Down
4 changes: 2 additions & 2 deletions requirements/tests-pallets-min.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:5bd33f1c06b3fb16f7ab50e80ed309655d110713
# SHA1:fe057f95a98251b053eec8fa27df0feb722c70e8
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -18,5 +18,5 @@ markupsafe==2.1.1
# -r requirements/tests-pallets-min.in
# jinja2
# werkzeug
werkzeug==2.3.6
werkzeug==2.3.7
# via -r requirements/tests-pallets-min.in
9 changes: 5 additions & 4 deletions src/flask/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import ast
import importlib.metadata
import inspect
import os
import platform
Expand Down Expand Up @@ -241,13 +242,13 @@ def get_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return

import werkzeug
from . import __version__
flask_version = importlib.metadata.version("flask")
werkzeug_version = importlib.metadata.version("werkzeug")

click.echo(
f"Python {platform.python_version()}\n"
f"Flask {__version__}\n"
f"Werkzeug {werkzeug.__version__}",
f"Flask {flask_version}\n"
f"Werkzeug {werkzeug_version}",
color=ctx.color,
)
ctx.exit()
Expand Down
15 changes: 14 additions & 1 deletion src/flask/testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib.metadata
import typing as t
from contextlib import contextmanager
from contextlib import ExitStack
Expand Down Expand Up @@ -92,6 +93,18 @@ def json_dumps(self, obj: t.Any, **kwargs: t.Any) -> str: # type: ignore
return self.app.json.dumps(obj, **kwargs)


_werkzeug_version = ""


def _get_werkzeug_version() -> str:
global _werkzeug_version

if not _werkzeug_version:
_werkzeug_version = importlib.metadata.version("werkzeug")

return _werkzeug_version


class FlaskClient(Client):
"""Works like a regular Werkzeug test client but has knowledge about
Flask's contexts to defer the cleanup of the request context until
Expand All @@ -115,7 +128,7 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
self._context_stack = ExitStack()
self.environ_base = {
"REMOTE_ADDR": "127.0.0.1",
"HTTP_USER_AGENT": f"werkzeug/{werkzeug.__version__}",
"HTTP_USER_AGENT": f"Werkzeug/{_get_werkzeug_version()}",
}

@contextmanager
Expand Down
12 changes: 5 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file was part of Flask-CLI and was modified under the terms of
# its Revised BSD License. Copyright © 2015 CERN.
import importlib.metadata
import os
import platform
import ssl
import sys
import types
Expand Down Expand Up @@ -227,10 +229,6 @@ def test_locate_app_suppress_raise(test_apps):


def test_get_version(test_apps, capsys):
from flask import __version__ as flask_version
from werkzeug import __version__ as werkzeug_version
from platform import python_version

class MockCtx:
resilient_parsing = False
color = None
Expand All @@ -241,9 +239,9 @@ def exit(self):
ctx = MockCtx()
get_version(ctx, None, "test")
out, err = capsys.readouterr()
assert f"Python {python_version()}" in out
assert f"Flask {flask_version}" in out
assert f"Werkzeug {werkzeug_version}" in out
assert f"Python {platform.python_version()}" in out
assert f"Flask {importlib.metadata.version('flask')}" in out
assert f"Werkzeug {importlib.metadata.version('werkzeug')}" in out


def test_scriptinfo(test_apps, monkeypatch):
Expand Down
40 changes: 21 additions & 19 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib.metadata

import click
import pytest
import werkzeug

import flask
from flask import appcontext_popped
Expand Down Expand Up @@ -38,34 +39,35 @@ def index():
assert rv.data == b"http://localhost/"


def test_environ_base_default(app, client, app_ctx):
def test_environ_base_default(app, client):
@app.route("/")
def index():
flask.g.user_agent = flask.request.headers["User-Agent"]
return flask.request.remote_addr
flask.g.remote_addr = flask.request.remote_addr
flask.g.user_agent = flask.request.user_agent.string
return ""

rv = client.get("/")
assert rv.data == b"127.0.0.1"
assert flask.g.user_agent == f"werkzeug/{werkzeug.__version__}"
with client:
client.get("/")
assert flask.g.remote_addr == "127.0.0.1"
assert flask.g.user_agent == (
f"Werkzeug/{importlib.metadata.version('werkzeug')}"
)


def test_environ_base_modified(app, client, app_ctx):
def test_environ_base_modified(app, client):
@app.route("/")
def index():
flask.g.user_agent = flask.request.headers["User-Agent"]
return flask.request.remote_addr
flask.g.remote_addr = flask.request.remote_addr
flask.g.user_agent = flask.request.user_agent.string
return ""

client.environ_base["REMOTE_ADDR"] = "0.0.0.0"
client.environ_base["REMOTE_ADDR"] = "192.168.0.22"
client.environ_base["HTTP_USER_AGENT"] = "Foo"
rv = client.get("/")
assert rv.data == b"0.0.0.0"
assert flask.g.user_agent == "Foo"

client.environ_base["REMOTE_ADDR"] = "0.0.0.1"
client.environ_base["HTTP_USER_AGENT"] = "Bar"
rv = client.get("/")
assert rv.data == b"0.0.0.1"
assert flask.g.user_agent == "Bar"
with client:
client.get("/")
assert flask.g.remote_addr == "192.168.0.22"
assert flask.g.user_agent == "Foo"


def test_client_open_environ(app, client, request):
Expand Down

0 comments on commit 9f95502

Please sign in to comment.