Skip to content

Commit

Permalink
Merge branch 'main' into nested-lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejiah authored Mar 28, 2024
2 parents c82afa0 + 1964143 commit c84a4e1
Show file tree
Hide file tree
Showing 67 changed files with 1,815 additions and 503 deletions.
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
26 changes: 14 additions & 12 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,7 +29,7 @@ jobs:

- run: npm install

- uses: pre-commit/action@v3.0.0
- uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files
env:
Expand All @@ -50,26 +50,28 @@ jobs:
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 +80,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 +112,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: 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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
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 c84a4e1

Please sign in to comment.