Skip to content

Commit

Permalink
sysconfig: make _sysconfigdata.py relocatable
Browse files Browse the repository at this point in the history
Co-authored-by: Алексей <[email protected]>
Co-authored-by: lovetox <[email protected]>
  • Loading branch information
3 people authored and lazka committed Aug 25, 2023
1 parent cce6ba9 commit 61a4f35
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys
import textwrap
from os.path import pardir, realpath

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

replacement = """
keys_to_replace = [
'BINDIR', 'BINLIBDEST', 'CONFINCLUDEDIR',
'CONFINCLUDEPY', 'DESTDIRS', 'DESTLIB', 'DESTSHARED',
'INCLDIRSTOMAKE', 'INCLUDEDIR', 'INCLUDEPY',
'LIBDEST', 'LIBDIR', 'LIBPC', 'LIBPL', 'MACHDESTLIB',
'MANDIR', 'SCRIPTDIR', 'datarootdir', 'exec_prefix',
'TZPATH',
]
prefix = build_time_vars['BINDIR'][:-4]
for key in keys_to_replace:
value = build_time_vars[key]
build_time_vars[key] = value.replace(prefix, sys.prefix)
"""

with open(destfile, 'w', encoding='utf8') as f:
f.write('import sys\n')
f.write('# system configuration generated and used by'
' the sysconfig module\n')
f.write('build_time_vars = ')
pprint.pprint(vars, stream=f)
f.write('\n%s' % textwrap.dedent(replacement))

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

0 comments on commit 61a4f35

Please sign in to comment.