diff options
author | Jeppe Fihl-Pearson <jeppe@tenzer.dk> | 2019-03-04 12:35:38 +0000 |
---|---|---|
committer | Jeppe Fihl-Pearson <jeppe@tenzer.dk> | 2019-03-04 12:35:38 +0000 |
commit | eb653c8bae52efad43fdb9f96b46d51b29214b1a (patch) | |
tree | d36d91669c23f08c890801443a1d98b460b6440e | |
parent | 1ec68ab8deab283f17bf7a39f011d18f02ad452a (diff) | |
download | isort-eb653c8bae52efad43fdb9f96b46d51b29214b1a.tar.gz |
Add LRU cache to RequirementsFinder._get_names
This should speed up the isort invocations significantly, like what
https://github.com/timothycrosley/isort/pull/856 intended to do, but somehow
missed the mark.
The `_get_names` method of RequirementsFinder seem to be the biggest culprit
and not `_get_files_from_dir`. I think I confused my previous benchmark results
due to `PipfileFinder` and `RequirementsFinder` being enabled in the same
change, so I may potentially have swapped around the benchmark results 🤦♂️
-rw-r--r-- | isort/finders.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/isort/finders.py b/isort/finders.py index c419bec8..e250cfa1 100644 --- a/isort/finders.py +++ b/isort/finders.py @@ -297,11 +297,20 @@ class RequirementsFinder(ReqsBaseFinder): def _get_names(self, path): """Load required packages from path to requirements file """ + return RequirementsFinder._get_names_cached(path) + + @classmethod + @lru_cache(maxsize=16) + def _get_names_cached(cls, path): + results = [] + with chdir(os.path.dirname(path)): requirements = parse_requirements(path, session=PipSession()) for req in requirements: if req.name: - yield req.name + results.append(req.name) + + return results class PipfileFinder(ReqsBaseFinder): |