Skip to content

Commit

Permalink
Remove caching logic from the cached function
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jan 23, 2018
1 parent 3381827 commit 06359c0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/flake8_requirements/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import sys
from collections import namedtuple
from functools import wraps
from logging import getLogger

from pkg_resources import parse_requirements
Expand All @@ -29,6 +30,19 @@
STDLIB.update(STDLIB_PY3)


def memoize(f):
"""Cache value returned by the function."""
@wraps(f)
def w(*args, **kw):
memoize.mem[f] = v = f(*args, **kw)
return v
return w


# Initialize cache memory block.
memoize.mem = {}


def project2module(project):
"""Convert project name into a module name."""
# Name unification in accordance with PEP 426.
Expand Down Expand Up @@ -271,16 +285,15 @@ def parse_options(cls, options):
}

@classmethod
@memoize
def get_setup(cls):
"""Get package setup."""
if not getattr(cls, '_setup', None):
try:
with open("setup.py") as f:
cls._setup = SetupVisitor(ast.parse(f.read()))
except IOError as e:
LOG.warning("Couldn't open setup file: %s", e)
cls._setup = SetupVisitor(ast.parse(""))
return cls._setup
try:
with open("setup.py") as f:
return SetupVisitor(ast.parse(f.read()))
except IOError as e:
LOG.warning("Couldn't open setup file: %s", e)
return SetupVisitor(ast.parse(""))

@property
def processing_setup_py(self):
Expand Down

0 comments on commit 06359c0

Please sign in to comment.