Skip to content

✨ NEW: Support local .whl packages #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions docs/example_md.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ py-config:
autoclose: true
packages:
- matplotlib
- hallo_world-0.1.0-py2.py3-none-any.whl
---

# Example with MyST
Expand Down
1 change: 1 addition & 0 deletions docs/example_rst.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
autoclose: true
packages:
- matplotlib
- hallo_world-0.1.0-py2.py3-none-any.whl

Example with RST
================
Expand Down
Binary file added docs/hallo_world-0.1.0-py2.py3-none-any.whl
Binary file not shown.
24 changes: 24 additions & 0 deletions src/sphinx_pyscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
__version__ = "0.1.0"

import json
import os
from pathlib import Path

import yaml
Expand Down Expand Up @@ -134,6 +135,7 @@ def doctree_read(app: Sphinx, doctree: nodes.document):
)
else:
doctree["pyscript"] = True
_copy_wheels(app, data)
data_str = json.dumps(data, indent=2)
doctree.append(
nodes.raw(
Expand All @@ -142,3 +144,25 @@ def doctree_read(app: Sphinx, doctree: nodes.document):
format="html",
)
)


def _copy_wheels(app: Sphinx, data: dict) -> None:
"""Copy wheels to the output directory."""
packages = []
for pkg in data.get("packages", []):
if pkg.endswith(".whl"):
rel_filename, filename = app.env.relfn2path(pkg, app.env.docname)
app.env.dependencies[app.env.docname].add(rel_filename)
if not os.access(filename, os.R_OK):
LOGGER.warning(
f"Could not read pyscript wheel: {filename}",
location=(app.env.docname, 0),
)
continue
packages.append(
"_downloads/" + app.env.dlfiles.add_file(app.env.docname, rel_filename)
)
else:
packages.append(pkg)
if packages:
data["packages"] = packages