|
1 | 1 | """ command line options, ini-file and conftest.py processing. """ |
2 | 2 | from __future__ import absolute_import, division, print_function |
3 | 3 | import argparse |
| 4 | +import functools |
4 | 5 | import inspect |
5 | 6 | import shlex |
6 | 7 | import types |
@@ -205,7 +206,7 @@ def __init__(self): |
205 | 206 | self._conftest_plugins = set() |
206 | 207 |
|
207 | 208 | # state related to local conftest plugins |
208 | | - self._path2confmods = {} |
| 209 | + self._dirpath2confmods = {} |
209 | 210 | self._conftestpath2mod = {} |
210 | 211 | self._confcutdir = None |
211 | 212 | self._noconftest = False |
@@ -376,31 +377,29 @@ def _try_load_conftest(self, anchor): |
376 | 377 | if x.check(dir=1): |
377 | 378 | self._getconftestmodules(x) |
378 | 379 |
|
| 380 | + @functools.lru_cache(maxsize=None) |
379 | 381 | def _getconftestmodules(self, path): |
380 | 382 | if self._noconftest: |
381 | 383 | return [] |
382 | 384 |
|
383 | | - try: |
384 | | - return self._path2confmods[path] |
385 | | - except KeyError: |
386 | | - if path.isfile(): |
387 | | - directory = path.dirpath() |
388 | | - else: |
389 | | - directory = path |
390 | | - # XXX these days we may rather want to use config.rootdir |
391 | | - # and allow users to opt into looking into the rootdir parent |
392 | | - # directories instead of requiring to specify confcutdir |
393 | | - clist = [] |
394 | | - for parent in directory.realpath().parts(): |
395 | | - if self._confcutdir and self._confcutdir.relto(parent): |
396 | | - continue |
397 | | - conftestpath = parent.join("conftest.py") |
398 | | - if conftestpath.isfile(): |
399 | | - mod = self._importconftest(conftestpath) |
400 | | - clist.append(mod) |
401 | | - |
402 | | - self._path2confmods[path] = clist |
403 | | - return clist |
| 385 | + if path.isfile(): |
| 386 | + directory = path.dirpath() |
| 387 | + else: |
| 388 | + directory = path |
| 389 | + |
| 390 | + # XXX these days we may rather want to use config.rootdir |
| 391 | + # and allow users to opt into looking into the rootdir parent |
| 392 | + # directories instead of requiring to specify confcutdir |
| 393 | + clist = [] |
| 394 | + for parent in directory.realpath().parts(): |
| 395 | + if self._confcutdir and self._confcutdir.relto(parent): |
| 396 | + continue |
| 397 | + conftestpath = parent.join("conftest.py") |
| 398 | + if conftestpath.isfile(): |
| 399 | + mod = self._importconftest(conftestpath) |
| 400 | + clist.append(mod) |
| 401 | + self._dirpath2confmods[directory] = clist |
| 402 | + return clist |
404 | 403 |
|
405 | 404 | def _rget_with_confmod(self, name, path): |
406 | 405 | modules = self._getconftestmodules(path) |
@@ -441,8 +440,8 @@ def _importconftest(self, conftestpath): |
441 | 440 | self._conftest_plugins.add(mod) |
442 | 441 | self._conftestpath2mod[conftestpath] = mod |
443 | 442 | dirpath = conftestpath.dirpath() |
444 | | - if dirpath in self._path2confmods: |
445 | | - for path, mods in self._path2confmods.items(): |
| 443 | + if dirpath in self._dirpath2confmods: |
| 444 | + for path, mods in self._dirpath2confmods.items(): |
446 | 445 | if path and path.relto(dirpath) or path == dirpath: |
447 | 446 | assert mod not in mods |
448 | 447 | mods.append(mod) |
|
0 commit comments