Skip to content

Commit

Permalink
Merge branch 'pyodide:main' into patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbroere committed Feb 28, 2024
2 parents fdffb7c + 07a0607 commit 07debdc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cpython/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sysconfigdata:
# the subfolder is written to pybuilddir.txt.
cd $(PYBUILD) && _PYTHON_SYSCONFIGDATA_NAME=$(SYSCONFIG_NAME) _PYTHON_PROJECT_BASE=$(PYBUILD) $(HOSTPYTHON) -m sysconfig --generate-posix-vars
$(eval PYBUILDDIR=$(PYBUILD)/`cat $(PYBUILD)/pybuilddir.txt`)
PYTHONPATH=$(PYBUILDDIR) python$(PYMAJOR).$(PYMINOR) adjust_sysconfig.py
PYODIDE_ROOT=$(PYODIDE_ROOT) PYTHONPATH=$(PYBUILDDIR) python$(PYMAJOR).$(PYMINOR) adjust_sysconfig.py
mkdir -p $(PYINSTALL)/lib/python$(PYMAJOR).$(PYMINOR)/
mkdir -p $(SYSCONFIGDATA_DIR)
cp $(PYBUILDDIR)/$(SYSCONFIG_NAME).py $(PYINSTALL)/lib/python$(PYMAJOR).$(PYMINOR)/
Expand Down Expand Up @@ -73,13 +73,13 @@ $(PYTARBALL):
@GOT_SHASUM=`shasum --algorithm 256 $(PYTARBALL) | cut -f1 -d' '` \
&& (echo $$GOT_SHASUM | grep -q $(PYTHON_ARCHIVE_SHA256)) \
|| (\
echo "Got unexpected shasum $$GOT_SHASUM" \
rm $@ \
&& echo "Got unexpected shasum $$GOT_SHASUM" \
&& echo "If you are updating the Python version, set PYTHON_ARCHIVE_SHA256 in Makefile.envs to this." \
&& exit 1 \
)



prepare-source: $(PYBUILD)/.patched

$(PYBUILD)/.patched: $(PYTARBALL)
Expand Down
33 changes: 29 additions & 4 deletions cpython/adjust_sysconfig.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import os
import pprint
from textwrap import dedent

PYODIDE_ROOT = os.environ["PYODIDE_ROOT"]


def load_sysconfig(sysconfig_name: str):
_temp = __import__(sysconfig_name, globals(), locals(), ["build_time_vars"], 0)
config_vars = _temp.build_time_vars
return config_vars, _temp.__file__


def write_sysconfig(destfile: str, config_vars: dict[str, str]):
def write_sysconfig(destfile: str, fmted_config_vars: dict[str, str]):
with open(destfile, "w", encoding="utf8") as f:
f.write("# system configuration generated and used by the sysconfig module\n")
# Set PYODIDE_ROOT
f.write("import os\n")
f.write(f'PYODIDE_ROOT = os.environ.get("PYODIDE_ROOT", "{PYODIDE_ROOT}")\n')
f.write("build_time_vars = ")
pprint.pprint(config_vars, stream=f)
f.write(fmted_config_vars)
# at build time, packages that are looking for the Python includes and
# libraries can get deceived by the values of platbase and
# installed_base (and possibly others, but we haven't run into trouble
Expand Down Expand Up @@ -44,10 +48,31 @@ def adjust_sysconfig(config_vars: dict[str, str]):
CXX="c++",
LDCXXSHARED="c++",
)
for [key, val] in config_vars.items():
if not isinstance(val, str):
continue
# Make sysconfigdata relocatable.
# Replace all instances of "/path/to/pyodide" with "{PYODIDE_ROOT}"
val = val.replace(f"{PYODIDE_ROOT}", "{PYODIDE_ROOT}")
# If we made a replacement, then prefix the string with `--tofstring--`
# so we can convert it to an fstring below
if "PYODIDE_ROOT" in val:
val = "--tofstring--" + val
config_vars[key] = val


def format_sysconfig(config_vars: dict[str, str]) -> str:
fmted_config_vars = repr(config_vars)
# Make any string that begins with `--tofstring--` into an fstring and
# remove the prefix.
fmted_config_vars = fmted_config_vars.replace("'--tofstring--", "f'")
fmted_config_vars = fmted_config_vars.replace('"--tofstring--', 'f"')
return fmted_config_vars


if __name__ == "__main__":
sysconfig_name = os.environ["SYSCONFIG_NAME"]
config_vars, file = load_sysconfig(sysconfig_name)
adjust_sysconfig(config_vars)
write_sysconfig(file, config_vars)
fmted_config_vars = format_sysconfig(config_vars)
write_sysconfig(file, fmted_config_vars)

0 comments on commit 07debdc

Please sign in to comment.