Skip to content

Commit 61a4f35

Browse files
mingwandroidAlexpuxlovetox
authored andcommitted
sysconfig: make _sysconfigdata.py relocatable
Co-authored-by: Алексей <[email protected]> Co-authored-by: lovetox <[email protected]>
1 parent cce6ba9 commit 61a4f35

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/sysconfig.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import textwrap
56
from os.path import pardir, realpath
67

78
__all__ = [
@@ -514,11 +515,30 @@ def _generate_posix_vars():
514515
os.makedirs(pybuilddir, exist_ok=True)
515516
destfile = os.path.join(pybuilddir, name + '.py')
516517

518+
replacement = """
519+
keys_to_replace = [
520+
'BINDIR', 'BINLIBDEST', 'CONFINCLUDEDIR',
521+
'CONFINCLUDEPY', 'DESTDIRS', 'DESTLIB', 'DESTSHARED',
522+
'INCLDIRSTOMAKE', 'INCLUDEDIR', 'INCLUDEPY',
523+
'LIBDEST', 'LIBDIR', 'LIBPC', 'LIBPL', 'MACHDESTLIB',
524+
'MANDIR', 'SCRIPTDIR', 'datarootdir', 'exec_prefix',
525+
'TZPATH',
526+
]
527+
528+
prefix = build_time_vars['BINDIR'][:-4]
529+
530+
for key in keys_to_replace:
531+
value = build_time_vars[key]
532+
build_time_vars[key] = value.replace(prefix, sys.prefix)
533+
"""
534+
517535
with open(destfile, 'w', encoding='utf8') as f:
536+
f.write('import sys\n')
518537
f.write('# system configuration generated and used by'
519538
' the sysconfig module\n')
520539
f.write('build_time_vars = ')
521540
pprint.pprint(vars, stream=f)
541+
f.write('\n%s' % textwrap.dedent(replacement))
522542

523543
# Create file used for sys.path fixup -- see Modules/getpath.c
524544
with open('pybuilddir.txt', 'w', encoding='utf8') as f:

0 commit comments

Comments
 (0)