]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/_imp.py
2 Re-implementation of find_module and get_frozen_object
3 from the deprecated imp module.
8 import importlib
.machinery
10 from .py34compat
import module_from_spec
20 def find_spec(module
, paths
):
22 importlib
.machinery
.PathFinder().find_spec
23 if isinstance(paths
, list) else
24 importlib
.util
.find_spec
26 return finder(module
, paths
)
29 def find_module(module
, paths
=None):
30 """Just like 'imp.find_module()', but with package support"""
31 spec
= find_spec(module
, paths
)
33 raise ImportError("Can't find %s" % module
)
34 if not spec
.has_location
and hasattr(spec
, 'submodule_search_locations'):
35 spec
= importlib
.util
.spec_from_loader('__init__.py', spec
.loader
)
39 static
= isinstance(spec
.loader
, type)
40 if spec
.origin
== 'frozen' or static
and issubclass(
41 spec
.loader
, importlib
.machinery
.FrozenImporter
):
43 path
= None # imp compabilty
44 suffix
= mode
= '' # imp compatibility
45 elif spec
.origin
== 'built-in' or static
and issubclass(
46 spec
.loader
, importlib
.machinery
.BuiltinImporter
):
48 path
= None # imp compabilty
49 suffix
= mode
= '' # imp compatibility
50 elif spec
.has_location
:
52 suffix
= os
.path
.splitext(path
)[1]
53 mode
= 'r' if suffix
in importlib
.machinery
.SOURCE_SUFFIXES
else 'rb'
55 if suffix
in importlib
.machinery
.SOURCE_SUFFIXES
:
57 elif suffix
in importlib
.machinery
.BYTECODE_SUFFIXES
:
59 elif suffix
in importlib
.machinery
.EXTENSION_SUFFIXES
:
62 if kind
in {PY_SOURCE
, PY_COMPILED
}:
63 file = open(path
, mode
)
68 return file, path
, (suffix
, mode
, kind
)
71 def get_frozen_object(module
, paths
=None):
72 spec
= find_spec(module
, paths
)
74 raise ImportError("Can't find %s" % module
)
75 return spec
.loader
.get_code(module
)
78 def get_module(module
, paths
, info
):
79 spec
= find_spec(module
, paths
)
81 raise ImportError("Can't find %s" % module
)
82 return module_from_spec(spec
)