@@ -214,7 +214,7 @@ def __init__(self):
214214 self ._conftest_plugins = set ()
215215
216216 # state related to local conftest plugins
217- self ._path2confmods = {}
217+ self ._dirpath2confmods = {}
218218 self ._conftestpath2mod = {}
219219 self ._confcutdir = None
220220 self ._noconftest = False
@@ -385,31 +385,35 @@ def _try_load_conftest(self, anchor):
385385 if x .check (dir = 1 ):
386386 self ._getconftestmodules (x )
387387
388+ @lru_cache (maxsize = 128 )
388389 def _getconftestmodules (self , path ):
389390 if self ._noconftest :
390391 return []
391392
392- try :
393- return self ._path2confmods [path ]
394- except KeyError :
395- if path .isfile ():
396- directory = path .dirpath ()
397- else :
398- directory = path
399- # XXX these days we may rather want to use config.rootdir
400- # and allow users to opt into looking into the rootdir parent
401- # directories instead of requiring to specify confcutdir
402- clist = []
403- for parent in directory .realpath ().parts ():
404- if self ._confcutdir and self ._confcutdir .relto (parent ):
405- continue
406- conftestpath = parent .join ("conftest.py" )
407- if conftestpath .isfile ():
408- mod = self ._importconftest (conftestpath )
409- clist .append (mod )
410-
411- self ._path2confmods [path ] = clist
412- return clist
393+ if path .isfile ():
394+ directory = path .dirpath ()
395+ else :
396+ directory = path
397+
398+ if six .PY2 : # py2 is not using lru_cache.
399+ try :
400+ return self ._dirpath2confmods [directory ]
401+ except KeyError :
402+ pass
403+
404+ # XXX these days we may rather want to use config.rootdir
405+ # and allow users to opt into looking into the rootdir parent
406+ # directories instead of requiring to specify confcutdir
407+ clist = []
408+ for parent in directory .realpath ().parts ():
409+ if self ._confcutdir and self ._confcutdir .relto (parent ):
410+ continue
411+ conftestpath = parent .join ("conftest.py" )
412+ if conftestpath .isfile ():
413+ mod = self ._importconftest (conftestpath )
414+ clist .append (mod )
415+ self ._dirpath2confmods [directory ] = clist
416+ return clist
413417
414418 def _rget_with_confmod (self , name , path ):
415419 modules = self ._getconftestmodules (path )
@@ -450,8 +454,8 @@ def _importconftest(self, conftestpath):
450454 self ._conftest_plugins .add (mod )
451455 self ._conftestpath2mod [conftestpath ] = mod
452456 dirpath = conftestpath .dirpath ()
453- if dirpath in self ._path2confmods :
454- for path , mods in self ._path2confmods .items ():
457+ if dirpath in self ._dirpath2confmods :
458+ for path , mods in self ._dirpath2confmods .items ():
455459 if path and path .relto (dirpath ) or path == dirpath :
456460 assert mod not in mods
457461 mods .append (mod )
@@ -902,7 +906,6 @@ def _getini(self, name):
902906 assert type is None
903907 return value
904908
905- @lru_cache (maxsize = None )
906909 def _getconftest_pathlist (self , name , path ):
907910 try :
908911 mod , relroots = self .pluginmanager ._rget_with_confmod (name , path )
0 commit comments