Skip to content

Commit

Permalink
Merge branch 'main' into dark-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ischaojie authored Sep 27, 2024
2 parents c6d4dbc + 5d9d604 commit a775426
Show file tree
Hide file tree
Showing 103 changed files with 3,710 additions and 676 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
extends: [
'standard',
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'prettier',
Expand All @@ -15,6 +16,9 @@ module.exports = {
'react-refresh/only-export-components': 'off', // how much effect does this have?
'@typescript-eslint/no-explicit-any': 'off',
'no-use-before-define': 'off',
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'react/display-name': 'off',
'import/order': [
'error',
{
Expand Down
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Keep GitHub Actions up to date with GitHub's Dependabot...
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
version: 2
updates:
- package-ecosystem: github-actions
directory: /
groups:
github-actions:
patterns:
- "*" # Group all Actions updates into a single larger pull request
schedule:
interval: monthly
71 changes: 56 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18

Expand All @@ -29,47 +29,88 @@ jobs:

- run: npm install

- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1
with:
extra_args: --all-files
env:
SKIP: no-commit-to-branch

docs-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.11'

# note: PPPR_TOKEN is not available on PRs sourced from forks, but the necessary
# dependencies are also listed in docs.txt :)
- name: install
run: |
pip install --upgrade pip
pip install --extra-index-url https://pydantic:${PPPR_TOKEN}@pppr.pydantic.dev/simple/ mkdocs-material mkdocstrings-python
pip install -r requirements/docs.txt
# note -- we can use these in the future when mkdocstrings-typescript and griffe-typedoc beocome publicly available
# pip install --extra-index-url https://pydantic:${PPPR_TOKEN}@pppr.pydantic.dev/simple/ mkdocs-material mkdocstrings-python griffe-typedoc mkdocstrings-typescript
# npm install
# npm install -g typedoc
env:
PPPR_TOKEN: ${{ secrets.PPPR_TOKEN }}

- name: build site
run: mkdocs build --strict

test:
name: test ${{ matrix.python-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
os: [ubuntu-latest, macos-13, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

runs-on: ${{ matrix.os }}-latest
exclude:
# Python 3.8 and 3.9 are not available on macOS 14
- os: macos-13
python-version: '3.10'
- os: macos-13
python-version: '3.11'
- os: macos-13
python-version: '3.12'
- os: macos-latest
python-version: '3.8'
- os: macos-latest
python-version: '3.9'

runs-on: ${{ matrix.os }}

env:
PYTHON: ${{ matrix.python-version }}
OS: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- run: pip install -r src/python-fastui/requirements/test.txt
- run: pip install -r src/python-fastui/requirements/pyproject.txt
- run: pip install src/python-fastui
- run: pip install -e src/python-fastui

- run: coverage run -m pytest src
# display coverage and fail if it's below 80%, which shouldn't happen
- run: coverage report --fail-under=80

# test demo on 3.11 and 3.12, these tests are intentionally omitted from coverage
- if: matrix.python-version == '3.11' || matrix.python-version == '3.12'
run: pytest demo/tests.py

- run: coverage xml

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
env_vars: PYTHON,OS
Expand All @@ -78,9 +119,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18

Expand Down Expand Up @@ -110,9 +151,9 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
hooks:
- id: no-commit-to-branch
- id: check-yaml
args: ['--unsafe']
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -27,6 +28,7 @@ repos:
types_or: [javascript, jsx, ts, tsx, css, json, markdown]
entry: npm run prettier
language: system
exclude: '^docs/.*'
- id: js-lint
name: js-lint
types_or: [ts, tsx]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 to present Samuel Colvin
Copyright (c) 2023 to present Pydantic Services inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ install:
pip install -e $(path)
pre-commit install


.PHONY: install-docs
install-docs:
pip install -r requirements/docs.txt

# note -- mkdocstrings-typescript and griffe-typedoc are not yet publicly available
# but the following can be added above the pip install -r requirements/docs.txt line in the future
# pip install mkdocstrings-python mkdocstrings-typescript griffe-typedoc

.PHONY: update-lockfiles
update-lockfiles:
@echo "Updating requirements files using pip-compile"
Expand Down Expand Up @@ -46,5 +55,13 @@ typescript-models:
dev:
uvicorn demo:app --reload --reload-dir .

.PHONY: docs
docs:
mkdocs build

.PHONY: serve
serve:
mkdocs serve

.PHONY: all
all: testcov lint
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# FastUI

Find the documentation [here](https://docs.pydantic.dev/fastui/).
Join the discussion in the #fastui slack channel [here](https://pydanticlogfire.slack.com/archives/C0720M7D31S)

[![CI](https://github.com/pydantic/FastUI/actions/workflows/ci.yml/badge.svg)](https://github.com/pydantic/FastUI/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
[![pypi](https://img.shields.io/pypi/v/fastui.svg)](https://pypi.python.org/pypi/fastui)
[![versions](https://img.shields.io/pypi/pyversions/fastui.svg)](https://github.com/pydantic/FastUI)
Expand Down Expand Up @@ -70,7 +73,7 @@ def users_table() -> list[AnyComponent]:
c.Page( # Page provides a basic container for components
components=[
c.Heading(text='Users', level=2), # renders `<h2>Users</h2>`
c.Table[User]( # c.Table is a generic component parameterized with the model used for rows
c.Table(
data=users,
# define two columns for the table
columns=[
Expand Down Expand Up @@ -136,7 +139,7 @@ Building an application this way has a number of significant advantages:
- You only need to write code in one place to build a new feature — add a new view, change the behavior of an existing view or alter the URL structure
- Deploying the front and backend can be completely decoupled, provided the frontend knows how to render all the components the backend is going to ask it to use, you're good to go
- You should be able to reuse a rich set of opensource components, they should end up being better tested and more reliable than anything you could build yourself, this is possible because the components need no context about how they're going to be used (note: since FastUI is brand new, this isn't true yet, hopefully we get there)
- We can use Pydantic, TypeScript and JSON Schema to provide guarantees that the two sides are communicating with an agreed schema (note: this is not complete yet, see [#18](https://github.com/pydantic/FastUI/issues/18))
- We can use Pydantic, TypeScript and JSON Schema to provide guarantees that the two sides are communicating with an agreed schema

In the abstract, FastUI is like the opposite of GraphQL but with the same goal — GraphQL lets frontend developers extend an application without any new backend development; FastUI lets backend developers extend an application without any new frontend development.

Expand Down
15 changes: 15 additions & 0 deletions build-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -e
set -x

python3 -V

python3 -m pip install --extra-index-url https://pydantic:${PPPR_TOKEN}@pppr.pydantic.dev/simple/ mkdocs-material mkdocstrings-python
python3 -m pip install -r ./requirements/docs.txt
# note -- we can use these in the future when mkdocstrings-typescript and griffe-typedoc beocome publicly available
# python3 -m pip install --extra-index-url https://pydantic:[email protected]/simple/ mkdocs-material mkdocstrings-python griffe-typedoc mkdocstrings-typescript
# npm install
# npm install -g typedoc

python3 -m mkdocs build
58 changes: 58 additions & 0 deletions bump_npm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
from __future__ import annotations

import json
import re
from pathlib import Path


def replace_package_json(package_json: Path, new_version: str, deps: bool = False) -> tuple[Path, str]:
content = package_json.read_text()
content, r_count = re.subn(r'"version": *".*?"', f'"version": "{new_version}"', content, count=1)
assert r_count == 1 , f'Failed to update version in {package_json}, expect replacement count 1, got {r_count}'
if deps:
content, r_count = re.subn(r'"(@pydantic/.+?)": *".*?"', fr'"\1": "{new_version}"', content)
assert r_count == 1, f'Failed to update version in {package_json}, expect replacement count 1, got {r_count}'

return package_json, content


def main():
this_dir = Path(__file__).parent
fastui_package_json = this_dir / 'src/npm-fastui/package.json'
with fastui_package_json.open() as f:
old_version = json.load(f)['version']

rest, patch_version = old_version.rsplit('.', 1)
new_version = f'{rest}.{int(patch_version) + 1}'
bootstrap_package_json = this_dir / 'src/npm-fastui-bootstrap/package.json'
prebuilt_package_json = this_dir / 'src/npm-fastui-prebuilt/package.json'
to_update: list[tuple[Path, str]] = [
replace_package_json(fastui_package_json, new_version),
replace_package_json(bootstrap_package_json, new_version, deps=True),
replace_package_json(prebuilt_package_json, new_version),
]

python_init = this_dir / 'src/python-fastui/fastui/__init__.py'
python_content = python_init.read_text()
python_content, r_count = re.subn(r"(_PREBUILT_VERSION = )'.+'", fr"\1'{new_version}'", python_content)
assert r_count == 1, f'Failed to update version in {python_init}, expect replacement count 1, got {r_count}'
to_update.append((python_init, python_content))

# logic is finished, no update all files
print(f'Updating files:')
for package_json, content in to_update:
print(f' {package_json.relative_to(this_dir)}')
package_json.write_text(content)

print(f"""
Bumped from `{old_version}` to `{new_version}` in {len(to_update)} files.
To publish the new version, run:
> npm --workspaces publish
""")


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from fastapi import FastAPI
from fastapi.responses import HTMLResponse, PlainTextResponse
from fastui import prebuilt_html
from fastui.auth import fastapi_auth_exception_handling
from fastui.dev import dev_fastapi_app
from httpx import AsyncClient

from .auth import router as auth_router
from .components_list import router as components_router
from .db import create_db
from .forms import router as forms_router
from .main import router as main_router
from .sse import router as sse_router
Expand All @@ -20,7 +20,6 @@

@asynccontextmanager
async def lifespan(app_: FastAPI):
await create_db()
async with AsyncClient() as client:
app_.state.httpx_client = client
yield
Expand All @@ -33,6 +32,7 @@ async def lifespan(app_: FastAPI):
else:
app = FastAPI(lifespan=lifespan)

fastapi_auth_exception_handling(app)
app.include_router(components_router, prefix='/api/components')
app.include_router(sse_router, prefix='/api/components')
app.include_router(table_router, prefix='/api/table')
Expand Down
Loading

0 comments on commit a775426

Please sign in to comment.