Check for version of Python on Windows

Certain versions of Python on Windows are capable of using
multiprocessing safely and correctly. Instead of completely disabling
multiprocessing on Windows, this allows us to check for safe versions.

This also updates our internal utility documentation to add missing
functions and add a strongly worded warning about the API of those
functions.
This commit is contained in:
Ian Cordasco 2016-06-07 19:56:41 -05:00
parent 49d1cf953c
commit 55f10211a3
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
3 changed files with 44 additions and 2 deletions

View file

@ -2,7 +2,20 @@
Utility Functions
===================
Flake8 has a few utility functions that it uses and provides to plugins.
Flake8 has a few utility functions that it uses internally.
.. warning::
As should be implied by where these are documented, these are all
**internal** utility functions. Their signatures and return types
may change between releases without notice.
Bugs reported about these **internal** functions will be closed
immediately.
If functions are needed by plugin developers, they may be requested
in the bug tracker and after careful consideration they *may* be added
to the *documented* stable API.
.. autofunction:: flake8.utils.parse_comma_separated_list
@ -51,6 +64,12 @@ allows plugins to use this to retrieve ``stdin`` if necessary.
This provides a convenient and explicitly named function that checks if we are
currently running on a Windows (or ``nt``) operating system.
.. autofunction:: flake8.utils.can_run_multiprocessing_on_windows
This provides a separate and distinct check from
:func:`~flake8.utils.is_windows` that allows us to check if the version of
Python we're using can actually use multiprocessing on Windows.
.. autofunction:: flake8.utils.is_using_stdin
Another helpful function that is named only to be explicit given it is a very
@ -98,3 +117,11 @@ plugin. This function will return the parameters in a consistent way across
versions of Python and will handle both classes and functions that are used as
plugins. Further, if the plugin is a class, it will strip the ``self``
argument so we can check the parameters of the plugin consistently.
.. autofunction:: flake8.utils.parse_unified_diff
In order to handle usage of :option:`flake8 --diff`, Flake8 needs to be able
to parse the name of the files in the diff as well as the ranges indicated the
sections that have been changed. This function either accepts the diff as an
argument or reads the diff from standard-in. It then returns a dictionary with
filenames as the keys and sets of line numbers as the value.

View file

@ -113,7 +113,8 @@ class Manager(object):
'Ignoring --jobs arguments.')
return 0
if utils.is_windows():
if (utils.is_windows() and
not utils.can_run_multiprocessing_on_windows()):
LOG.warning('The --jobs option is not available on Windows. '
'Ignoring --jobs arguments.')
return 0

View file

@ -159,6 +159,20 @@ def is_windows():
return os.name == 'nt'
def can_run_multiprocessing_on_windows():
# type: () -> bool
"""Determine if we can use multiprocessing on Windows.
:returns:
True if the version of Python is modern enough, otherwise False
:rtype:
bool
"""
is_new_enough_python27 = sys.version_info >= (2, 7, 11)
is_new_enough_python3 = sys.version_info > (3, 2)
return is_new_enough_python27 or is_new_enough_python3
def is_using_stdin(paths):
# type: (List[str]) -> bool
"""Determine if we're going to read from stdin.