Skip to content

Commit

Permalink
Poetry+Hatch Monorepo (#1002)
Browse files Browse the repository at this point in the history
* re-organize dirs + start using hatch

* setup root pyproject.toml + basic invoke tasks

* add publish task

* more ruff fixes

* get workflows to run

* split up script runs

* rename to check

* change matrix order

* make ruff happy

* get tests to pass

* check semver

* more fixes

* ignore missing coverage

* fix cov

* fix import sort

* try build in env-js

* try latest hatch-build-scripts

* misc fixes

* try to fix npm in gh action

* do not set registry url by default

* allow re-runs

* no need for extra build

* fix doc build and tests

* remove scripts

* fix tests

* update contributor guide
  • Loading branch information
rmorshea authored Jun 3, 2023
1 parent cf7950d commit ac58266
Show file tree
Hide file tree
Showing 198 changed files with 3,859 additions and 1,916 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: Nox Session
name: hatch-run

on:
workflow_call:
inputs:
job-name:
required: true
type: string
nox-args:
hatch-run:
required: true
type: string
nox-session-args:
required: false
type: string
runs-on-array:
required: false
type: string
Expand All @@ -20,6 +17,10 @@ on:
required: false
type: string
default: '["3.x"]'
node-registry-url:
required: false
type: string
default: ""
secrets:
node-auth-token:
required: false
Expand All @@ -29,30 +30,30 @@ on:
required: false

jobs:
nox-session:
hatch:
name: ${{ format(inputs.job-name, matrix.python-version, matrix.runs-on) }}
strategy:
matrix:
runs-on: ${{ fromJson(inputs.runs-on-array) }}
python-version: ${{ fromJson(inputs.python-version-array) }}
runs-on: ${{ fromJson(inputs.runs-on-array) }}
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14.x"
registry-url: "https://registry.npmjs.org"
registry-url: ${{ inputs.node-registry-url }}
- name: Pin NPM Version
run: npm install -g [email protected]
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Dependencies
run: pip install -r requirements/nox-deps.txt
- name: Run Sessions
run: pip install hatch poetry
- name: Run Scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.node-auth-token }}
PYPI_USERNAME: ${{ secrets.pypi-username }}
PYPI_PASSWORD: ${{ secrets.pypi-password }}
run: nox ${{ inputs.nox-args }} --stop-on-first-error -- ${{ inputs.nox-session-args }}
run: hatch run ${{ inputs.hatch-run }}
45 changes: 45 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: check

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * 0"

jobs:
test-py-cov:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "python-{0}"
hatch-run: "test-py"
lint-py:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "python-{0}"
hatch-run: "lint-py"
test-py-matrix:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "python-{0} {1}"
hatch-run: "test-py --no-cov"
runs-on-array: '["ubuntu-latest", "macos-latest", "windows-latest"]'
python-version-array: '["3.9", "3.10", "3.11"]'
test-docs:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "python-{0}"
hatch-run: "test-docs"
test-js:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "{1}"
hatch-run: "test-js"
lint-js:
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "{1}"
hatch-run: "lint-js"
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ on:

jobs:
publish:
uses: ./.github/workflows/.nox-session.yml
uses: ./.github/workflows/.hatch-run.yml
with:
job-name: "publish"
nox-args: "-s publish"
hatch-run: "publish"
node-registry-url: "https://registry.npmjs.org"
secrets:
node-auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
pypi-username: ${{ secrets.PYPI_USERNAME }}
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# --- Build Artifacts ---
src/reactpy/_client

# --- Jupyter ---
*.ipynb_checkpoints
*Untitled*.ipynb
Expand Down
14 changes: 0 additions & 14 deletions .pre-commit-config.yaml

This file was deleted.

42 changes: 13 additions & 29 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,26 @@ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -yq nodejs build-essential
RUN npm install -g [email protected]

# Create Python Venv
# ------------------
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --upgrade pip

# Install ReactPy
# Install Pipx
# ------------
COPY requirements ./requirements
RUN pip install -r requirements/build-docs.txt
RUN pip install pipx

# Copy Files
# ----------
COPY LICENSE ./
COPY src ./src
COPY scripts ./scripts
COPY setup.py ./
COPY pyproject.toml ./
COPY MANIFEST.in ./
COPY README.md ./
RUN pip install .[all]

# COPY License
# -----------
COPY LICENSE /app/

# Build the Docs
# --------------
COPY docs/__init__.py ./docs/
COPY docs/app.py ./docs/
COPY docs/examples.py ./docs/
COPY docs/source ./docs/source
COPY docs ./docs
COPY branding ./branding
RUN sphinx-build -v -W -b html docs/source docs/build

# Install and Build Docs
# ----------------------
WORKDIR /app/docs
RUN pipx run poetry install
RUN pipx run poetry run sphinx-build -v -W -b html source build

# Define Entrypoint
# -----------------
ENV PORT 5000
ENV REACTPY_DEBUG_MODE=1
ENV REACTPY_CHECK_VDOM_SPEC=0
CMD python scripts/run_docs.py
CMD pipx run poetry run python main.py
19 changes: 0 additions & 19 deletions docs/Makefile

This file was deleted.

File renamed without changes.
15 changes: 8 additions & 7 deletions docs/app.py → docs/docs_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from sanic import Sanic, response

from docs_app.examples import get_normalized_example_name, load_examples
from reactpy import component
from reactpy.backend.sanic import Options, configure, use_request
from reactpy.core.types import ComponentConstructor

from .examples import get_normalized_example_name, load_examples
THIS_DIR = Path(__file__).parent
DOCS_DIR = THIS_DIR.parent
DOCS_BUILD_DIR = DOCS_DIR / "build"


HERE = Path(__file__).parent
REACTPY_MODEL_SERVER_URL_PREFIX = "/_reactpy"

logger = getLogger(__name__)
Expand Down Expand Up @@ -40,13 +41,13 @@ def reload_examples():
_EXAMPLES: dict[str, ComponentConstructor] = {}


def make_app():
app = Sanic("docs_app")
def make_app(name: str):
app = Sanic(name)

app.static("/docs", str(HERE / "build"))
app.static("/docs", str(DOCS_BUILD_DIR))

@app.route("/")
async def forward_to_index(request):
async def forward_to_index(_):
return response.redirect("/docs/index.html")

configure(
Expand Down
17 changes: 5 additions & 12 deletions scripts/live_docs.py → docs/docs_app/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
get_parser,
)

from docs.app import make_app, reload_examples
from docs_app.app import make_app, reload_examples
from reactpy.backend.sanic import serve_development_app
from reactpy.testing import clear_reactpy_web_modules_dir


# these environment variable are used in custom Sphinx extensions
os.environ["REACTPY_DOC_EXAMPLE_SERVER_HOST"] = "127.0.0.1:5555"
os.environ["REACTPY_DOC_STATIC_SERVER_HOST"] = ""

_running_reactpy_servers = []


def wrap_builder(old_builder):
# This is the bit that we're injecting to get the example components to reload too

app = make_app()
app = make_app("docs_dev_app")

thread_started = threading.Event()

Expand Down Expand Up @@ -87,8 +84,8 @@ def main():
ignore_handler = _get_ignore_handler(args)
server.watch(srcdir, builder, ignore=ignore_handler)
for dirpath in args.additional_watched_dirs:
dirpath = os.path.realpath(dirpath)
server.watch(dirpath, builder, ignore=ignore_handler)
real_dirpath = os.path.realpath(dirpath)
server.watch(real_dirpath, builder, ignore=ignore_handler)
server.watch(outdir, ignore=ignore_handler)

if not args.no_initial_build:
Expand All @@ -100,12 +97,8 @@ def main():

def opener():
time.sleep(args.delay)
webbrowser.open("http://%s:%s/index.html" % (args.host, args.port))
webbrowser.open(f"http://{args.host}:{args.port}/index.html")

threading.Thread(target=opener, daemon=True).start()

server.serve(port=portn, host=args.host, root=outdir)


if __name__ == "__main__":
main()
7 changes: 3 additions & 4 deletions docs/examples.py → docs/docs_app/examples.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from collections.abc import Iterator
from io import StringIO
from pathlib import Path
from traceback import format_exc
from typing import Callable, Iterator
from typing import Callable

import reactpy
from reactpy.types import ComponentType


HERE = Path(__file__)
SOURCE_DIR = HERE.parent / "source"
SOURCE_DIR = HERE.parent.parent / "source"
CONF_FILE = SOURCE_DIR / "conf.py"
RUN_ReactPy = reactpy.run

Expand Down Expand Up @@ -148,7 +148,6 @@ def __init__(self, max_lines: int = 10):

def set_callback(self, function: Callable[[str], None]) -> None:
self._callback = function
return None

def getvalue(self) -> str:
return "".join(self._lines)
Expand Down
14 changes: 14 additions & 0 deletions docs/docs_app/prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

from docs_app.app import make_app

app = make_app("docs_prod_app")


def main() -> None:
app.run(
host="0.0.0.0", # noqa: S104
port=int(os.environ.get("PORT", 5000)),
workers=int(os.environ.get("WEB_CONCURRENCY", 1)),
debug=bool(int(os.environ.get("DEBUG", "0"))),
)
Loading

0 comments on commit ac58266

Please sign in to comment.