mirror of
https://github.com/python/cpython.git
synced 2025-07-16 15:55:18 +00:00
Separate out finder for source and source/bytecode.
This commit is contained in:
parent
2dee597e05
commit
4afab6b30b
4 changed files with 21 additions and 10 deletions
|
@ -5,19 +5,22 @@ to do
|
||||||
subclass of source support (makes it nicer for VMs that don't use CPython
|
subclass of source support (makes it nicer for VMs that don't use CPython
|
||||||
bytecode).
|
bytecode).
|
||||||
|
|
||||||
+ ExtensionFileFinder
|
+ PyLoader (for ABC)
|
||||||
+ PyFileFinder
|
|
||||||
+ PyPycFileFinder
|
|
||||||
+ PyFileLoader
|
|
||||||
|
|
||||||
- get_code for source only
|
- get_code for source only
|
||||||
|
|
||||||
|
+ PyFileLoader(PyLoader)
|
||||||
|
|
||||||
- get_data
|
- get_data
|
||||||
- source_mtime
|
- source_mtime
|
||||||
- source_path
|
- source_path
|
||||||
|
|
||||||
+ PyPycFileLoader(PyFileLoader)
|
+PyPycLoader (PyLoader, for ABC)
|
||||||
|
|
||||||
|
- get_code for source and bytecode
|
||||||
|
|
||||||
|
+ PyPycFileLoader(PyPycLoader, PyFileLoader)
|
||||||
|
|
||||||
- get_code
|
|
||||||
- bytecode_path
|
- bytecode_path
|
||||||
- write_bytecode
|
- write_bytecode
|
||||||
|
|
||||||
|
|
|
@ -592,10 +592,18 @@ class PyFileFinder(FileFinder):
|
||||||
# Make sure that Python source files are listed first! Needed for an
|
# Make sure that Python source files are listed first! Needed for an
|
||||||
# optimization by the loader.
|
# optimization by the loader.
|
||||||
self._suffixes = suffix_list(imp.PY_SOURCE)
|
self._suffixes = suffix_list(imp.PY_SOURCE)
|
||||||
self._suffixes += suffix_list(imp.PY_COMPILED)
|
|
||||||
super().__init__(path_entry)
|
super().__init__(path_entry)
|
||||||
|
|
||||||
|
|
||||||
|
class PyPycFileFinder(PyFileFinder):
|
||||||
|
|
||||||
|
"""Finder for source and bytecode files."""
|
||||||
|
|
||||||
|
def __init__(self, path_entry):
|
||||||
|
super().__init__(path_entry)
|
||||||
|
self._suffixes += suffix_list(imp.PY_COMPILED)
|
||||||
|
|
||||||
|
|
||||||
class PathFinder:
|
class PathFinder:
|
||||||
|
|
||||||
"""Meta path finder for sys.(path|path_hooks|path_importer_cache)."""
|
"""Meta path finder for sys.(path|path_hooks|path_importer_cache)."""
|
||||||
|
@ -659,7 +667,7 @@ class PathFinder:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
_DEFAULT_PATH_HOOK = chained_path_hook(ExtensionFileFinder, PyFileFinder)
|
_DEFAULT_PATH_HOOK = chained_path_hook(ExtensionFileFinder, PyPycFileFinder)
|
||||||
|
|
||||||
class _DefaultPathFinder(PathFinder):
|
class _DefaultPathFinder(PathFinder):
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class CaseSensitivityTest(unittest.TestCase):
|
||||||
assert name != name.lower()
|
assert name != name.lower()
|
||||||
|
|
||||||
def find(self, path):
|
def find(self, path):
|
||||||
finder = importlib.PyFileFinder(path)
|
finder = importlib.PyPycFileFinder(path)
|
||||||
return finder.find_module(self.name)
|
return finder.find_module(self.name)
|
||||||
|
|
||||||
def sensitivity_test(self):
|
def sensitivity_test(self):
|
||||||
|
|
|
@ -32,7 +32,7 @@ class FinderTests(abc.FinderTests):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def import_(self, root, module):
|
def import_(self, root, module):
|
||||||
finder = importlib.PyFileFinder(root)
|
finder = importlib.PyPycFileFinder(root)
|
||||||
return finder.find_module(module)
|
return finder.find_module(module)
|
||||||
|
|
||||||
def run_test(self, test, create=None, *, compile_=None, unlink=None):
|
def run_test(self, test, create=None, *, compile_=None, unlink=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue