diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-01 23:57:52 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-01 23:57:52 -0800 |
commit | 30b1e9f57b3fd5f09327a0094f6ed793f1c9b3a3 (patch) | |
tree | 247f57130c1968b64385df16f98c677368312be1 /isort | |
parent | f0badf18389935b0275660f8f3ef9899dc4c4f49 (diff) | |
parent | a7992050c0721139c7dd40abd7f7d746576abd12 (diff) | |
download | isort-30b1e9f57b3fd5f09327a0094f6ed793f1c9b3a3.tar.gz |
Merge in latest from master
Diffstat (limited to 'isort')
-rw-r--r-- | isort/__init__.py | 2 | ||||
-rw-r--r-- | isort/finders.py | 20 | ||||
-rw-r--r-- | isort/settings.py | 8 |
3 files changed, 22 insertions, 8 deletions
diff --git a/isort/__init__.py b/isort/__init__.py index 3553b811..63034de6 100644 --- a/isort/__init__.py +++ b/isort/__init__.py @@ -22,4 +22,4 @@ OTHER DEALINGS IN THE SOFTWARE. from . import settings # noqa: F401 from .isort import SortImports # noqa: F401 -__version__ = "4.3.8" +__version__ = "4.3.9" diff --git a/isort/finders.py b/isort/finders.py index e21ef447..05abb585 100644 --- a/isort/finders.py +++ b/isort/finders.py @@ -34,6 +34,11 @@ try: except ImportError: Pipfile = None +try: + from functools import lru_cache +except ImportError: + from backports.functools_lru_cache import lru_cache + KNOWN_SECTION_MAPPING = { 'STDLIB': 'STANDARD_LIBRARY', @@ -268,6 +273,13 @@ class RequirementsFinder(ReqsBaseFinder): def _get_files_from_dir(self, path: str) -> Iterator[str]: """Return paths to requirements files from passed dir. """ + return RequirementsFinder._get_files_from_dir_cached(path) + + @classmethod + @lru_cache(maxsize=16) + def _get_files_from_dir_cached(cls, path): + result = [] + for fname in os.listdir(path): if 'requirements' not in fname: continue @@ -276,16 +288,16 @@ class RequirementsFinder(ReqsBaseFinder): # *requirements*/*.{txt,in} if os.path.isdir(full_path): for subfile_name in os.listdir(path): - for ext in self.exts: + for ext in cls.exts: if subfile_name.endswith(ext): - yield os.path.join(path, subfile_name) + result.append(os.path.join(path, subfile_name)) continue # *requirements*.{txt,in} if os.path.isfile(full_path): - for ext in self.exts: + for ext in cls.exts: if fname.endswith(ext): - yield full_path + result.append(full_path) break def _get_names(self, path: str) -> Iterator[str]: diff --git a/isort/settings.py b/isort/settings.py index c1d17802..1fbd8cb6 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -28,7 +28,6 @@ import fnmatch import os import posixpath import re -import stat import warnings from distutils.util import strtobool from functools import lru_cache @@ -337,7 +336,10 @@ def should_skip( path: str = '/' ) -> bool: """Returns True if the file should be skipped based on the passed in settings.""" - normalized_path = posixpath.join(path.replace('\\', '/'), filename) + os_path = os.path.join(path, filename) + normalized_path = os_path.replace('\\', '/') + if normalized_path[1:2] == ':': + normalized_path = normalized_path[2:] if config['safety_excludes'] and safety_exclude_re.search(normalized_path): return True @@ -356,7 +358,7 @@ def should_skip( if fnmatch.fnmatch(filename, glob): return True - if stat.S_ISFIFO(os.stat(normalized_path).st_mode): + if not (os.path.isfile(os_path) or os.path.isdir(os_path) or os.path.islink(os_path)): return True return False |