Skip to content

Commit fac0109

Browse files
Allow overriding _f2c_fixes.py from user (#8)
While most parts of pyodide-build are decoupled with pyodide/pyodide, `_f2c_fixes.py` file that is used to build scipy is highly coupled with the scipy recipe in pyodide/pyodide. It would be very inefficient if we need to update pyodide-build whenever we fix scipy (e.g. pyodide/pyodide#4818). Therefore, this add a private config variable `_f2c_fixes_wrapper`, which allows users to modify override `_f2c_fixes.py` file without touching pyodide-build itself. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 833135c commit fac0109

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.27.3] - 2024/07/17
11+
12+
- It is now possible to override `_f2c_fixes.py` file, with `_f2c_fixes_wrapper` variable.
13+
[#8](https://github.com/pyodide/pyodide-build/pull/8)
14+
1015
## [0.27.2] - 2024/07/11
1116

1217
## Changed

pyodide_build/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def to_env(self) -> dict[str, str]:
169169
"home": "HOME",
170170
"path": "PATH",
171171
"zip_compression_level": "PYODIDE_ZIP_COMPRESSION_LEVEL",
172+
# maintainer only
173+
"_f2c_fixes_wrapper": "_F2C_FIXES_WRAPPER",
172174
}
173175

174176
BUILD_VAR_TO_KEY = {v: k for k, v in BUILD_KEY_TO_VAR.items()}
@@ -181,6 +183,8 @@ def to_env(self) -> dict[str, str]:
181183
"ldflags",
182184
"rust_toolchain",
183185
"meson_cross_file",
186+
# maintainer only
187+
"_f2c_fixes_wrapper",
184188
}
185189

186190
# Default configuration values.
@@ -197,6 +201,8 @@ def to_env(self) -> dict[str, str]:
197201
"rust_toolchain": "nightly-2024-01-29",
198202
# Other configuration
199203
"pyodide_jobs": "1",
204+
# maintainer only
205+
"_f2c_fixes_wrapper": "",
200206
}
201207

202208
# Default configs that are computed from other values (often from Makefile.envs)

pyodide_build/pypabuild.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from build.env import DefaultIsolatedEnv
1616
from packaging.requirements import Requirement
1717

18-
from . import common, pywasmcross
18+
from . import _f2c_fixes, common, pywasmcross
1919
from .build_env import (
2020
get_build_flag,
2121
get_hostsitepackages,
@@ -214,10 +214,20 @@ def make_command_wrapper_symlinks(symlink_dir: Path) -> dict[str, str]:
214214
The dictionary of compiler environment variables that points to the symlinks.
215215
"""
216216

217+
# For maintainers:
218+
# - you can set "_f2c_fixes_wrapper" variable in pyproject.toml
219+
# in order to change the script to use when cross-compiling
220+
# this is only for maintainers and *should* not be used by others
221+
217222
pywasmcross_exe = symlink_dir / "pywasmcross.py"
218-
shutil.copy2(pywasmcross.__file__, pywasmcross_exe)
223+
pywasmcross_origin = pywasmcross.__file__
224+
shutil.copy2(pywasmcross_origin, pywasmcross_exe)
219225
pywasmcross_exe.chmod(0o755)
220226

227+
f2c_fixes_exe = symlink_dir / "_f2c_fixes.py"
228+
f2c_fixes_origin = get_build_flag("_F2C_FIXES_WRAPPER") or _f2c_fixes.__file__
229+
shutil.copy2(f2c_fixes_origin, f2c_fixes_exe)
230+
221231
env = {}
222232
for symlink in pywasmcross.SYMLINKS:
223233
symlink_path = symlink_dir / symlink
@@ -266,7 +276,7 @@ def get_build_env(
266276
env.update(make_command_wrapper_symlinks(symlink_dir))
267277

268278
sysconfig_dir = Path(get_build_flag("TARGETINSTALLDIR")) / "sysconfigdata"
269-
args["PYTHONPATH"] = sys.path + [str(sysconfig_dir)]
279+
args["PYTHONPATH"] = sys.path + [str(symlink_dir), str(sysconfig_dir)]
270280
args["orig__name__"] = __name__
271281
args["pythoninclude"] = get_build_flag("PYTHONINCLUDE")
272282
args["PATH"] = env["PATH"]

pyodide_build/pywasmcross.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def handle_command(
591591
"""
592592

593593
if line[0] == "gfortran":
594-
from pyodide_build._f2c_fixes import replay_f2c
594+
from _f2c_fixes import replay_f2c
595595

596596
tmp = replay_f2c(line)
597597
if tmp is None:
@@ -604,7 +604,7 @@ def handle_command(
604604
new_args = handle_command_generate_args(line, build_args)
605605

606606
if build_args.pkgname == "scipy":
607-
from pyodide_build._f2c_fixes import scipy_fixes
607+
from _f2c_fixes import scipy_fixes
608608

609609
scipy_fixes(new_args)
610610

pyodide_build/tests/test_pypabuild.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,25 @@ def test_make_command_wrapper_symlinks(tmp_path):
5050
assert key in pypabuild.SYMLINK_ENV_VARS.values()
5151

5252

53-
def test_get_build_env(tmp_path):
53+
def test_make_command_wrapper_symlinks_f2c_wrapper(
54+
tmp_path, dummy_xbuildenv, reset_env_vars, reset_cache
55+
):
56+
import os
57+
58+
dummy_f2c_wrapper = tmp_path / "_dummy_f2c_fixes.py"
59+
dummy_f2c_wrapper.write_text("print('Hello, world!')")
60+
61+
os.environ["_F2C_FIXES_WRAPPER"] = str(dummy_f2c_wrapper)
62+
63+
symlink_dir = tmp_path
64+
pypabuild.make_command_wrapper_symlinks(symlink_dir)
65+
66+
wrapper = symlink_dir / "_f2c_fixes.py"
67+
assert wrapper.exists()
68+
assert wrapper.read_text() == dummy_f2c_wrapper.read_text()
69+
70+
71+
def test_get_build_env(tmp_path, dummy_xbuildenv):
5472
build_env_ctx = pypabuild.get_build_env(
5573
env={"PATH": ""},
5674
pkgname="",

0 commit comments

Comments
 (0)