Skip to content

Commit

Permalink
deprecate __version__ (#2772)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Aug 21, 2023
2 parents 47c6bd5 + 40ba284 commit 01fa8ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Version 3.0.0
Unreleased

- Remove previously deprecated code. :pr:`2768`
- Deprecate the ``__version__`` attribute. Use feature detection, or
``importlib.metadata.version("werkzeug")``, instead. :issue:`2770`
- ``generate_password_hash`` uses scrypt by default. :issue:`2769`


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[project]
name = "Werkzeug"
version = "3.0.0.dev"
description = "The comprehensive WSGI web application library."
readme = "README.rst"
license = {file = "LICENSE.rst"}
Expand All @@ -19,7 +20,6 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = ["MarkupSafe>=2.1.1"]
dynamic = ["version"]

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand Down
21 changes: 20 additions & 1 deletion src/werkzeug/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
from __future__ import annotations

import typing as t

from .serving import run_simple as run_simple
from .test import Client as Client
from .wrappers import Request as Request
from .wrappers import Response as Response

__version__ = "3.0.0.dev"

def __getattr__(name: str) -> t.Any:
if name == "__version__":
import importlib.metadata
import warnings

warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" Werkzeug 3.1. Use feature detection or"
" 'importlib.metadata.version(\"werkzeug\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("werkzeug")

raise AttributeError(name)
8 changes: 5 additions & 3 deletions src/werkzeug/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):

@property
def server_version(self) -> str: # type: ignore
from . import __version__

return f"Werkzeug/{__version__}"
return self.server._server_version

def make_environ(self) -> WSGIEnvironment:
request_url = urlsplit(self.path)
Expand Down Expand Up @@ -796,6 +794,10 @@ def __init__(
else:
self.ssl_context = None

import importlib.metadata

self._server_version = f"Werkzeug/{importlib.metadata.version('werkzeug')}"

def log(self, type: str, message: str, *args: t.Any) -> None:
_log(type, message, *args)

Expand Down

0 comments on commit 01fa8ee

Please sign in to comment.