Use asottile.cached_property.

This commit is contained in:
Anthony Sottile 2014-06-01 16:41:58 -07:00
parent 619bca2bdc
commit 39c4ee6e96
7 changed files with 5 additions and 45 deletions

View file

@ -1,8 +1,8 @@
import os.path
from asottile.cached_property import cached_property
import pre_commit.constants as C
from pre_commit.clientlib.validate_manifest import load_manifest
from pre_commit.util import cached_property
class Manifest(object):

View file

@ -1,9 +1,9 @@
from asottile.cached_property import cached_property
from asottile.ordereddict import OrderedDict
from pre_commit.languages.all import languages
from pre_commit.manifest import Manifest
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
from pre_commit.util import cached_property
class Repository(object):

View file

@ -1,12 +1,12 @@
import os
import os.path
from asottile.cached_property import cached_property
import pre_commit.constants as C
from pre_commit import git
from pre_commit.clientlib.validate_config import load_config
from pre_commit.repository import Repository
from pre_commit.store import Store
from pre_commit.util import cached_property
class Runner(object):

View file

@ -5,10 +5,10 @@ import logging
import os
import os.path
import tempfile
from asottile.cached_property import cached_property
from plumbum import local
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
from pre_commit.util import cached_property
from pre_commit.util import clean_path_on_failure

View file

@ -6,23 +6,6 @@ import shutil
import sys
class cached_property(object):
"""Like @property, but caches the value."""
def __init__(self, func):
self.__name__ = func.__name__
self.__module__ = func.__module__
self.__doc__ = func.__doc__
self._func = func
def __get__(self, obj, cls):
if obj is None:
return self
value = self._func(obj)
obj.__dict__[self.__name__] = value
return value
def memoize_by_cwd(func):
"""Memoize a function call based on os.getcwd()."""
@functools.wraps(func)