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

feat: setup with poetry #7

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
# Python Func Runtime

This repository contains the function invocation and runtime framework for
Knative Python functions.
This middleware is used by Knative Functions to expose a Function written in
Python as a network service.


## Contents
```
.
├── cmd
│   └── fhttp - Example a function using the http middleware
├── src/func_python
│   ├── http.py - HTTP Middleware
└── README.md - This Readme
```

## Development

- install `poetry` via `pipx`
- activate the virtual environment managed by poetry via `poetry shell`
Note that on some environments this command may cause collissions with
configured keyboard shortcuts. If there are problems, you can source
the environment variables from the autogenerated venv with:
`source $(poetry env info --path)/bin/activate`
- install dependencies into the activated environment with `poetry install`
- run the example via `python cmd/fhttp/main.py`
- deactivate the virtual environment with `exit`
24 changes: 0 additions & 24 deletions cmd/fhttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,3 @@ This is an example usage of the Functions HTTP middleware.

To see the actual middleware which is used when building a Python Function,
see the [Functions Python Scaffolding](https://github.com/knative/func/tree/main/templates/python/http)

## Running

Create a local virtual environment if it does not already exist:
```bash
python3 -m venv venv
```
Activate the virtual environment:
```bash
source ./venv/bin/activate
```
Ensure the requirements are installed:
```bash
pip install -r requirements.txt
```
Run the application:
```bash
python3 ./main.py
```
use `^C` to stop the application

To Deactivate the virtual environment:
```bash
deactivate
6 changes: 3 additions & 3 deletions cmd/fhttp/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import logging
import func_python.http
from func_python.http import serve

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -65,7 +65,7 @@ def new():
if __name__ == "__main__":
if args.static:
logging.info("Starting static handler")
func_python.http.serve(handle)
serve(handle)
else:
logging.info("Starting new instance")
func_python.http.serve(new)
serve(new)
1 change: 0 additions & 1 deletion http/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion http/requirements.txt

This file was deleted.

102 changes: 102 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "func-python"
version = "0.1.0"
description = "Knative Functions Python Middleware"
authors = ["Luke Kingland <[email protected]>"]
readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/knative-extensions/func-python"

[tool.poetry.dependencies]
python = "^3.12"
hypercorn = "^0.17.3"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading