]>
jfr.im git - dlqueue.git/blob - 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 importlib
.util
import module_from_spec
20 def find_spec(module
, paths
):
22 importlib
.machinery
.PathFinder().find_spec
23 if isinstance(paths
, list)
24 else 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)
41 spec
.origin
== 'frozen'
43 and issubclass(spec
.loader
, importlib
.machinery
.FrozenImporter
)
46 path
= None # imp compabilty
47 suffix
= mode
= '' # imp compatibility
49 spec
.origin
== 'built-in'
51 and issubclass(spec
.loader
, importlib
.machinery
.BuiltinImporter
)
54 path
= None # imp compabilty
55 suffix
= mode
= '' # imp compatibility
56 elif spec
.has_location
:
58 suffix
= os
.path
.splitext(path
)[1]
59 mode
= 'r' if suffix
in importlib
.machinery
.SOURCE_SUFFIXES
else 'rb'
61 if suffix
in importlib
.machinery
.SOURCE_SUFFIXES
:
63 elif suffix
in importlib
.machinery
.BYTECODE_SUFFIXES
:
65 elif suffix
in importlib
.machinery
.EXTENSION_SUFFIXES
:
68 if kind
in {PY_SOURCE, PY_COMPILED}
:
69 file = open(path
, mode
)
74 return file, path
, (suffix
, mode
, kind
)
77 def get_frozen_object(module
, paths
=None):
78 spec
= find_spec(module
, paths
)
80 raise ImportError("Can't find %s" % module
)
81 return spec
.loader
.get_code(module
)
84 def get_module(module
, paths
, info
):
85 spec
= find_spec(module
, paths
)
87 raise ImportError("Can't find %s" % module
)
88 return module_from_spec(spec
)