Created
February 3, 2021 14:21
-
-
Save podhmo/afed2551dd7a423fb44a3a085105aab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
from wsgiref.simple_server import make_server | |
def make_app(handler): | |
def app(environ, start_response): | |
status = "200 OK" | |
headers = [("Content-type", "application/json; charset=utf-8")] | |
start_response(status, headers) | |
return [json.dumps(handler(environ)).encode("utf-8")] | |
return app | |
def run_app(app, port): | |
httpd = make_server("", port, app) | |
print(f"Serving on port {port}...", file=sys.stderr) | |
# Serve until process is killed | |
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hello(name: str) -> str: | |
return f"hello {name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import foo | |
from foo.hello import hello | |
def main(): | |
app = foo.make_app(lambda environ: {"message": hello("world")}) | |
foo.run_app(app, 8000) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run: | |
python -m main.py | |
build: | |
python -m zipapp -c -o app.pyz ../myzipapp -m "main:main" | |
clean: | |
rm -f app.pyz | |
find . -name __pycache__ -type d -exec rm -rf {} + | |
.PHONY: run build clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment