Skip to content

Commit

Permalink
Merge pull request #2825 from eso31/fix-2824-issue
Browse files Browse the repository at this point in the history
Fixes issue #2824 flask --version
  • Loading branch information
davidism committed Jan 7, 2019
2 parents 0f56c0c + a0ccc47 commit 232e5c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ Unreleased
stricter about header encodings than PEP 3333. (`#2766`_)
- Allow custom CLIs using ``FlaskGroup`` to set the debug flag without
it always being overwritten based on environment variables. (`#2765`_)
- ``flask --version`` outputs Werkzeug's version and simplifies the
Python version. (`#2825`_)

.. _#2766: https://github.com/pallets/flask/issues/2766
.. _#2765: https://github.com/pallets/flask/pull/2765
.. _#2825: https://github.com/pallets/flask/pull/2825


Version 1.0.2
Expand Down
13 changes: 10 additions & 3 deletions flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ast
import inspect
import os
import platform
import re
import ssl
import sys
Expand Down Expand Up @@ -259,10 +260,16 @@ def locate_app(script_info, module_name, app_name, raise_if_not_found=True):
def get_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
message = 'Flask %(version)s\nPython %(python_version)s'
import werkzeug
message = (
'Python %(python)s\n'
'Flask %(flask)s\n'
'Werkzeug %(werkzeug)s'
)
click.echo(message % {
'version': __version__,
'python_version': sys.version,
'python': platform.python_version(),
'flask': __version__,
'werkzeug': werkzeug.__version__,
}, color=ctx.color)
ctx.exit()

Expand Down
11 changes: 6 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def test_locate_app_suppress_raise():


def test_get_version(test_apps, capsys):
"""Test of get_version."""
from flask import __version__ as flask_ver
from sys import version as py_ver
from flask import __version__ as flask_version
from werkzeug import __version__ as werkzeug_version
from platform import python_version

class MockCtx(object):
resilient_parsing = False
Expand All @@ -254,8 +254,9 @@ def exit(self): return
ctx = MockCtx()
get_version(ctx, None, "test")
out, err = capsys.readouterr()
assert flask_ver in out
assert py_ver in out
assert "Python " + python_version() in out
assert "Flask " + flask_version in out
assert "Werkzeug " + werkzeug_version in out


def test_scriptinfo(test_apps, monkeypatch):
Expand Down

0 comments on commit 232e5c8

Please sign in to comment.