MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / pyodide_setup

Function pyodide_setup

scripts/test.py:1217–1302  ·  view source on GitHub ↗

Returns a command that will set things up for a pyodide build. Args: directory: Our command cd's into this directory. clean: If true we create an entirely new environment. Otherwise we reuse any existing emsdk repository and venv.

(
        directory,
        clean=False,
        pyodide_build_version=None,
        )

Source from the content-addressed store, hash-verified

1215
1216
1217def pyodide_setup(
1218 directory,
1219 clean=False,
1220 pyodide_build_version=None,
1221 ):
1222 '''
1223 Returns a command that will set things up for a pyodide build.
1224
1225 Args:
1226 directory:
1227 Our command cd's into this directory.
1228 clean:
1229 If true we create an entirely new environment. Otherwise
1230 we reuse any existing emsdk repository and venv.
1231 pyodide_build_version:
1232 Version of Python package pyodide-build; if None we use latest
1233 available version.
1234 2025-02-13: pyodide_build_version='0.29.3' works.
1235
1236 The returned command does the following:
1237
1238 * Checkout latest emsdk from https://github.com/emscripten-core/emsdk.git:
1239 * Clone emsdk repository to `emsdk` if not already present.
1240 * Run `git pull -r` inside emsdk checkout.
1241 * Create venv `venv_pyodide_<python_version>` if not already present.
1242 * Activate venv `venv_pyodide_<python_version>`.
1243 * Install/upgrade package `pyodide-build`.
1244 * Run emsdk install scripts and enter emsdk environment.
1245
1246 Example usage in a build function:
1247
1248 command = pyodide_setup()
1249 command += ' && pyodide build --exports pyinit'
1250 subprocess.run(command, shell=1, check=1)
1251 ''&#x27;
1252
1253 pv = platform.python_version_tuple()[:2]
1254 assert pv == ('3', '12'), f'Pyodide builds need to be run with Python-3.12 but current Python is {platform.python_version()}.'
1255 command = f'cd {directory}'
1256
1257 # Clone/update emsdk. We always use the latest emsdk with `git pull`.
1258 #
1259 # 2025-02-13: this works: 2514ec738de72cebbba7f4fdba0cf2fabcb779a5
1260 #
1261 dir_emsdk = 'emsdk'
1262 if clean:
1263 shutil.rmtree(dir_emsdk, ignore_errors=1)
1264 # 2024-06-25: old `.pyodide-xbuildenv` directory was breaking build, so
1265 # important to remove it here.
1266 shutil.rmtree('.pyodide-xbuildenv', ignore_errors=1)
1267 if not os.path.exists(f'{directory}/{dir_emsdk}'):
1268 command += f' && echo "### Cloning emsdk.git"'
1269 command += f' && git clone https://github.com/emscripten-core/emsdk.git {dir_emsdk}'
1270 command += f' && echo "### Updating checkout {dir_emsdk}"'
1271 command += f' && (cd {dir_emsdk} && git pull -r)'
1272 command += f' && echo "### Checkout {dir_emsdk} is:"'
1273 command += f' && (cd {dir_emsdk} && git show -s --oneline)'
1274

Callers 1

build_pyodide_wheelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…