Skip to content

Commit

Permalink
Refactoring python code location, adding tests (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Dec 5, 2023
1 parent 90f30d2 commit ef70bed
Show file tree
Hide file tree
Showing 99 changed files with 1,041 additions and 588 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
'plugin:react-hooks/recommended',
'prettier',
],
ignorePatterns: ['node_modules'],
ignorePatterns: ['node_modules', 'dist'],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint', 'react-refresh', 'simple-import-sort'],
rules: {
Expand Down
43 changes: 39 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
node-version: 18

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

- run: npm install

Expand All @@ -34,7 +34,42 @@ jobs:
env:
SKIP: no-commit-to-branch

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

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

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

steps:
- uses: actions/checkout@v3

- name: set up python
uses: actions/setup-python@v4
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: make test

- run: coverage xml

- uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
env_vars: PYTHON,OS

npm-build:
runs-on: ubuntu-latest

steps:
Expand All @@ -46,11 +81,11 @@ jobs:

- run: npm install
- run: npm run build
- run: tree packages
- run: tree src

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

steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
/**/*.egg-info

node_modules
dist
Expand All @@ -31,3 +32,4 @@ __pycache__/
/frontend-dist/
/scratch/
/packages-dist/
/.coverage
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
.DEFAULT_GOAL:=all
paths = python
path = src/python-fastui

.PHONY: install
install:
pip install -U pip pre-commit pip-tools
pip install -r python/requirements/all.txt
pip install -r $(path)/requirements/all.txt
pip install -e $(path)
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 --extra=fastapi
pip install --dry-run -r python/requirements/all.txt
pip-compile -q --strip-extras -o $(path)/requirements/lint.txt $(path)/requirements/lint.in
pip-compile -q --strip-extras -o $(path)/requirements/test.txt $(path)/requirements/test.in
pip-compile -q --strip-extras -o $(path)/requirements/pyproject.txt $(path)/pyproject.toml --extra=fastapi
pip install --dry-run -r $(path)/requirements/all.txt

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

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

.PHONY: typecheck
typecheck:
pyright python/fastui
pyright

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

.PHONY: testcov
testcov: test
coverage html

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

.PHONY: all
all: testcov lint
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 3 additions & 12 deletions python/demo/forms.py → demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,19 @@ def form_content(kind: FormKind):
return [
c.Heading(text='Login Form', level=2),
c.Paragraph(text='Simple login form with email and password.'),
c.ModelForm[LoginForm](
submit_url='/api/forms/login',
success_event=PageEvent(name='form_success'),
),
c.ModelForm[LoginForm](submit_url='/api/forms/login'),
]
case 'select':
return [
c.Heading(text='Select Form', level=2),
c.Paragraph(text='Form showing different ways of doing select.'),
c.ModelForm[SelectForm](
submit_url='/api/forms/select',
success_event=PageEvent(name='form_success'),
),
c.ModelForm[SelectForm](submit_url='/api/forms/select'),
]
case 'big':
return [
c.Heading(text='Large Form', level=2),
c.Paragraph(text='Form with a lot of fields.'),
c.ModelForm[BigModel](
submit_url='/api/forms/big',
success_event=PageEvent(name='form_success'),
),
c.ModelForm[BigModel](submit_url='/api/forms/big'),
]
case _:
raise ValueError(f'Invalid kind {kind!r}')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"private": true,
"type": "module",
"workspaces": [
"packages/*"
"src/*"
],
"scripts": {
"dev": "npm run --workspace=@pydantic/fastui-prebuilt dev",
"build": "npm run --workspaces prepublishOnly",
"typecheck": "npm run --workspaces typecheck",
"lint": "eslint packages --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint src --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0",
"lint-fix": "npm run lint -- --fix",
"prettier": "prettier --write",
"format": "npm run prettier -- . && npm run lint-fix"
Expand Down
57 changes: 10 additions & 47 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,17 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.sdist]
include = ["python"]

[tool.hatch.build.targets.wheel]
packages = ["python/fastui"]

[tool.hatch.version]
path = "python/fastui/__init__.py"

[project]
name = "fastui"
description = "Build better UIs faster."
authors = [{ name = "Samuel Colvin", email = "[email protected]" }]
license = "MIT"
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"Topic :: Internet",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Framework :: Pydantic :: 2",
"Framework :: FastAPI",
]
requires-python = ">=3.8"
dependencies = ["pydantic[email]>=2.5.2"]
dynamic = ["version"]

[project.optional-dependencies]
fastapi = [
"fastapi>=0.104",
"python-multipart>=0.0.6",
]

[project.urls]
Homepage = "https://github.com/samuelcolvin/FastUI"
# this is not the used for the python package "fastui",
# for that see packages/python-fastui/pyproject.toml

[tool.ruff]
line-length = 120
extend-select = ["Q", "RUF100", "UP", "I"]
flake8-quotes = {inline-quotes = "single", multiline-quotes = "double"}
format.quote-style="single"
target-version = "py38"

[tool.pyright]
include = ["src/python-fastui/fastui"]

[tool.pytest.ini_options]
testpaths = "src/python-fastui/tests"
xfail_strict = true
filterwarnings = ["error"]
6 changes: 0 additions & 6 deletions python/fastui/class_name.py

This file was deleted.

Loading

0 comments on commit ef70bed

Please sign in to comment.