From 7ee9118c73064f11cc97e271b320f4f712472320 Mon Sep 17 00:00:00 2001 From: rmorshea Date: Fri, 14 Apr 2023 18:32:24 -0700 Subject: [PATCH] fix dev env var + add publish workflow --- .github/workflows/publish.yml | 25 +++++++++++++++++++++++++ README.md | 17 ++++++++--------- noxfile.py | 7 +++++++ reactpy_jupyter/__init__.py | 2 +- reactpy_jupyter/widget.py | 6 ++++-- 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..4eb5d59 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +# This workflows will upload a Javscript Package using NPM to npmjs.org when a release is created +# For more information see: https://docs.github.com/en/actions/guides/publishing-nodejs-packages + +name: publish + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 14 + - uses: actions/setup-python@v2 + with: + python-version: "3.x" + - run: pip install noxopt + - run: nox -s publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} diff --git a/README.md b/README.md index 8ba9327..0b0db7b 100644 --- a/README.md +++ b/README.md @@ -91,16 +91,15 @@ For a development installation (requires [Node.js](https://nodejs.org) and [Yarn $ git clone https://github.com/reactive-python/reactpy-jupyter.git $ cd reactpy-jupyter $ pip install -e . - $ jupyter nbextension install --py --symlink --overwrite --sys-prefix reactpy_jupyter - $ jupyter nbextension enable --py --sys-prefix reactpy_jupyter -When actively developing your extension for JupyterLab, run the command: +To automatically re-build and refresh Jupyter when making changes start a Vite dev server: - $ jupyter labextension develop --overwrite reactpy_jupyter + $ npx vite -Then you need to rebuild the JS when you make a code change: +Then, before importing `reactpy_jupyter` set the following environment variable: - $ cd js - $ yarn run build - -You then need to refresh the JupyterLab page when your javascript changes. +```python +import os +os.environ["REACTPY_JUPYTER_DEV"] = "1" +import reactpy_jupyter +``` diff --git a/noxfile.py b/noxfile.py index 492c1fd..053460b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,3 +20,10 @@ def check_python(session: Session) -> None: def check_javascript(session: Session) -> None: session.run("npm", "ci", external=True) session.run("npm", "run", "lint", external=True) + + +@group.session +def publish(session: Session) -> None: + session.install("twine", "build", "wheel") + session.run("python", "-m", "build", "--sdist", "--wheel", "--outdir", "dist/") + session.run("twine", "upload", "dist/*") diff --git a/reactpy_jupyter/__init__.py b/reactpy_jupyter/__init__.py index b1c9d27..f8ca9fa 100644 --- a/reactpy_jupyter/__init__.py +++ b/reactpy_jupyter/__init__.py @@ -9,7 +9,7 @@ from .ipython_extension import load_ipython_extension, unload_ipython_extension from .widget import LayoutWidget, run, set_import_source_base_url, widgetize -__version__ = "0.8.0" # DO NOT MODIFY +__version__ = "0.8.1" # DO NOT MODIFY __all__ = [ "LayoutWidget", diff --git a/reactpy_jupyter/widget.py b/reactpy_jupyter/widget.py index 166ebfa..397d055 100644 --- a/reactpy_jupyter/widget.py +++ b/reactpy_jupyter/widget.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import os from functools import wraps from pathlib import Path from queue import Queue as SyncQueue @@ -11,13 +12,14 @@ from IPython.display import DisplayHandle from IPython.display import display as ipython_display from jsonpointer import set_pointer -from reactpy.config import REACTPY_DEBUG_MODE from reactpy.core.layout import Layout from reactpy.core.types import ComponentType from traitlets import Unicode from typing_extensions import ParamSpec -if REACTPY_DEBUG_MODE.current: +DEV = bool(int(os.environ.get("REACTPY_JUPYTER_DEV", "0"))) + +if DEV: # from `npx vite` ESM = "http://localhost:5173/src/index.js?anywidget" else: