Skip to content

Commit 31e1732

Browse files
committed
pythonbuild: prepare to support dynamic extension modules
We introduce a dict capturing the Setup.local lines for each section. This will allow us to conditionally write extensions to different sections.
1 parent 0248aae commit 31e1732

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pythonbuild/cpython.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ def derive_setup_local(
385385

386386
# Translate our YAML metadata into Setup lines.
387387

388-
# All extensions are statically linked.
389-
dest_lines = [b"*static*"]
388+
section_lines = {
389+
"disabled": [],
390+
"static": [],
391+
}
390392

391393
# makesetup parses lines with = as extra config options. There appears
392394
# to be no easy way to define e.g. -Dfoo=bar in Setup.local. We hack
@@ -397,7 +399,11 @@ def derive_setup_local(
397399
enabled_extensions = {}
398400

399401
for name, info in sorted(extension_modules.items()):
400-
if name in disabled or name in ignored:
402+
if name in ignored:
403+
continue
404+
405+
if name in disabled:
406+
section_lines["disabled"].append(name.encode("ascii"))
401407
continue
402408

403409
enabled_extensions[name] = dict(info)
@@ -421,6 +427,8 @@ def derive_setup_local(
421427
enabled_extensions[name]["setup_line"] = name.encode("ascii")
422428
continue
423429

430+
section = "static"
431+
424432
# Presumably this means the extension comes from the distribution's
425433
# Setup. Lack of sources means we don't need to derive a Setup.local
426434
# line.
@@ -535,11 +543,14 @@ def derive_setup_local(
535543
"makesetup: %s" % line.decode("utf-8")
536544
)
537545

538-
dest_lines.append(line)
546+
section_lines[section].append(line)
539547
enabled_extensions[name]["setup_line"] = line
540548

541-
dest_lines.append(b"\n*disabled*\n")
542-
dest_lines.extend(sorted(x.encode("ascii") for x in disabled))
549+
dest_lines = []
550+
551+
for section, lines in sorted(section_lines.items()):
552+
dest_lines.append(b"\n*%s*\n" % section.encode("ascii"))
553+
dest_lines.extend(lines)
543554

544555
dest_lines.append(b"")
545556

0 commit comments

Comments
 (0)