MCPcopy Index your code
hub / github.com/RustPython/RustPython / _generate_posix_vars

Function _generate_posix_vars

Lib/sysconfig/__main__.py:176–248  ·  view source on GitHub ↗

Generate the Python module containing build-time variables.

()

Source from the content-addressed store, hash-verified

174
175
176def _generate_posix_vars():
177 """Generate the Python module containing build-time variables."""
178 vars = {}
179 # load the installed Makefile:
180 makefile = get_makefile_filename()
181 try:
182 _parse_makefile(makefile, vars)
183 except OSError as e:
184 msg = f"invalid Python installation: unable to open {makefile}"
185 if hasattr(e, "strerror"):
186 msg = f"{msg} ({e.strerror})"
187 raise OSError(msg)
188 # load the installed pyconfig.h:
189 config_h = get_config_h_filename()
190 try:
191 with open(config_h, encoding="utf-8") as f:
192 parse_config_h(f, vars)
193 except OSError as e:
194 msg = f"invalid Python installation: unable to open {config_h}"
195 if hasattr(e, "strerror"):
196 msg = f"{msg} ({e.strerror})"
197 raise OSError(msg)
198 # On AIX, there are wrong paths to the linker scripts in the Makefile
199 # -- these paths are relative to the Python source, but when installed
200 # the scripts are in another directory.
201 if _PYTHON_BUILD:
202 vars['BLDSHARED'] = vars['LDSHARED']
203
204 name = _get_sysconfigdata_name()
205
206 # There's a chicken-and-egg situation on OS X with regards to the
207 # _sysconfigdata module after the changes introduced by #15298:
208 # get_config_vars() is called by get_platform() as part of the
209 # `make pybuilddir.txt` target -- which is a precursor to the
210 # _sysconfigdata.py module being constructed. Unfortunately,
211 # get_config_vars() eventually calls _init_posix(), which attempts
212 # to import _sysconfigdata, which we won't have built yet. In order
213 # for _init_posix() to work, if we're on Darwin, just mock up the
214 # _sysconfigdata module manually and populate it with the build vars.
215 # This is more than sufficient for ensuring the subsequent call to
216 # get_platform() succeeds.
217 # GH-127178: Since we started generating a .json file, we also need this to
218 # be able to run sysconfig.get_config_vars().
219 module = types.ModuleType(name)
220 module.build_time_vars = vars
221 sys.modules[name] = module
222
223 pybuilddir = _get_pybuilddir()
224 os.makedirs(pybuilddir, exist_ok=True)
225 destfile = os.path.join(pybuilddir, name + '.py')
226
227 with open(destfile, 'w', encoding='utf8') as f:
228 f.write('# system configuration generated and used by'
229 ' the sysconfig module\n')
230 f.write('build_time_vars = ')
231 _print_config_dict(vars, stream=f)
232
233 print(f'Written {destfile}')

Callers 1

_mainFunction · 0.85

Calls 15

get_makefile_filenameFunction · 0.90
get_config_h_filenameFunction · 0.90
parse_config_hFunction · 0.90
_get_sysconfigdata_nameFunction · 0.90
get_config_varsFunction · 0.90
_parse_makefileFunction · 0.85
hasattrFunction · 0.85
_get_pybuilddirFunction · 0.85
_print_config_dictFunction · 0.85
_get_json_data_nameFunction · 0.85
openFunction · 0.50
printFunction · 0.50

Tested by

no test coverage detected