Skip to content

Commit

Permalink
Add python and platform details to --version
Browse files Browse the repository at this point in the history
On Flake8 2.x we added the information about the implementation,
version, and operating system to the --version output to make helping
users easier. In short they can pretty simply just give us the output
from

    flake8 --version

And we can get a lot of the information that we need.
  • Loading branch information
sigmavirus24 committed Jun 28, 2016
1 parent 2d3e277 commit c9fb680
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/flake8/options/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def generate_versions(self, format_str='%(name)s: %(version)s'):

def update_version_string(self):
"""Update the flake8 version string."""
self.parser.version = (self.version + ' (' +
self.generate_versions() + ')')
self.parser.version = (
self.version + ' (' + self.generate_versions() + ') ' +
utils.get_python_version()
)

def generate_epilog(self):
"""Create an epilog with the version and name of each of plugin."""
Expand Down
17 changes: 17 additions & 0 deletions src/flake8/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect
import io
import os
import platform
import re
import sys

Expand Down Expand Up @@ -290,3 +291,19 @@ def parameters_for(plugin):
parameters.pop('self', None)

return parameters


def get_python_version():
"""Find and format the python implementation and version.
:returns:
Implementation name, version, and platform as a string.
:rtype:
str
"""
# The implementation isn't all that important.
try:
impl = platform.python_implementation() + " "
except AttributeError: # Python 2.5
impl = ''
return '%s%s on %s' % (impl, platform.python_version(), platform.system())
4 changes: 3 additions & 1 deletion tests/unit/test_option_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from flake8 import utils
from flake8.options import manager

TEST_VERSION = '3.0.0b1'
Expand Down Expand Up @@ -162,7 +163,8 @@ def test_update_version_string(optmanager):

assert optmanager.version == TEST_VERSION
assert (optmanager.parser.version == TEST_VERSION + ' ('
'Testing 100: 0.0.0, Testing 101: 0.0.0, Testing 300: 0.0.0)')
'Testing 100: 0.0.0, Testing 101: 0.0.0, Testing 300: 0.0.0) ' +
utils.get_python_version())


def test_generate_epilog(optmanager):
Expand Down

0 comments on commit c9fb680

Please sign in to comment.