diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/README.md b/README.md index 683af360..72d58651 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/cmd/fhttp/README.md b/cmd/fhttp/README.md index e0da1d78..b800a58e 100644 --- a/cmd/fhttp/README.md +++ b/cmd/fhttp/README.md @@ -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 diff --git a/cmd/fhttp/main.py b/cmd/fhttp/main.py index 65b4230f..f014c15a 100644 --- a/cmd/fhttp/main.py +++ b/cmd/fhttp/main.py @@ -1,6 +1,6 @@ import argparse import logging -import func_python.http +from func_python.http import serve logging.basicConfig(level=logging.INFO) @@ -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) diff --git a/http/__init__.py b/http/__init__.py deleted file mode 100644 index 06491da8..00000000 --- a/http/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .serve import serve diff --git a/http/requirements.txt b/http/requirements.txt deleted file mode 100644 index 083a5e9c..00000000 --- a/http/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -hypercorn diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 00000000..dcfeb2c6 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,102 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "h11" +version = "0.14.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +optional = false +python-versions = ">=3.7" +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + +[[package]] +name = "h2" +version = "4.1.0" +description = "HTTP/2 State-Machine based protocol implementation" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "h2-4.1.0-py3-none-any.whl", hash = "sha256:03a46bcf682256c95b5fd9e9a99c1323584c3eec6440d379b9903d709476bc6d"}, + {file = "h2-4.1.0.tar.gz", hash = "sha256:a83aca08fbe7aacb79fec788c9c0bac936343560ed9ec18b82a13a12c28d2abb"}, +] + +[package.dependencies] +hpack = ">=4.0,<5" +hyperframe = ">=6.0,<7" + +[[package]] +name = "hpack" +version = "4.0.0" +description = "Pure-Python HPACK header compression" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "hpack-4.0.0-py3-none-any.whl", hash = "sha256:84a076fad3dc9a9f8063ccb8041ef100867b1878b25ef0ee63847a5d53818a6c"}, + {file = "hpack-4.0.0.tar.gz", hash = "sha256:fc41de0c63e687ebffde81187a948221294896f6bdc0ae2312708df339430095"}, +] + +[[package]] +name = "hypercorn" +version = "0.17.3" +description = "A ASGI Server based on Hyper libraries and inspired by Gunicorn" +optional = false +python-versions = ">=3.8" +files = [ + {file = "hypercorn-0.17.3-py3-none-any.whl", hash = "sha256:059215dec34537f9d40a69258d323f56344805efb462959e727152b0aa504547"}, + {file = "hypercorn-0.17.3.tar.gz", hash = "sha256:1b37802ee3ac52d2d85270700d565787ab16cf19e1462ccfa9f089ca17574165"}, +] + +[package.dependencies] +h11 = "*" +h2 = ">=3.1.0" +priority = "*" +wsproto = ">=0.14.0" + +[package.extras] +docs = ["pydata_sphinx_theme", "sphinxcontrib_mermaid"] +h3 = ["aioquic (>=0.9.0,<1.0)"] +trio = ["trio (>=0.22.0)"] +uvloop = ["uvloop (>=0.18)"] + +[[package]] +name = "hyperframe" +version = "6.0.1" +description = "HTTP/2 framing layer for Python" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "hyperframe-6.0.1-py3-none-any.whl", hash = "sha256:0ec6bafd80d8ad2195c4f03aacba3a8265e57bc4cff261e802bf39970ed02a15"}, + {file = "hyperframe-6.0.1.tar.gz", hash = "sha256:ae510046231dc8e9ecb1a6586f63d2347bf4c8905914aa84ba585ae85f28a914"}, +] + +[[package]] +name = "priority" +version = "2.0.0" +description = "A pure-Python implementation of the HTTP/2 priority tree" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "priority-2.0.0-py3-none-any.whl", hash = "sha256:6f8eefce5f3ad59baf2c080a664037bb4725cd0a790d53d59ab4059288faf6aa"}, + {file = "priority-2.0.0.tar.gz", hash = "sha256:c965d54f1b8d0d0b19479db3924c7c36cf672dbf2aec92d43fbdaf4492ba18c0"}, +] + +[[package]] +name = "wsproto" +version = "1.2.0" +description = "WebSockets state-machine based protocol implementation" +optional = false +python-versions = ">=3.7.0" +files = [ + {file = "wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736"}, + {file = "wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065"}, +] + +[package.dependencies] +h11 = ">=0.9.0,<1" + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "4572bc0148f9ac50a91572cdc02dd5a978a6760da7ddae0413b021e3305db338" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..77eb5bb7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "func-python" +version = "0.1.0" +description = "Knative Functions Python Middleware" +authors = ["Luke Kingland "] +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" diff --git a/http/README.md b/src/func_python/README.md similarity index 100% rename from http/README.md rename to src/func_python/README.md diff --git a/__init__.py b/src/func_python/__init__.py similarity index 100% rename from __init__.py rename to src/func_python/__init__.py diff --git a/http/serve.py b/src/func_python/http.py similarity index 100% rename from http/serve.py rename to src/func_python/http.py