Skip to content

Commit 7973e36

Browse files
committed
Modified freeze_modules to accept recursive modules with pyfile
The pyfile that is specified in the module metadata wasn't allowed to be a folder. This is a problem to us, as the gdb module is not a single python file. These modifications allow people to add pyfile recursive dirs from non-Lib locations. Also modified deep_freeze.py to accept surrogates in text it receives. Not sure why it received surrogates though, something from pygments.
1 parent 30af7eb commit 7973e36

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Tools/build/deepfreeze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def generate_unicode(self, name: str, s: str) -> str:
222222
self.write(".compact = 1,")
223223
self.write(".ascii = 0,")
224224
self.write(".statically_allocated = 1,")
225-
utf8 = s.encode('utf-8')
225+
utf8 = s.encode('utf-8', 'surrogatepass')
226226
self.write(f'.utf8 = {make_string_literal(utf8)},')
227227
self.write(f'.utf8_length = {len(utf8)},')
228228
with self.block(f"._data =", ","):

Tools/build/freeze_modules.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,18 @@ def _parse_spec(spec, knownids=None, section=None):
321321
else:
322322
pyfile = _resolve_module(frozenid, ispkg=False)
323323
ispkg = True
324-
elif pyfile:
324+
elif pyfile and not os.path.isdir(pyfile):
325325
assert check_modname(frozenid), spec
326326
assert not knownids or frozenid not in knownids, spec
327327
assert check_modname(modname), spec
328-
assert not os.path.isdir(pyfile), spec
329328
ispkg = False
330329
elif knownids and frozenid in knownids:
331330
assert check_modname(frozenid), spec
332331
assert check_modname(modname), spec
333332
ispkg = False
334333
else:
335334
assert not modname or check_modname(modname), spec
336-
resolved = iter(resolve_modules(frozenid))
335+
resolved = iter(resolve_modules(frozenid, pyfile if os.path.isdir(pyfile) else None))
337336
frozenid, pyfile, ispkg = next(resolved)
338337
if not modname:
339338
modname = frozenid

0 commit comments

Comments
 (0)