Skip to content

Commit 33bb37b

Browse files
committed
feat: migrate to uv
1 parent 0558fe2 commit 33bb37b

24 files changed

+637
-176
lines changed

.github/workflows/publish.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515

16-
- uses: actions/setup-python@v5
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v4
1718
with:
18-
python-version: 3.13
19+
version: "latest"
20+
enable-cache: true
1921

20-
- run: |
21-
pip install --upgrade pip
22-
pip install hatch
23-
hatch build
22+
- name: Set up Python
23+
run: uv python install 3.13
24+
25+
- name: Build package
26+
run: uv build
2427

2528
- uses: actions/upload-artifact@v4
2629
with:
2730
path: ./dist
2831
if-no-files-found: error
2932

3033
pypi-publish:
31-
needs: ['build']
32-
environment: 'publish'
34+
needs: ["build"]
35+
environment: "publish"
3336

3437
name: upload release to PyPI
3538
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,71 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v5
19-
- name: Set up Python
20-
uses: actions/setup-python@v5
21-
with:
22-
python-version: ${{ matrix.python-version }}
23-
- uses: actions/cache@v4
24-
id: cache
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v4
2521
with:
26-
path: ${{ env.pythonLocation }}
27-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test
22+
version: "latest"
23+
enable-cache: true
24+
25+
- name: Set up Python
26+
run: uv python install ${{ matrix.python-version }}
27+
2828
- name: Install dependencies
29-
if: steps.cache-python-env.outputs.cache-hit != 'true'
30-
run: |
31-
pip install --upgrade pip
32-
pip install -e .[dev]
29+
run: uv sync --extra dev
30+
3331
- name: Lint
3432
run: |
3533
make lint
36-
- name: Install app
34+
35+
- name: Add uv venv to PATH
3736
run: |
38-
pip install -e .
37+
echo "$PWD/.venv/bin" >> $GITHUB_PATH
3938
cd ../..
39+
4040
- name: Create project using default template
4141
run: |
4242
fastapi-gen hello_world
4343
cd hello_world
4444
make lint
4545
make test
4646
cd ..
47+
4748
- name: Create project using "hello_world" template
4849
run: |
4950
fastapi-gen hello_world_v2 --template hello_world
5051
cd hello_world_v2
5152
make lint
5253
make test
5354
cd ..
55+
5456
- name: Create project using "advanced" template
5557
run: |
5658
fastapi-gen advanced --template advanced
5759
cd advanced
5860
make lint
5961
make test
6062
cd ..
63+
6164
- name: Create project using "nlp" template
6265
run: |
6366
fastapi-gen nlp --template nlp
6467
cd nlp
6568
make lint
6669
make test
6770
cd ..
71+
6872
- name: Create project using "langchain" template
6973
run: |
7074
fastapi-gen langchain_app --template langchain
7175
cd langchain_app
7276
make lint
7377
make test
7478
cd ..
79+
7580
- name: Create project using "llama" template
81+
env:
82+
CMAKE_ARGS: "-DGGML_METAL=OFF -DGGML_BLAS=OFF -DGGML_VULKAN=OFF"
83+
FORCE_CMAKE: 1
7684
run: |
7785
fastapi-gen llama_app --template llama
7886
cd llama_app

MANIFEST.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include README.md
2+
include LICENSE
3+
recursive-include src/templates *.toml
4+
recursive-include src/templates *.txt
5+
recursive-include src/templates *.py
6+
recursive-include src/templates *.md
7+
recursive-include src/templates Makefile
8+
recursive-include src/templates .env*
9+
recursive-include src/templates .git*
10+
graft src/templates
11+
prune src/templates/__pycache__
12+
prune src/templates/.pytest_cache
13+
prune src/templates/venv
14+
prune src/templates/.ruff_cache

Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
.PHONY: lint lint-fix
1+
.PHONY: install sync lint lint-fix test build clean update
2+
3+
install:
4+
uv sync --extra dev
5+
6+
sync:
7+
uv sync --extra dev
28

39
lint:
4-
ruff check src/cli
10+
uv run ruff check src/
511

612
lint-fix:
7-
ruff check --fix src
13+
uv run ruff check --fix src
14+
15+
test:
16+
uv run pytest
17+
18+
build:
19+
uv build
20+
21+
clean:
22+
rm -rf dist/ build/ *.egg-info/ .pytest_cache/ .ruff_cache/
23+
24+
update:
25+
uv sync --upgrade

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ cd my_app && make start
5151

5252
> **Platform Support:** Works on macOS and Linux | [Report Issues](https://github.com/mirpo/fastapi-gen/issues/new)
5353
54+
## Requirements
55+
56+
- Python 3.12+
57+
- `uv` (`curl -LsSf https://astral.sh/uv/install.sh | sh`)
58+
5459
## Why FastAPI Gen?
5560

5661
<div align="center">
5762

58-
| **Focus on Code** | **Production Ready** | **Testing Included** | **Zero Config** |
59-
|:---:|:---:|:---:|:---:|
60-
| Skip boilerplate setup | Enterprise patterns | Real test coverage | Ready-to-run templates |
63+
| **Focus on Code** | **Production Ready** | **Testing Included** | **Zero Config** |
64+
| :--------------------: | :------------------: | :------------------: | :--------------------: |
65+
| Skip boilerplate setup | Enterprise patterns | Real test coverage | Ready-to-run templates |
6166

6267
</div>
6368

@@ -160,13 +165,13 @@ cd my_app && make start
160165

161166
## Template Comparison
162167

163-
| Template | Best For | Complexity | AI/ML | Database | Auth |
164-
|----------|----------|------------|--------|----------|------|
165-
| **Hello World** | Learning, Simple APIs |||||
166-
| **Advanced** | Production Apps | ⭐⭐⭐ ||||
167-
| **NLP** | AI Text Processing | ⭐⭐⭐⭐ ||||
168-
| **LangChain** | LLM Workflows | ⭐⭐⭐⭐ ||||
169-
| **Llama** | Local LLM | ⭐⭐⭐⭐⭐ ||||
168+
| Template | Best For | Complexity | AI/ML | Database | Auth |
169+
| --------------- | --------------------- | ---------- | ----- | -------- | ---- |
170+
| **Hello World** | Learning, Simple APIs | | | | |
171+
| **Advanced** | Production Apps | ⭐⭐⭐ | | | |
172+
| **NLP** | AI Text Processing | ⭐⭐⭐⭐ | | | |
173+
| **LangChain** | LLM Workflows | ⭐⭐⭐⭐ | | | |
174+
| **Llama** | Local LLM | ⭐⭐⭐⭐⭐ | | | |
170175

171176
## What You Get Out of the Box
172177

@@ -196,8 +201,6 @@ make start # Run!
196201

197202
## Creating an App
198203

199-
**You'll need to have Python 3.12+ or later version on your local development machine**. We recommend using the latest LTS version. You can use [pyenv](https://github.com/pyenv/pyenv) (macOS/Linux) to switch Python versions between different projects.
200-
201204
### Basic template
202205

203206
```console

pyproject.toml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
2+
requires = ["setuptools>=45", "wheel"]
3+
build-backend = "setuptools.build_meta"
44

5-
[tool.hatch.build]
6-
include = ["src"]
5+
[tool.setuptools]
6+
include-package-data = true
77

8-
[tool.hatch.build.targets.wheel]
9-
sources = ["src"]
8+
[tool.setuptools.packages.find]
9+
where = ["src"]
10+
11+
[tool.setuptools.package-data]
12+
"*" = ["*"]
1013

1114
[project]
1215
name = "fastapi-gen"
13-
dynamic = ["version"]
16+
version = "0.9.0"
1417
description = "Set up a modern REST API by running one command."
1518
readme = "README.md"
1619
requires-python = ">=3.12"
@@ -51,7 +54,6 @@ classifiers = [
5154
"Framework :: Pydantic",
5255
"Framework :: Pydantic :: 1",
5356
"Intended Audience :: Developers",
54-
"License :: OSI Approved :: MIT License",
5557
"Programming Language :: Python :: 3 :: Only",
5658
"Programming Language :: Python :: 3.12",
5759
"Programming Language :: Python :: 3.13",
@@ -72,14 +74,11 @@ Source = "https://github.com/mirpo/fastapi-gen"
7274
[project.scripts]
7375
fastapi-gen = "cli.__main__:main"
7476

75-
[tool.hatch.version]
76-
path = "src/cli/__about__.py"
77-
78-
[tool.hatch.envs.default]
79-
dependencies = ["coverage[toml]==7.10.3", "pytest"]
80-
81-
[[tool.hatch.envs.all.matrix]]
82-
python = ["3.12", "3.13"]
77+
[dependency-groups]
78+
dev = [
79+
"coverage[toml]==7.10.3",
80+
"pytest",
81+
]
8382

8483
[tool.black]
8584
target-version = ["py312"]

src/cli/__main__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ def _create_dir(path: str):
3636

3737
def _walk_resources(package: str, path: str = ""):
3838
for file in resources.files(package).iterdir():
39-
if file.name in ["__pycache__", ".pytest_cache", "venv"]:
39+
if (file.name in ["__pycache__", ".pytest_cache", "venv", ".ruff_cache", ".venv", ".git"] or
40+
file.name.endswith(".egg-info") or file.name.endswith("__pycache__") or
41+
not file.name or file.name.strip() == "" or file.name.isspace()):
4042
continue
4143

4244
if file.is_dir():
4345
_create_dir(os.path.join(path, file.name))
4446
_walk_resources(f"{package}.{file.name}", os.path.join(path, file.name))
47+
elif file.name.startswith("."):
48+
with open(os.path.join(path, file.name), "w") as f:
49+
f.write(file.read_text())
4550
else:
4651
with open(os.path.join(path, file.name), "w") as f:
4752
f.write(resources.read_text(package, file.name))

src/templates/advanced/Makefile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
.PHONY: init lint start test
1+
.PHONY: install sync lint lint-fix test start build clean update
22

33
PORT=8000
44
HOST=127.0.0.1
55

6-
init: requirements.txt
7-
test -d venv || python3 -m venv venv
8-
. venv/bin/activate && pip install -r requirements.txt
6+
install:
7+
uv sync --group dev
98
test -d .git || git init || true
109

10+
sync:
11+
uv sync --group dev
12+
1113
lint:
12-
. venv/bin/activate && ruff check tests main.py
14+
uv run ruff check tests main.py
15+
16+
lint-fix:
17+
uv run ruff check --fix tests main.py
1318

1419
test:
15-
. venv/bin/activate && pytest -vv .
20+
uv run pytest -vv .
1621

1722
start:
18-
. venv/bin/activate && uvicorn main:app --reload --host $(HOST) --port $(PORT)
23+
uv run uvicorn main:app --reload --host $(HOST) --port $(PORT)
24+
25+
build:
26+
uv build
27+
28+
clean:
29+
rm -rf dist/ build/ *.egg-info/ .pytest_cache/ .ruff_cache/
30+
31+
update:
32+
uv sync --upgrade
33+
34+
init: install
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "advanced-fastapi-app"
7+
version = "0.1.0"
8+
description = "Advanced FastAPI Application with Authentication and Database"
9+
requires-python = ">=3.12"
10+
license = {text = "MIT"}
11+
dependencies = [
12+
"fastapi==0.116.1",
13+
"uvicorn==0.35.0",
14+
"python-dotenv==1.1.1",
15+
"pydantic-settings==2.10.1",
16+
"sqlalchemy==2.0.43",
17+
"python-jose[cryptography]==3.5.0",
18+
"passlib[bcrypt]==1.7.4",
19+
"bcrypt==4.1.3", # Pin compatible bcrypt version
20+
"slowapi==0.1.9",
21+
"python-multipart==0.0.20",
22+
"websockets==15.0.1",
23+
]
24+
25+
[dependency-groups]
26+
dev = [
27+
"ruff==0.12.10",
28+
"pytest==8.4.1",
29+
"httpx==0.28.1",
30+
"pytest-asyncio==1.1.0",
31+
]
32+
33+
[tool.ruff]
34+
target-version = "py312"
35+
line-length = 120
36+
37+
[tool.ruff.lint]
38+
select = ["E", "F", "I", "N", "W", "UP"]
39+
ignore = []
40+
41+
[tool.ruff.lint.isort]
42+
known-first-party = ["main"]

0 commit comments

Comments
 (0)