Skip to content

Commit 1888df3

Browse files
committed
Merge remote-tracking branch 'origin/2.1.x'
2 parents a52a7db + d506af1 commit 1888df3

File tree

8 files changed

+53
-48
lines changed

8 files changed

+53
-48
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ci:
33
autoupdate_schedule: monthly
44
repos:
55
- repo: https://github.com/asottile/pyupgrade
6-
rev: v2.32.0
6+
rev: v2.32.1
77
hooks:
88
- id: pyupgrade
99
args: ["--py36-plus"]

requirements/dev.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010
-r typing.txt
1111
cfgv==3.3.1
1212
# via pre-commit
13-
click==8.1.2
13+
click==8.1.3
1414
# via
1515
# pip-compile-multi
1616
# pip-tools
1717
distlib==0.3.4
1818
# via virtualenv
19-
filelock==3.6.0
19+
filelock==3.7.0
2020
# via
2121
# tox
2222
# virtualenv
2323
greenlet==1.1.2 ; python_version < "3.11"
2424
# via -r requirements/tests.in
25-
identify==2.5.0
25+
identify==2.5.1
2626
# via pre-commit
2727
nodeenv==1.6.0
2828
# via pre-commit
2929
pep517==0.12.0
3030
# via pip-tools
3131
pip-compile-multi==2.4.5
3232
# via -r requirements/dev.in
33-
pip-tools==6.6.0
33+
pip-tools==6.6.1
3434
# via pip-compile-multi
3535
platformdirs==2.5.2
3636
# via virtualenv
37-
pre-commit==2.18.1
37+
pre-commit==2.19.0
3838
# via -r requirements/dev.in
3939
pyyaml==6.0
4040
# via pre-commit

requirements/docs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ alabaster==0.7.12
99
# via sphinx
1010
babel==2.10.1
1111
# via sphinx
12-
certifi==2021.10.8
12+
certifi==2022.5.18.1
1313
# via requests
1414
charset-normalizer==2.0.12
1515
# via requests
@@ -21,7 +21,7 @@ idna==3.3
2121
# via requests
2222
imagesize==1.3.0
2323
# via sphinx
24-
jinja2==3.1.1
24+
jinja2==3.1.2
2525
# via sphinx
2626
markupsafe==2.1.1
2727
# via jinja2
@@ -35,7 +35,7 @@ pygments==2.12.0
3535
# via
3636
# sphinx
3737
# sphinx-tabs
38-
pyparsing==3.0.8
38+
pyparsing==3.0.9
3939
# via packaging
4040
pytz==2022.1
4141
# via babel

requirements/tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# pip-compile-multi
77
#
8-
asgiref==3.5.0
8+
asgiref==3.5.2
99
# via -r requirements/tests.in
1010
attrs==21.4.0
1111
# via pytest
@@ -21,7 +21,7 @@ pluggy==1.0.0
2121
# via pytest
2222
py==1.11.0
2323
# via pytest
24-
pyparsing==3.0.8
24+
pyparsing==3.0.9
2525
# via packaging
2626
pytest==7.1.2
2727
# via -r requirements/tests.in

requirements/typing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
cffi==1.15.0
99
# via cryptography
10-
cryptography==37.0.1
10+
cryptography==37.0.2
1111
# via -r requirements/typing.in
1212
mypy==0.950
1313
# via -r requirements/typing.in
@@ -21,7 +21,7 @@ types-contextvars==2.4.5
2121
# via -r requirements/typing.in
2222
types-dataclasses==0.6.5
2323
# via -r requirements/typing.in
24-
types-setuptools==57.4.14
24+
types-setuptools==57.4.15
2525
# via -r requirements/typing.in
2626
typing-extensions==4.2.0
2727
# via mypy

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ ignore_missing_imports = True
116116

117117
[mypy-cryptography.*]
118118
ignore_missing_imports = True
119+
120+
[mypy-importlib_metadata]
121+
ignore_missing_imports = True

src/flask/cli.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from operator import attrgetter
1010
from threading import Lock
1111
from threading import Thread
12-
from typing import Any
13-
from typing import TYPE_CHECKING
1412

1513
import click
1614
from werkzeug.utils import import_string
@@ -20,31 +18,6 @@
2018
from .helpers import get_env
2119
from .helpers import get_load_dotenv
2220

23-
try:
24-
import dotenv
25-
except ImportError:
26-
dotenv = None
27-
28-
try:
29-
import ssl
30-
except ImportError:
31-
ssl = None # type: ignore
32-
33-
if sys.version_info >= (3, 10):
34-
from importlib import metadata
35-
else:
36-
# Use a backport on Python < 3.10.
37-
#
38-
# We technically have importlib.metadata on 3.8+,
39-
# but the API changed in 3.10, so use the backport
40-
# for consistency.
41-
if TYPE_CHECKING:
42-
metadata: Any
43-
else:
44-
# we do this to avoid a version dependent mypy error
45-
# because importlib_metadata is not installed in python3.10+
46-
import importlib_metadata as metadata
47-
4821

4922
class NoAppException(click.UsageError):
5023
"""Raised if an application cannot be found or loaded."""
@@ -520,6 +493,14 @@ def _load_plugin_commands(self):
520493
if self._loaded_plugin_commands:
521494
return
522495

496+
if sys.version_info >= (3, 10):
497+
from importlib import metadata
498+
else:
499+
# Use a backport on Python < 3.10. We technically have
500+
# importlib.metadata on 3.8+, but the API changed in 3.10,
501+
# so use the backport for consistency.
502+
import importlib_metadata as metadata
503+
523504
for ep in metadata.entry_points(group="flask.commands"):
524505
self.add_command(ep.load(), ep.name)
525506

@@ -615,7 +596,9 @@ def load_dotenv(path=None):
615596
616597
.. versionadded:: 1.0
617598
"""
618-
if dotenv is None:
599+
try:
600+
import dotenv
601+
except ImportError:
619602
if path or os.path.isfile(".env") or os.path.isfile(".flaskenv"):
620603
click.secho(
621604
" * Tip: There are .env or .flaskenv files present."
@@ -691,12 +674,14 @@ def __init__(self):
691674
self.path_type = click.Path(exists=True, dir_okay=False, resolve_path=True)
692675

693676
def convert(self, value, param, ctx):
694-
if ssl is None:
677+
try:
678+
import ssl
679+
except ImportError:
695680
raise click.BadParameter(
696681
'Using "--cert" requires Python to be compiled with SSL support.',
697682
ctx,
698683
param,
699-
)
684+
) from None
700685

701686
try:
702687
return self.path_type(value, param, ctx)
@@ -729,7 +714,13 @@ def _validate_key(ctx, param, value):
729714
"""
730715
cert = ctx.params.get("cert")
731716
is_adhoc = cert == "adhoc"
732-
is_context = ssl and isinstance(cert, ssl.SSLContext)
717+
718+
try:
719+
import ssl
720+
except ImportError:
721+
is_context = False
722+
else:
723+
is_context = isinstance(cert, ssl.SSLContext)
733724

734725
if value is not None:
735726
if is_adhoc:

tests/test_cli.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from flask import Flask
1919
from flask.cli import AppGroup
2020
from flask.cli import DispatchingApp
21-
from flask.cli import dotenv
2221
from flask.cli import find_best_app
2322
from flask.cli import FlaskGroup
2423
from flask.cli import get_version
@@ -492,7 +491,18 @@ def test_no_routes(self, invoke_no_routes):
492491
assert "No routes were registered." in result.output
493492

494493

495-
need_dotenv = pytest.mark.skipif(dotenv is None, reason="dotenv is not installed")
494+
def dotenv_not_available():
495+
try:
496+
import dotenv # noqa: F401
497+
except ImportError:
498+
return True
499+
500+
return False
501+
502+
503+
need_dotenv = pytest.mark.skipif(
504+
dotenv_not_available(), reason="dotenv is not installed"
505+
)
496506

497507

498508
@need_dotenv
@@ -530,7 +540,7 @@ def test_dotenv_path(monkeypatch):
530540

531541

532542
def test_dotenv_optional(monkeypatch):
533-
monkeypatch.setattr("flask.cli.dotenv", None)
543+
monkeypatch.setitem(sys.modules, "dotenv", None)
534544
monkeypatch.chdir(test_path)
535545
load_dotenv()
536546
assert "FOO" not in os.environ
@@ -602,7 +612,8 @@ def test_run_cert_import(monkeypatch):
602612

603613

604614
def test_run_cert_no_ssl(monkeypatch):
605-
monkeypatch.setattr("flask.cli.ssl", None)
615+
monkeypatch.setitem(sys.modules, "ssl", None)
616+
606617
with pytest.raises(click.BadParameter):
607618
run_command.make_context("run", ["--cert", "not_here"])
608619

0 commit comments

Comments
 (0)