Skip to content

Commit 3c06704

Browse files
committed
build: allow a pure-Python wheel, and drop pkg_resources
Two changes that together let `vpython` be installed and imported under Pyodide/wasm. Both are opt-in or invisible to existing users: an ordinary `python -m build` still produces the same platform wheel it always did, and `install_requires` is untouched. 1. `VPYTHON_PURE_PYTHON=1` builds with no C extension, producing a `py3-none-any` wheel. micropip (and any other wasm installer) cannot install a platform wheel, and merely DECLARING `ext_modules` is what makes every wheel a platform wheel — so the key is now omitted entirely for that build rather than set to an empty list, which would not have changed the tag. Nothing is lost but speed: `_vector_import_helper` already falls back to the pure-Python `vector` when `cyvector` is unavailable. 2. `vpython/__init__.py` uses `importlib.metadata` instead of `pkg_resources`. pkg_resources is deprecated upstream and simply absent in Pyodide, so importing vpython there failed on the package's very first line. `python_requires` moves to >=3.8 accordingly (importlib.metadata is 3.8+; `notebook>=7` already required 3.8+, so this narrows nothing in practice). Verified in a real Pyodide 3.13.2 Web Worker, installing this branch's own pure wheel with `deps=False` and no setuptools present: OK vpython.vector OK vpython.vpython PACKAGE OK __version__ = 7.6.5 __gs_version__ = 3.2 `__gs_version__` resolving also confirms `gs_version.py` reads the bundled glow.min.js fine there, and that it is on the same 3.2 line trinket serves. Both builds were checked: with the flag, `vpython-7.6.5-py3-none-any.whl`; without it, `vpython-7.6.5-cp314-cp314-macosx_10_15_universal2.whl` as before. Execution now reaches the transport seam — `sphere()` stops at vpython.py:267 `from .no_notebook import _` (autobahn), which is the next piece of work, not a packaging problem.
1 parent a9a6bd4 commit 3c06704

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

‎setup.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import os
2+
13
from setuptools import setup
24

35
from distutils.extension import Extension
46

5-
try:
6-
from Cython.Build import cythonize
7-
USE_CYTHON = True
8-
extensions = cythonize('vpython/cyvector.pyx')
9-
except ImportError:
10-
extensions = [Extension('vpython.cyvector', ['vpython/cyvector.c'])]
7+
# Set VPYTHON_PURE_PYTHON=1 to build with no C extension at all. The result is a
8+
# `py3-none-any` wheel, which is what Pyodide/micropip and other wasm targets
9+
# require — they cannot install a platform wheel, and declaring `ext_modules` is
10+
# what makes every wheel a platform wheel.
11+
#
12+
# Nothing is lost but speed: `_vector_import_helper` already falls back to the
13+
# pure-Python `vector` implementation when `cyvector` cannot be imported, so the
14+
# same source runs either way. Ordinary builds are unchanged — this is opt-in.
15+
PURE_PYTHON = os.environ.get('VPYTHON_PURE_PYTHON', '').strip() not in ('', '0', 'false', 'False')
16+
17+
if PURE_PYTHON:
18+
extensions = []
19+
else:
20+
try:
21+
from Cython.Build import cythonize
22+
USE_CYTHON = True
23+
extensions = cythonize('vpython/cyvector.pyx')
24+
except ImportError:
25+
extensions = [Extension('vpython.cyvector', ['vpython/cyvector.c'])]
1126

1227

1328
install_requires = ['jupyter', 'jupyter-server-proxy', 'jupyterlab-vpython>=3.1.8', 'notebook>=7.0.0', 'numpy', 'ipykernel',
@@ -35,14 +50,19 @@
3550
'Topic :: Multimedia :: Graphics :: 3D Rendering',
3651
'Topic :: Scientific/Engineering :: Visualization',
3752
],
38-
ext_modules=extensions,
3953
install_requires=install_requires,
40-
python_requires=">=3.8",
54+
python_requires=">=3.8", # importlib.metadata, used in vpython/__init__.py
4155
package_data={'vpython': ['vpython_data/*',
4256
'vpython_libraries/*',
4357
'vpython_libraries/images/*']},
4458
)
4559

60+
# `ext_modules` is added only for a normal build. Omitting the key entirely (as
61+
# opposed to passing an empty list) is what makes setuptools tag the wheel
62+
# `py3-none-any` rather than a platform wheel.
63+
if not PURE_PYTHON:
64+
setup_args['ext_modules'] = extensions
65+
4666
try:
4767
setup(**setup_args)
4868
except SystemExit as e:

‎vpython/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# importlib.metadata, not pkg_resources: fresh Python 3.12+ environments no
22
# longer ship setuptools, so `import pkg_resources` raises ModuleNotFoundError
3-
# the moment `import vpython` runs (caught by CI's macos-3.12 leg).
3+
# the moment `import vpython` runs (caught by CI's macos-3.12 leg). The same
4+
# import is simply absent on Pyodide/wasm, so this also unblocks wasm targets.
45
from importlib.metadata import version as _dist_version, PackageNotFoundError
56

67
from .gs_version import glowscript_version

0 commit comments

Comments
 (0)