diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 9503eba1aa..1b8a7ca7de 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -129,8 +129,8 @@ jobs: name: wheels-${{ matrix.platform }} path: ./wheelhouse/*.whl - build_universal_wheel: - name: Build universal wheel for Pyodide + build_pyodide_wheel: + name: Build Pyodide (WASM) wheel needs: check_changes # Run if it's a release or if relevant files changed on main if: | @@ -150,24 +150,34 @@ jobs: with: python-version: '3.12' - - name: Install dependencies - run: pip install --upgrade setuptools numpy versioneer wheel - - - name: Build universal wheel + - name: Get Emscripten version for pyodide-build + id: emscripten run: | - PYODIDE=1 python setup.py bdist_wheel --universal + pip install pyodide-build>=0.29.2 + echo "version=$(pyodide config get emscripten_version)" >> $GITHUB_OUTPUT + + - name: Set up Emscripten + uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14 + with: + version: ${{ steps.emscripten.outputs.version }} + + - name: Install project with pyodide extra + run: pip install -e ".[pyodide]" + + - name: Build Pyodide wheel + run: pyodide build - name: Attest GitHub build provenance uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1 # Don't attest from forks if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository with: - subject-path: dist/*.whl + subject-path: dist/*wasm32.whl - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: - name: universal_wheel - path: dist/*.whl + name: pyodide_wheel + path: dist/*wasm32.whl check_dist: name: Check dist @@ -203,6 +213,25 @@ jobs: - run: pipx run twine check --strict dist/* + upload_pyodide_to_release: + name: Upload Pyodide wheel to GitHub Release + needs: [build_pyodide_wheel] + runs-on: ubuntu-latest + if: github.repository_owner == 'pymc-devs' && github.event_name == 'release' && github.event.action == 'published' + permissions: + contents: write + steps: + - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 + with: + name: pyodide_wheel + path: dist + + - name: Upload Pyodide wheel to Release + run: gh release upload "$RELEASE_TAG" dist/*.whl + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: ${{ github.event.release.tag_name }} + upload_pypi: name: Upload to PyPI on release # Use the `release` GitHub environment to protect the Trusted Publishing (OIDC) @@ -226,10 +255,5 @@ jobs: path: dist merge-multiple: true - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - name: universal_wheel - path: dist - - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 # Implicitly attests that the packages were uploaded in the context of this workflow. diff --git a/README.rst b/README.rst index 76299252db..fd502aa98b 100644 --- a/README.rst +++ b/README.rst @@ -115,6 +115,9 @@ The current development branch of |Project Name| can be installed from GitHub, a pip install git+https://github.com/pymc-devs/pytensor +For browser-based Python environments (Pyodide/JupyterLite), see the `Pyodide installation instructions `__. + + Background ========== diff --git a/doc/index.rst b/doc/index.rst index a70a28df82..886a5bfdb2 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -41,6 +41,8 @@ directory, so that when you pull updates via Git, they will be automatically reflected the "installed" version. For more information about installation and configuration, see :ref:`installing PyTensor `. +For browser-based Python environments (Pyodide/JupyterLite), see :ref:`the Pyodide installation section `. + .. _available on PyPI: http://pypi.python.org/pypi/pytensor .. _Related Projects: https://github.com/pymc-devs/pytensor/wiki/Related-projects diff --git a/doc/install.rst b/doc/install.rst index 71ff66a53e..cf9661a43b 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -26,3 +26,24 @@ The current development branch of PyTensor can be installed from GitHub using `p To use the Numba and JAX backend you will need to install these libraries in addition to PyTensor. Please refer to `Numba's installation instructions `__ and `JAX's installation instructions `__ respectively. + + +Installing on Pyodide (WebAssembly) +----------------------------------- + +.. _install-pyodide: + +PyTensor can be used in browser-based Python environments via `Pyodide `__, such as `JupyterLite `__. + +PyPI does not yet accept WebAssembly wheels, so you'll need to install from a GitHub Release: + +.. code-block:: python + + import micropip + micropip.install("https://github.com/pymc-devs/pytensor/releases/download/vVERSION/pytensor-VERSION-py312-py312-pyodide_2024_0_wasm32.whl") + +Replace ``VERSION`` with the desired release version (e.g., ``2.26.4``). + +.. note:: + + The Numba backend is not available on Pyodide/wasm32. PyTensor will use other backends automatically. diff --git a/pyproject.toml b/pyproject.toml index d18a1ae0bb..0e73f76660 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,6 +85,7 @@ kanren = [ "miniKanren", "cons", ] +pyodide = ["pyodide-build>=0.29.2"] [tool.setuptools.packages.find] include = ["pytensor*"]