mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-31 19:26:52 +00:00
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:
parent
49d1cf953c
commit
55f10211a3
3 changed files with 44 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue