Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,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
Comment thread
ericmjl marked this conversation as resolved.
needs: check_changes
# Run if it's a release or if relevant files changed on main
if: |
Expand All @@ -161,26 +161,35 @@ jobs:
- name: Set up Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: '3.11'

- name: Install dependencies
run: pip install --upgrade setuptools numpy versioneer wheel
python-version: '3.12'

- 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@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
# 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: universal_wheel
path: dist/*.whl
name: pyodide_wheel
path: dist/*wasm32.whl

check_dist:
name: Check dist
Expand Down Expand Up @@ -216,6 +225,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)
Expand All @@ -240,10 +268,5 @@ jobs:
path: dist
merge-multiple: true

- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
with:
name: universal_wheel
path: dist

- uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
# Implicitly attests that the packages were uploaded in the context of this workflow.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pytensor.readthedocs.io/en/latest/install.html>`__.


Background
==========

Expand Down
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <install>`.

For browser-based Python environments (Pyodide/JupyterLite), see :ref:`the Pyodide installation section <install-pyodide>`.

.. _available on PyPI: http://pypi.python.org/pypi/pytensor
.. _Related Projects: https://github.com/pymc-devs/pytensor/wiki/Related-projects

Expand Down
21 changes: 21 additions & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://numba.readthedocs.io/en/stable/user/installing.html>`__ and `JAX's installation instructions <https://github.com/google/jax#installation>`__ respectively.


Installing on Pyodide (WebAssembly)
-----------------------------------

.. _install-pyodide:

PyTensor can be used in browser-based Python environments via `Pyodide <https://pyodide.org/>`__, such as `JupyterLite <https://jupyterlite.readthedocs.io/>`__.

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.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies = [
"setuptools>=59.0.0",
"scipy>=1,<2",
"numpy>=2.0",
"numba>0.57,<1",
"numba>0.57,<1; platform_machine != 'wasm32' and sys_platform != 'emscripten'",
"filelock>=3.15",
"etuples",
"logical-unification",
Expand Down Expand Up @@ -82,6 +82,7 @@ tests = [
rtd = ["sphinx>=5.1.0,<6", "pygments", "pydot"]
jax = ["jax", "jaxlib"]
numba = ["numba>=0.57", "llvmlite"]
pyodide = ["pyodide-build>=0.29.2"]

[tool.setuptools.packages.find]
include = ["pytensor*"]
Expand Down
Loading