Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
97bdaa2
Make use of find_frozen() more consistent.
ericsnowcurrently Sep 29, 2021
e2e676d
Drop some one-off helper functions.
ericsnowcurrently Sep 29, 2021
6333212
Factor out unmarshal_frozen_code().
ericsnowcurrently Sep 29, 2021
8cd239b
Add a "data" arg to _imp.get_frozen_object().
ericsnowcurrently Sep 29, 2021
7724019
Add _imp.find_frozen().
ericsnowcurrently Sep 29, 2021
0dd3870
Use _imp.find_frozen() in the frozen importer.
ericsnowcurrently Sep 29, 2021
1a0ad16
Clear loader_state to save memory.
ericsnowcurrently Sep 29, 2021
fdf7689
Only call is_frozen() in the fallback case.
ericsnowcurrently Sep 29, 2021
385d412
Add a NEWS entry.
ericsnowcurrently Sep 29, 2021
e0fe501
Add a missing "static" declaration.
ericsnowcurrently Sep 29, 2021
7221e0e
Treat FROZEN_BAD_NAME as FROZEN_NOT_FOUND in some cases.
ericsnowcurrently Sep 29, 2021
5f68ee8
Make frozen_info.size Py_ssize_t.
ericsnowcurrently Sep 29, 2021
7b85a63
Py_ssize_t is never smaller than int.
ericsnowcurrently Sep 29, 2021
cdbc611
name -> nameobj.
ericsnowcurrently Sep 29, 2021
c6e70cc
Add tests.
ericsnowcurrently Sep 30, 2021
f86dcd5
Tweak the tests.
ericsnowcurrently Oct 1, 2021
d1b1868
Default to using _imp.get_frozen_object().
ericsnowcurrently Oct 1, 2021
4e105a9
Do not use <> to mark source package.
ericsnowcurrently Oct 1, 2021
5d6af1e
Drop unused code.
ericsnowcurrently Oct 1, 2021
017c932
Store data in loader_state directly.
ericsnowcurrently Oct 2, 2021
1a833ed
Set "name" on import errors.
ericsnowcurrently Oct 2, 2021
5363708
Use a narrower exception.
ericsnowcurrently Oct 2, 2021
07c947f
Fix a comment.
ericsnowcurrently Oct 2, 2021
cddf089
Clarify a comment.
ericsnowcurrently Oct 2, 2021
ca0500f
Add a note about why we silence an error.
ericsnowcurrently Oct 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not use <> to mark source package.
  • Loading branch information
ericsnowcurrently committed Oct 1, 2021
commit 4e105a9a081f5f0f891fdfed153dbf6c7babea85
46 changes: 31 additions & 15 deletions Lib/test/test_importlib/frozen/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from test.support import import_helper, REPO_ROOT, STDLIB_DIR


def get_frozen_code(name, source=None, ispkg=False, *, useimp=True):
def get_frozen_code(name, source=None, ispkg=None, *, useimp=True):
"""Return the code object for the given module.

This should match the data stored in the frozen .h file used
Expand All @@ -24,17 +24,34 @@ def get_frozen_code(name, source=None, ispkg=False, *, useimp=True):
with import_helper.frozen_modules():
return _imp.get_frozen_object(name)

if not source:
source = name
else:
ispkg = source.startswith('<') and source.endswith('>')
if ispkg:
source = source[1:-1]
filename = resolve_filename(source, ispkg)
origname = name if filename == source else source
if source:
ispkg = None
origname, filename = resolve_source(source or name, ispkg)
with open(filename) as infile:
text = infile.read()
return compile(text, f'<frozen {origname}>', 'exec')
return compile(text, f'<frozen {origname or name}>', 'exec')


def resolve_source(source, ispkg=None):
origname, filename, _ispkg = parse_source(source)
if ispkg is None:
ispkg = _ispkg
if filename is None:
filename = resolve_filename(origname, ispkg)
return origname, filename


def parse_source(source):
assert source
if source.endswith('.py'):
origname = None
filename = source
ispkg = os.path.basename(source) == '__init__.py'
else:
ispkg = source.endswith('.__init__')
origname = source.rpartition('.')[0] if ispkg else source
filename = None
return origname, filename, ispkg


def resolve_filename(source, ispkg=False):
Expand Down Expand Up @@ -74,8 +91,7 @@ def check_search_location(self, spec, source=None):
expected = []
self.assertListEqual(spec.submodule_search_locations, expected)

def check_data(self, spec, source=None):
ispkg = spec.submodule_search_locations is not None
def check_data(self, spec, source=None, ispkg=None):
expected = get_frozen_code(spec.name, source, ispkg)
data, = spec.loader_state
# We can't compare the marshaled data directly because
Expand All @@ -87,9 +103,9 @@ def check_data(self, spec, source=None):
def test_module(self):
modules = {
'__hello__': None,
'__phello__.__init__': '<__phello__>',
'__phello__.__init__': None,
'__phello__.spam': None,
'__phello__.ham.__init__': '<__phello__.ham>',
'__phello__.ham.__init__': None,
'__phello__.ham.eggs': None,
'__hello_alias__': '__hello__',
}
Expand All @@ -110,7 +126,7 @@ def test_package(self):
spec = self.find(name)
self.check_basic(spec, name, ispkg=True)
self.check_search_location(spec, source)
self.check_data(spec, source)
self.check_data(spec, source, ispkg=True)

def test_frozen_only(self):
name = '__hello_only__'
Expand Down