Skip to content

Commit

Permalink
Merge pull request #14 from mirumee/feature/oss
Browse files Browse the repository at this point in the history
  • Loading branch information
pkucmus authored Oct 25, 2024
2 parents bb8aa78 + 9d455fc commit dc8672a
Show file tree
Hide file tree
Showing 42 changed files with 1,657 additions and 412 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build

on:
workflow_call:
workflow_dispatch:

env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:
test:
uses: ./.github/workflows/test.yml
permissions:
contents: read
build:
name: Build distribution 📦
runs-on: ubuntu-latest
needs:
- test
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml

- name: Install Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc

- name: Set package version from tag
run: hatch version $(git describe --tags --always)

- name: Build package
run: hatch build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

sign-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
needs:
- build
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: mandatory for sigstore
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Store the signature files
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
overwrite: true
73 changes: 0 additions & 73 deletions .github/workflows/code_quality.yaml

This file was deleted.

8 changes: 5 additions & 3 deletions .github/workflows/deploy_docs.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Deploy documentation

on:
push:
branches:
- main
release:
types:
- published
workflow_call:
workflow_dispatch:

jobs:
docs-publish:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Prepare release

on:
push:
tags:
- '*'
workflow_call:
workflow_dispatch:

env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:
build:
uses: ./.github/workflows/build.yml
permissions:
contents: read
id-token: write # IMPORTANT: mandatory for sigstore in build.yml

create-release:
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Release
id: create-draft-release
uses: softprops/action-gh-release@v2
with:
files: |
./dist/*
draft: true
- name: Summary
run: |
echo "# Release summary" >> $GITHUB_STEP_SUMMARY
echo "Url: ${{ steps.create-draft-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY
echo "You can now publish the release on GitHub" >> $GITHUB_STEP_SUMMARY
43 changes: 26 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,38 @@ on:
release:
types:
- published
workflow_call:
workflow_dispatch:

env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:
pypi-publish:
name: upload release to PyPI
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
runs-on: ubuntu-latest
environment: release
environment:
name: pypi
url: https://pypi.org/p/smyth
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml

- name: Install Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc

- name: Build package
run: hatch build
contents: read

steps:
- name: Download all the dists from the release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release download
'${{ github.ref_name }}'
--dir dist/
--pattern *
--repo '${{ github.repository }}'
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test

on:
push:
branches:
- main
- master
pull_request:
workflow_call:
workflow_dispatch:

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:
run:
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
# - windows-latest
# - macos-latest

python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc

- name: Run static analysis
run: hatch fmt --check

- name: Run type checking
run: hatch run types:check

- name: Run tests
run: hatch test -c -py ${{ matrix.python-version }}
File renamed without changes.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Smyth

[![docs](https://img.shields.io/badge/Docs-Smyth-f5c03b.svg?style=flat&logo=materialformkdocs)](https://mirumee.github.io/smyth/)
![pypi](https://img.shields.io/pypi/v/smyth?style=flat)
![licence](https://img.shields.io/pypi/l/smyth?style=flat)
![pypi downloads](https://img.shields.io/pypi/dm/smyth?style=flat)
![pyversion](https://img.shields.io/pypi/pyversions/smyth?style=flat)

Smyth is a versatile tool designed to enhance your AWS Lambda development experience. It is a pure Python tool that allows for easy customization and state persistence, making your Lambda development more efficient and developer-friendly.

## Features
Expand Down Expand Up @@ -72,7 +78,6 @@ The combination of Uvicorn reload process and HTTP server process with what is b
## TODO

- [ ] Write tests
- [ ] Properly handle Uvicorn exit, kill the LambdaProcesses gracefully
- [x] Publish on PyPi

## Name
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ sequenceDiagram
STAR->>STAR: Lookup handlers by path
STAR->>+PROC: Send event and context
alt "Process is cold"
PROC<<->>HAND: Import handler
end
PROC->>+HAND: Invoke handler
HAND->>-PROC: Result
PROC->>-STAR: Result
Expand Down
4 changes: 0 additions & 4 deletions docs/user_guide/all_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ Here's a list of all the settings, including those that are simpler but equally

`context_data_function_path` - `str` (default: `"smyth.context.generate_context_data"`) A function similar to the [event generator](event_functions.md), but it constructs the `context`, adding some metadata from Smyth's runtime. You can create and use your own.

### Fake Coldstart

`fake_coldstart` - `bool` (default: `False`) Makes the subprocess `time.sleep` for a random time between 0.5 and 1 second when a subprocess is cold, imitating the longer first response time of real Lambdas.

### Log Level

`log_level` - `str` (default: `"INFO"`) Log level for Smyth's runner function, which is still part of Smyth but already running in the subprocess. Note that the logging of your Lambda handler code should be set separately.
Expand Down
1 change: 0 additions & 1 deletion docs/user_guide/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ concurrency = 2
handler_path = "smyth_test_app.handlers.product_handler"
url_path = "/products/{path:path}"
concurrency = 2
fake_coldstart = true
strategy_function_path = "smyth.runner.strategy.round_robin"
```

Expand Down
12 changes: 7 additions & 5 deletions docs/user_guide/custom_entrypoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Here's an example `smyth_conf.py` file:

```python title="my_project/etc/smyth_conf.py" linenums="1"
import uvicorn
from starlette.requests import Request
from smyth.smyth import Smyth
from smyth.server.app import SmythStarlette
from smyth.smyth import Smyth
from starlette.requests import Request


def my_handler(event, context):
return {"statusCode": 200, "body": "Hello, World!"}
Expand All @@ -46,16 +47,17 @@ smyth = Smyth()
smyth.add_handler(
name="hello",
path="/hello",
lambda_handler=my_handler,
lambda_handler_path="smyth_run.my_handler",
timeout=1,
concurrency=1,
event_data_generator=my_event_data_generator,
event_data_function=my_event_data_generator,
)

app = SmythStarlette(smyth=smyth, smyth_path_prefix="/smyth")

if __name__ == "__main__":
uvicorn.run("smyth_conf:app", host="0.0.0.0", port=8080, reload=True)
uvicorn.run("smyth_run:app", host="0.0.0.0", port=8080, reload=True)

```

Normally, the handler would be imported, but including the custom event generator in this file is a good use case. Use the `SmythStarlette` subclass of `Starlette` - it ensures all subprocesses are run at server start and killed on stop (using ASGI Lifetime). Create a Smyth instance and pass it to your `SmythStarlette` instance. Here, you can fine-tune logging, change Uvicorn settings, etc.
Expand Down
Loading

0 comments on commit dc8672a

Please sign in to comment.