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

Add rye and ruff, and local dependency for CI and development #287

Closed
wants to merge 8 commits into from
Closed
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
57 changes: 41 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ on:
tags:
- '**'
pull_request:
types: [opened, synchronize]
types: [opened, synchronize, reopened, ready_for_review]

jobs:
lint:
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest

steps:
Expand All @@ -24,8 +25,12 @@ jobs:
with:
node-version: 18

- run: pip install -r src/python-fastui/requirements/all.txt
- run: pip install src/python-fastui
- name: Install the latest version of rye
uses: eifinger/setup-rye@v2
ManiMozaffar marked this conversation as resolved.
Show resolved Hide resolved

- run: make install
ManiMozaffar marked this conversation as resolved.
Show resolved Hide resolved

- run: make lint

- run: npm install
sydney-runkle marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -82,6 +87,7 @@ jobs:
- os: macos-latest
python-version: '3.9'

if: github.event.pull_request.draft != true
runs-on: ${{ matrix.os }}

env:
Expand All @@ -96,26 +102,45 @@ jobs:
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 -e src/python-fastui
- name: Install the latest version of rye
uses: eifinger/setup-rye@v2

- name: Pin python-version ${{ matrix.python-version }}
run: rye pin ${{ matrix.python-version }}

- name: Install dependencies
run: make install

- name: Run test, with generating coverage on FastUI source
run: make testcov

- 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
- name: Run cov report generator
run: make testcov-report

- name: Run type check on FastUI source
run: make typecheck

# ci on demo for 3.11 and 3.12, these ops are intentionally omitted, reason is that it's using 3.11 and 3.12 syntax
- if: matrix.python-version == '3.11' || matrix.python-version == '3.12'
run: make lint-demo

- if: matrix.python-version == '3.11' || matrix.python-version == '3.12'
run: make typecheck-demo

# 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: make test-demo

- run: coverage xml
- name: Run XML coverage report generator
run: make testcov-xml

- uses: codecov/codecov-action@v4
- name: Upload coverage report from XML
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
file: ./src/python-fastui/coverage.xml
env_vars: PYTHON,OS

npm-build:
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest

steps:
Expand All @@ -130,7 +155,7 @@ jobs:
- run: tree src

check: # This job does nothing and is only used for the branch protection
if: always()
if: github.event.pull_request.draft != true
needs: [lint, test, npm-build]
runs-on: ubuntu-latest

Expand All @@ -143,7 +168,7 @@ jobs:

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

Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ __pycache__/
/frontend-dist/
/scratch/
/packages-dist/
/.coverage
.coverage
/users.db

# rye
.python-version
49 changes: 32 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ path = src/python-fastui

.PHONY: install
install:
pip install -U pip pre-commit pip-tools
pip install -r $(path)/requirements/all.txt
pip install -e $(path)
pre-commit install
cd src/python-fastui && rye sync
cd demo && rye sync


.PHONY: install-docs
Expand All @@ -19,41 +17,58 @@ install-docs:

.PHONY: update-lockfiles
update-lockfiles:
@echo "Updating requirements files using pip-compile"
pip-compile -q --strip-extras -o $(path)/requirements/lint.txt $(path)/requirements/lint.in
pip-compile -q --strip-extras -o $(path)/requirements/pyproject.txt -c $(path)/requirements/lint.txt $(path)/pyproject.toml --extra=fastapi
pip-compile -q --strip-extras -o $(path)/requirements/test.txt -c $(path)/requirements/lint.txt -c $(path)/requirements/pyproject.txt $(path)/requirements/test.in
pip install --dry-run -r $(path)/requirements/all.txt
cd src/python-fastui && rye lock
cd demo && rye lock

.PHONY: format
format:
ruff check --fix-only $(path) demo
ruff format $(path) demo
cd src/python-fastui && rye run ruff check --fix-only .
cd demo && rye run ruff check --fix-only .

.PHONY: lint
lint:
ruff check $(path) demo
ruff format --check $(path) demo
cd src/python-fastui && rye run ruff check .

.PHONY: lint-demo
lint-demo:
cd demo && rye run ruff check .


.PHONY: typecheck
typecheck:
pyright
cd src/python-fastui && rye run pyright fastui

.PHONY: typecheck-demo
typecheck-demo:
cd demo && rye run pyright src


.PHONY: test
test:
coverage run -m pytest
cd src/python-fastui && rye run coverage run -m pytest tests

.PHONY: test-demo
test-demo:
cd demo && rye run pytest tests

.PHONY: testcov
testcov: test
coverage html
cd src/python-fastui && rye run coverage html

.PHONY: testcov-report
testcov-report:
cd src/python-fastui && rye run coverage report --fail-under=80

testcov-xml:
cd src/python-fastui && rye run coverage xml

.PHONY: typescript-models
typescript-models:
fastui generate fastui:FastUI src/npm-fastui/src/models.d.ts

.PHONY: dev
dev:
uvicorn demo:app --reload --reload-dir .
uvicorn demo.src:app --reload --reload-dir .

.PHONY: docs
docs:
Expand Down
106 changes: 106 additions & 0 deletions demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[tool.hatch.version]
path = "src/__init__.py"
allow-direct-references = true

[project]
sydney-runkle marked this conversation as resolved.
Show resolved Hide resolved
name = 'demo'
description = 'FastUI demo project'
authors = [{ name = 'Samuel Colvin', email = '[email protected]' }]
classifiers = [
'Development Status :: 5 - Production/Stable',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? Haha

'Programming Language :: Python',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'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',
'Intended Audience :: System Administrators',
'Operating System :: Unix',
'Operating System :: POSIX :: Linux',
'Environment :: Console',
'Environment :: MacOS X',
'Framework :: Hypothesis',
'Framework :: Pydantic',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Internet',
]
requires-python = '>=3.8'
dependencies = [
"fastapi>=0.110.2",
"httpx>=0.27.0",
"openai==1.10.0",
"PYjwt>=2.8.0",
"pydantic[email]>=2.7.1",
Comment on lines +35 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all truly dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not the pyproject for fastui, that's for the demo.
Yes they're all. but it shouldn't affect anyway, because demo itself is "dev" package right? it's not that we ship it to client.

]
dynamic = ['version']


[tool.ruff]
line-length = 120
target-version = 'py38'
lint.extend-select = ['Q', 'RUF100', 'C90', 'UP', 'I', 'D', 'T']
lint.extend-ignore = [
'D100',
'D101',
'D102',
'D103',
'D104',
'D105',
'D107',
'D205',
'D415',
'T201',
]
lint.flake8-quotes = { inline-quotes = 'single', multiline-quotes = 'double' }
lint.isort = { known-first-party = ['pydantic', 'tests'] }
lint.mccabe = { max-complexity = 14 }
lint.pydocstyle = { convention = 'google' }
Comment on lines +45 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make sure these are consistent with what we're using in pydantic in general - seems like a lot of ignores?


[tool.ruff.lint.per-file-ignores]
'docs/*' = ['D']
'pydantic/__init__.py' = ['F405', 'F403', 'D']
'tests/test_forward_ref.py' = ['F821']
'tests/*' = ['D']
'pydantic/deprecated/*' = ['D']
'pydantic/json_schema.py' = ['D']

[tool.ruff.lint.extend-per-file-ignores]
"docs/**/*.py" = ['T']
"tests/**/*.py" = ['T', 'E721', 'F811']
"tests/benchmarks/test_fastapi_startup_generics.py" = ['UP006', 'UP007']
"tests/benchmarks/test_fastapi_startup_simple.py" = ['UP006', 'UP007']
Comment on lines +66 to +77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - we don't need these in this repo


[tool.ruff.format]
quote-style = 'single'

[tool.coverage.run]
source = ['pydantic']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems off

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true my bad, i tried to copy from pydantic's rule, some were dead codes.

branch = true
context = '${CONTEXT}'


[tool.rye]
managed = true
dev-dependencies = [
"fastui @ file:///${PROJECT_ROOT}/../src/python-fastui",
"dirty-equals>=0.7.1.post0",
"coverage==7.4.1",
"rich==13.7.0",
"pytest-pretty==1.2.0",
"pytest-asyncio==0.23.4",
"dirty-equals==0.7.1.post0",
"markdown-it-py==3.0.0",
"pytest==7.4.4",
"pyright==1.1.335",
"ruff==0.2.1",
"mypy~=1.1.1",
]

[tool.behavior]
use-uv = true
Loading
Loading