File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import os .path
2+ from asottile .cached_property import cached_property
23
34import pre_commit .constants as C
45from pre_commit .clientlib .validate_manifest import load_manifest
5- from pre_commit .util import cached_property
66
77
88class Manifest (object ):
Original file line number Diff line number Diff line change 1+ from asottile .cached_property import cached_property
12from asottile .ordereddict import OrderedDict
23
34from pre_commit .languages .all import languages
45from pre_commit .manifest import Manifest
56from pre_commit .prefixed_command_runner import PrefixedCommandRunner
6- from pre_commit .util import cached_property
77
88
99class Repository (object ):
Original file line number Diff line number Diff line change 11import os
22import os .path
3+ from asottile .cached_property import cached_property
34
45import pre_commit .constants as C
56from pre_commit import git
67from pre_commit .clientlib .validate_config import load_config
78from pre_commit .repository import Repository
89from pre_commit .store import Store
9- from pre_commit .util import cached_property
1010
1111
1212class Runner (object ):
Original file line number Diff line number Diff line change 55import os
66import os .path
77import tempfile
8+ from asottile .cached_property import cached_property
89from plumbum import local
910
1011from pre_commit .prefixed_command_runner import PrefixedCommandRunner
11- from pre_commit .util import cached_property
1212from pre_commit .util import clean_path_on_failure
1313
1414
Original file line number Diff line number Diff line change 66import sys
77
88
9- class cached_property (object ):
10- """Like @property, but caches the value."""
11-
12- def __init__ (self , func ):
13- self .__name__ = func .__name__
14- self .__module__ = func .__module__
15- self .__doc__ = func .__doc__
16- self ._func = func
17-
18- def __get__ (self , obj , cls ):
19- if obj is None :
20- return self
21- value = self ._func (obj )
22- obj .__dict__ [self .__name__ ] = value
23- return value
24-
25-
269def memoize_by_cwd (func ):
2710 """Memoize a function call based on os.getcwd()."""
2811 @functools .wraps (func )
Original file line number Diff line number Diff line change 2929 },
3030 install_requires = [
3131 'argparse' ,
32+ 'asottile.cached_property' ,
3233 'asottile.ordereddict' ,
3334 'asottile.yaml' ,
3435 'jsonschema' ,
Original file line number Diff line number Diff line change 66import sys
77from plumbum import local
88
9- from pre_commit .util import cached_property
109from pre_commit .util import clean_path_on_failure
1110from pre_commit .util import entry
1211from pre_commit .util import memoize_by_cwd
1312
1413
15- @pytest .fixture
16- def class_with_cached_property ():
17- class Foo (object ):
18- @cached_property
19- def my_property (self ):
20- return "Foo" + str (random .getrandbits (64 ))
21-
22- return Foo
23-
24-
25- def test_cached_property (class_with_cached_property ):
26- instance = class_with_cached_property ()
27- val = instance .my_property
28- val2 = instance .my_property
29- assert val is val2
30-
31-
32- def test_unbound_cached_property (class_with_cached_property ):
33- # Make sure we don't blow up when accessing the property unbound
34- prop = class_with_cached_property .my_property
35- assert isinstance (prop , cached_property )
36-
37-
3814@pytest .fixture
3915def memoized_by_cwd ():
4016 @memoize_by_cwd
You can’t perform that action at this time.
0 commit comments