Skip to content

Commit aab4c8c

Browse files
authored
Merge pull request pallets#2694 from pallets/backport-2359-cli-warning
backport pallets#2359 fix python -m import warning
2 parents c52e1b7 + 18c9db4 commit aab4c8c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

flask/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,19 @@ def shell_command():
494494

495495

496496
def main(as_module=False):
497-
this_module = __package__ + '.cli'
498497
args = sys.argv[1:]
499498

500499
if as_module:
501-
if sys.version_info >= (2, 7):
502-
name = 'python -m ' + this_module.rsplit('.', 1)[0]
503-
else:
504-
name = 'python -m ' + this_module
500+
this_module = 'flask'
501+
502+
if sys.version_info < (2, 7):
503+
this_module += '.cli'
504+
505+
name = 'python -m ' + this_module
505506

506-
# This module is always executed as "python -m flask.run" and as such
507-
# we need to ensure that we restore the actual command line so that
508-
# the reloader can properly operate.
509-
sys.argv = ['-m', this_module] + sys.argv[1:]
507+
# Python rewrites "python -m flask" to the path to the file in argv.
508+
# Restore the original command so that the reloader works.
509+
sys.argv = ['-m', this_module] + args
510510
else:
511511
name = None
512512

0 commit comments

Comments
 (0)