diff --git a/docs/source/internal/utils.rst b/docs/source/internal/utils.rst index d8adeac..98b2f27 100644 --- a/docs/source/internal/utils.rst +++ b/docs/source/internal/utils.rst @@ -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. diff --git a/flake8/checker.py b/flake8/checker.py index 43482dd..03709dd 100644 --- a/flake8/checker.py +++ b/flake8/checker.py @@ -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 diff --git a/flake8/utils.py b/flake8/utils.py index 7cd12b0..597dea6 100644 --- a/flake8/utils.py +++ b/flake8/utils.py @@ -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.