Skip to content

Commit

Permalink
ci(gha): set up CI (#4)
Browse files Browse the repository at this point in the history
* chore: configure mypy

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* fix: type errors

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* docs: sort imports of README.md

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* ci(gha): add ci

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* ci(gha): add release

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* build: install fastapi on dev

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* build: exclude py3.8

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* fix: replace BaseModel with pydantic dataclass

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* build: specify minimum version of fastapi

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* Revert "build: exclude py3.8"

This reverts commit a12f5ac.

* ci(gha): build

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* 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 <[email protected]>

* ci(gha): fix build

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

* ci(gha): skip existing versions on publish

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>

---------

Signed-off-by: Isac Byeonghoon Yoo <[email protected]>
  • Loading branch information
isac322 authored Dec 20, 2023
1 parent 9fec5e8 commit 80e9756
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 13 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
pyver: ["3.9", "3.10", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.pyver }}"
cache: pip
- name: Install dependencies
# language=Bash
run: |
python -m pip install --upgrade pip
pip install -e '.[dev]'
- name: Test with pytest
# language=Bash
run: |
pytest
- name: Lint
# language=Bash
run: |
ruff check --show-fixes --show-source
mypy -p plugbear
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Build
# language=Bash
run: |
python -m pip install --upgrade pip build
python -m build .
27 changes: 27 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
push:
branches:
- master

workflow_dispatch:

jobs:
pypi-publish:
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Build
# language=Bash
run: |
pip install -U build
python -m build .
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Here's a simple example to get you started:
```python
import contextlib

import plugbear
import plugbear.fastapi
from fastapi import FastAPI

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

```python
from fastapi import FastAPI

import plugbear
import plugbear.fastapi
from fastapi import FastAPI

app = FastAPI()
PLUGBEAR_API_KEY = ""
Expand Down
7 changes: 4 additions & 3 deletions plugbear/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import inspect
from collections.abc import Coroutine, Sequence
from typing import Any, Optional, Protocol, Union, runtime_checkable
from typing import Any, Optional, Protocol, Union, cast, runtime_checkable

import fastapi
import fastapi.responses
from pydantic import BaseModel

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

@app.post(endpoint, response_class=fastapi.responses.PlainTextResponse)
async def plugbear_callback(request: Request) -> str:
return await llm_func(request)
return cast(str, await llm_func(request))
else:

@app.post(endpoint, response_class=fastapi.responses.PlainTextResponse)
def plugbear_callback(request: Request) -> str:
return llm_func(request)
return cast(str, llm_func(request))
39 changes: 33 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ name = "plugbear"
authors = [{name = "Runbear", email = "[email protected]"}]
readme = "README.md"
dynamic = ["version", "description"]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"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",
Expand All @@ -31,16 +30,17 @@ Home = "https://plugbear.io/"
Source = "https://github.com/runbear-io/plugbear-python-sdk"

[project.optional-dependencies]
fastapi = ["fastapi"]
fastapi = ["fastapi>=0.51.0"]

dev = ["plugbear[test]", "plugbear[lint]"]
dev = ["plugbear[test]", "plugbear[lint]", "plugbear[fastapi]"]
test = [
"pytest~=7.4",
"pytest-asyncio~=0.23",
"httpx", # for fastapi.testclient
]
lint = [
"ruff~=0.1",
"mypy~=1.7",
]


Expand All @@ -50,7 +50,7 @@ asyncio_mode = "auto"

[tool.ruff]
line-length = 120
target-version = "py38"
target-version = "py39"

[tool.ruff.format]
# Like Black, use double quotes for strings.
Expand All @@ -60,4 +60,31 @@ indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
line-ending = "auto"


[tool.mypy]
python_version = "3.9"
allow_redefinition = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
no_implicit_reexport = true
no_warn_no_return = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_ignores = true

pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true

# Plugins
plugins = [
"pydantic.mypy",
]

0 comments on commit 80e9756

Please sign in to comment.