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

ci(gha): set up CI #4

Merged
merged 16 commits into from
Dec 20, 2023
Merged
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
Copy link
Member

Choose a reason for hiding this comment

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

How are we bumping the package version while publishing? Can the version be automatically reflected to sdk version header?

Copy link
Member Author

Choose a reason for hiding this comment

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

How are we bumping the package version while publishing?

Just update variable __version__ of plugbear/__init__.py. Flit will pick the variable and publish with it.

Can the version be automatically reflected to sdk version header?

Yeap. Because the __version__ is an ordinary python variable, and we use it on header directly.

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",
]
Loading