Skip to content

Commit 80e9756

Browse files
authored
ci(gha): set up CI (#4)
* chore: configure mypy Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * fix: type errors Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * docs: sort imports of README.md Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * ci(gha): add ci Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * ci(gha): add release Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * build: install fastapi on dev Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * build: exclude py3.8 Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * fix: replace BaseModel with pydantic dataclass Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * build: specify minimum version of fastapi Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * Revert "build: exclude py3.8" This reverts commit a12f5ac. * ci(gha): build Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * Reapply "build: exclude py3.8" This reverts commit 55eb498. * Revert "fix: replace BaseModel with pydantic dataclass" This reverts commit 8142c80. * ci(gha): fix build Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * ci(gha): fix build Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> * ci(gha): skip existing versions on publish Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io> --------- Signed-off-by: Isac Byeonghoon Yoo <isac@runbear.io>
1 parent 9fec5e8 commit 80e9756

File tree

5 files changed

+110
-13
lines changed

5 files changed

+110
-13
lines changed

.github/workflows/ci.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
ci:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
pyver: ["3.9", "3.10", "3.12"]
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "${{ matrix.pyver }}"
19+
cache: pip
20+
- name: Install dependencies
21+
# language=Bash
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e '.[dev]'
25+
- name: Test with pytest
26+
# language=Bash
27+
run: |
28+
pytest
29+
- name: Lint
30+
# language=Bash
31+
run: |
32+
ruff check --show-fixes --show-source
33+
mypy -p plugbear
34+
35+
build:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- name: Set up Python
40+
uses: actions/setup-python@v5
41+
- name: Build
42+
# language=Bash
43+
run: |
44+
python -m pip install --upgrade pip build
45+
python -m build .

.github/workflows/release.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
workflow_dispatch:
7+
8+
jobs:
9+
pypi-publish:
10+
runs-on: ubuntu-latest
11+
environment: release
12+
permissions:
13+
# IMPORTANT: this permission is mandatory for trusted publishing
14+
id-token: write
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
- name: Build
20+
# language=Bash
21+
run: |
22+
pip install -U build
23+
python -m build .
24+
- name: Publish package distributions to PyPI
25+
uses: pypa/gh-action-pypi-publish@release/v1
26+
with:
27+
skip-existing: true

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Here's a simple example to get you started:
2020
```python
2121
import contextlib
2222

23-
import plugbear
2423
import plugbear.fastapi
2524
from fastapi import FastAPI
2625

@@ -54,10 +53,8 @@ async def some_llm(context: plugbear.fastapi.Request) -> str:
5453
<summary>For versions below 0.93.0</summary>
5554

5655
```python
57-
from fastapi import FastAPI
58-
59-
import plugbear
6056
import plugbear.fastapi
57+
from fastapi import FastAPI
6158

6259
app = FastAPI()
6360
PLUGBEAR_API_KEY = ""

plugbear/fastapi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import inspect
44
from collections.abc import Coroutine, Sequence
5-
from typing import Any, Optional, Protocol, Union, runtime_checkable
5+
from typing import Any, Optional, Protocol, Union, cast, runtime_checkable
66

77
import fastapi
8+
import fastapi.responses
89
from pydantic import BaseModel
910

1011
import plugbear
@@ -41,9 +42,9 @@ async def register(app: fastapi.FastAPI, *, llm_func: LLMHandler, api_key: str,
4142

4243
@app.post(endpoint, response_class=fastapi.responses.PlainTextResponse)
4344
async def plugbear_callback(request: Request) -> str:
44-
return await llm_func(request)
45+
return cast(str, await llm_func(request))
4546
else:
4647

4748
@app.post(endpoint, response_class=fastapi.responses.PlainTextResponse)
4849
def plugbear_callback(request: Request) -> str:
49-
return llm_func(request)
50+
return cast(str, llm_func(request))

pyproject.toml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ name = "plugbear"
77
authors = [{name = "Runbear", email = "dev@runbear.io"}]
88
readme = "README.md"
99
dynamic = ["version", "description"]
10-
requires-python = ">=3.8"
10+
requires-python = ">=3.9"
1111
classifiers = [
1212
"Development Status :: 4 - Beta",
1313
"Intended Audience :: Developers",
1414
"Operating System :: OS Independent",
1515
"Programming Language :: Python :: 3",
1616
"Programming Language :: Python :: 3 :: Only",
17-
"Programming Language :: Python :: 3.8",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
@@ -31,16 +30,17 @@ Home = "https://plugbear.io/"
3130
Source = "https://github.com/runbear-io/plugbear-python-sdk"
3231

3332
[project.optional-dependencies]
34-
fastapi = ["fastapi"]
33+
fastapi = ["fastapi>=0.51.0"]
3534

36-
dev = ["plugbear[test]", "plugbear[lint]"]
35+
dev = ["plugbear[test]", "plugbear[lint]", "plugbear[fastapi]"]
3736
test = [
3837
"pytest~=7.4",
3938
"pytest-asyncio~=0.23",
4039
"httpx", # for fastapi.testclient
4140
]
4241
lint = [
4342
"ruff~=0.1",
43+
"mypy~=1.7",
4444
]
4545

4646

@@ -50,7 +50,7 @@ asyncio_mode = "auto"
5050

5151
[tool.ruff]
5252
line-length = 120
53-
target-version = "py38"
53+
target-version = "py39"
5454

5555
[tool.ruff.format]
5656
# Like Black, use double quotes for strings.
@@ -60,4 +60,31 @@ indent-style = "space"
6060
# Like Black, respect magic trailing commas.
6161
skip-magic-trailing-comma = false
6262
# Like Black, automatically detect the appropriate line ending.
63-
line-ending = "auto"
63+
line-ending = "auto"
64+
65+
66+
[tool.mypy]
67+
python_version = "3.9"
68+
allow_redefinition = true
69+
disallow_incomplete_defs = true
70+
disallow_untyped_calls = true
71+
disallow_untyped_decorators = true
72+
disallow_untyped_defs = true
73+
no_implicit_optional = true
74+
no_implicit_reexport = true
75+
no_warn_no_return = true
76+
strict_equality = true
77+
warn_redundant_casts = true
78+
warn_return_any = true
79+
warn_unreachable = true
80+
warn_unused_ignores = true
81+
82+
pretty = true
83+
show_column_numbers = true
84+
show_error_codes = true
85+
show_error_context = true
86+
87+
# Plugins
88+
plugins = [
89+
"pydantic.mypy",
90+
]

0 commit comments

Comments
 (0)