Skip to content
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

Refactor #1

Merged
merged 10 commits into from
Nov 12, 2023
Merged
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
3 changes: 2 additions & 1 deletion demo/.eslintrc.cjs → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'prettier',
],
ignorePatterns: ['dist', '.eslintrc.cjs', 'vite.config.ts'],
ignorePatterns: ['dist', '.eslintrc.cjs', 'demo/vite.config.ts'],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint', 'react-refresh', 'simple-import-sort'],
rules: {
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI

on:
push:
branches:
- main
tags:
- '**'
pull_request:
types: [opened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

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

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

- run: pip install -r python/requirements/all.txt

- run: npm install

- uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files
env:
SKIP: no-commit-to-branch

check: # This job does nothing and is only used for the branch protection
if: always()
needs: [lint]
runs-on: ubuntu-latest

steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
id: all-green
with:
jobs: ${{ toJSON(needs) }}

release:
needs: [check]
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
environment: release

permissions:
id-token: write

steps:
- uses: actions/checkout@v3

- name: set up python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: install
run: pip install -U build

- name: check version
id: check-version
uses: samuelcolvin/check-python-version@v4.1
with:
version_file_path: 'python/fastui/__init__.py'

- name: build
run: python -m build

- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ dist-ssr
__pycache__/

/.logfire/
/frontend-dist/
/scratch/
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: no-commit-to-branch
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: local
hooks:
- id: python-format
name: python-format
types_or: [python]
entry: make format
language: system
pass_filenames: false
- id: python-typecheck
name: python-typecheck
types_or: [python]
entry: make typecheck
language: system
pass_filenames: false
- id: react-prettier
name: react-prettier
types_or: [javascript, jsx, ts, tsx, css, json, markdown]
entry: npm run prettier
language: system
- id: react-lint
name: react-lint
types_or: [ts, tsx]
entry: npm run lint-fix
language: system
pass_filenames: false
- id: react-typecheck
name: react-typecheck
types_or: [ts, tsx]
entry: npm run typecheck
language: system
pass_filenames: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 to present Samuel Colvin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.DEFAULT_GOAL:=all
paths = python

.PHONY: install
install:
pip install -U pip pre-commit pip-tools
pip install -r python/requirements/all.txt
pre-commit install

.PHONY: update-lockfiles
update-lockfiles:
@echo "Updating requirements files using pip-compile"
pip-compile -q --strip-extras -o python/requirements/lint.txt python/requirements/lint.in
pip-compile -q --strip-extras -o python/requirements/pyproject.txt pyproject.toml
pip install --dry-run -r python/requirements/all.txt

.PHONY: format
format:
ruff check --fix-only $(paths)
ruff format $(paths)

.PHONY: lint
lint:
ruff check $(paths)
ruff format --check $(paths)

.PHONY: typecheck
typecheck:
pyright python/fastui

.PHONY: test
test:
coverage run -m pytest tests

.PHONY: testcov
testcov: test
coverage html

.PHONY: dev
dev:
uvicorn demo.server:app --reload

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

[![CI](https://github.com/samuelcolvin/FastUI/workflows/CI/badge.svg?event=push)](https://github.com/samuelcolvin/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/samuelcolvin/FastUI)
[![license](https://img.shields.io/github/license/samuelcolvin/FastUI.svg)](https://github.com/samuelcolvin/FastUI/blob/main/LICENSE)

WIP
17 changes: 6 additions & 11 deletions demo/server/main.py → demo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
from datetime import date

from fastapi import FastAPI
from pydantic import RootModel, BaseModel, Field
from pydantic import BaseModel, Field

import components as c
from components import AnyComponent
from components.events import PageEvent, GoToEvent
from fastui import components as c
from fastui import FastUI, PageEvent, GoToEvent, Display, AnyComponent

app = FastAPI()


class FastUi(RootModel):
root: AnyComponent


@app.get('/api/', response_model=FastUi, response_model_exclude_none=True)
@app.get('/api/', response_model=FastUI, response_model_exclude_none=True)
def read_root() -> AnyComponent:
return c.Page(
children=[
Expand Down Expand Up @@ -44,7 +39,7 @@ class MyTableRow(BaseModel):
enabled: bool | None = None


@app.get('/api/table', response_model=FastUi, response_model_exclude_none=True)
@app.get('/api/table', response_model=FastUI, response_model_exclude_none=True)
def read_foo() -> AnyComponent:
return c.Page(
children=[
Expand All @@ -57,7 +52,7 @@ def read_foo() -> AnyComponent:
],
columns=[
c.Column(field='name', on_click=GoToEvent(url='/api/more/{id}/')),
c.Column(field='dob', display=c.Display.date),
c.Column(field='dob', display=Display.date),
c.Column(field='enabled'),
]
)
Expand Down
4 changes: 2 additions & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastUI, ClassNameGenerator, CustomRender } from './FastUI'
import { FastUI, ClassNameGenerator, CustomRender } from 'fastui'

export default function App () {
export default function App() {
return (
<div className="app">
<FastUI rootUrl="/api" classNameGenerator={bootstrapClassName} customRender={customRender} />
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import './main.scss'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
</React.StrictMode>,
)
5 changes: 4 additions & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"paths": {
"fastui": ["../react/fastui"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
1 change: 1 addition & 0 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default () => {
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
fastui: path.resolve(__dirname, '../react/fastui'),
},
},
server: serverConfig,
Expand Down
25 changes: 21 additions & 4 deletions demo/package-lock.json → package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading