--- /dev/null
+.mypy_cache
+result
--- /dev/null
+## [1.0.0] - 2023-04-04
+
+Initial release
--- /dev/null
+A minimal "hello world" python web server.
--- /dev/null
+{ pkgs ? import <nixpkgs> { }, lint ? false }:
+
+pkgs.python3Packages.callPackage
+({ autopep8, buildPythonPackage, curl, lib, mypy, pylint, }:
+ buildPythonPackage rec {
+ pname = "hellowebpy";
+ version = "1.0.0";
+ src = lib.cleanSource ./.;
+ PIP_DISABLE_PIP_VERSION_CHECK = 1;
+ checkInputs = [ curl mypy ] ++ lib.optionals lint [ autopep8 pylint ];
+ doCheck = true;
+ checkPhase = "./test.sh";
+ meta = {
+ description = "A minimal 'hello world' python web server.";
+ homepage = "https://git.scottworley.com/hellowebpy";
+ license = pkgs.lib.licenses.gpl3;
+ maintainers = with pkgs.lib.maintainers; [ chkno ];
+ };
+ }) { }
--- /dev/null
+#!/usr/bin/env bash
+
+# Copy me to .git/hooks/pre-commit
+
+set -e
+
+cleanup() {
+ if [[ "$D" && -e "$D" ]];then
+ rm -rf "$D"
+ fi
+}
+trap cleanup EXIT
+
+D=$(mktemp -d)
+[[ "$D" && -d "$D" ]]
+
+git checkout-index --prefix="$D/" -a
+pushd "$D"
+
+nix-shell --arg lint true --run './test.sh lint'
+
+popd
--- /dev/null
+from http.server import BaseHTTPRequestHandler, HTTPServer
+
+listen_address = ('', 8080)
+
+
+class HelloServer(BaseHTTPRequestHandler):
+ def do_GET(self) -> None:
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
+ self.end_headers()
+ self.wfile.write(bytes("<html><body>Hello Web</body></html>", "utf-8"))
+
+
+def main() -> None:
+ webServer = HTTPServer(listen_address, HelloServer)
+ webServer.serve_forever()
+
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+from setuptools import setup
+
+setup(
+ name='hellowebpy',
+ version='1.0.0',
+ description="A minimal 'hello world' python web server.",
+ author="Scott Worley",
+ author_email="scottworley@scottworley.com",
+ url="https://git.scottworley.com/hellowebpy",
+ py_modules=['hellowebpy'],
+ license="GPL-3.0",
+ entry_points={'console_scripts': ['hellowebpy = hellowebpy:main']},
+)
--- /dev/null
+#!/bin/sh
+
+set -e
+
+PARALLELISM=4
+
+find . -name build -prune -o -name dist -prune -o -name '*.py' -print0 |
+ xargs -0 mypy --strict --ignore-missing-imports --no-warn-unused-ignores
+
+for test in tests/*;do
+ if [ ! -d "$test" ];then
+ echo "### Running test $test" >&2
+ "$test"
+ fi
+done
+
+find . -name '*_test.py' -print0 | xargs -0 -r -n1 python3
+
+if [ "$1" = lint ];then
+
+ find . -name '*.py' -print0 | xargs -0 pylint --reports=n --persistent=n --ignore-imports=y -d fixme,invalid-name,missing-docstring,subprocess-run-check,too-few-public-methods
+
+ formatting_needs_fixing=$(
+ find . -name '*.py' -print0 |
+ xargs -P "$PARALLELISM" -0 -n1 autopep8 --diff -aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ )
+ if [ "$formatting_needs_fixing" ];then
+ echo "Formatting needs fixing:"
+ echo "$formatting_needs_fixing"
+ exit 1
+ fi
+
+fi
--- /dev/null
+#!/bin/sh
+
+set -eu
+
+python3 hellowebpy.py &
+pid=$!
+
+exit_status=1
+
+for _ in $(seq 10);do
+ if curl --max-time 2 http://localhost:8080 | grep 'Hello Web';then
+ echo SUCCESS
+ exit_status=0
+ break
+ fi
+ sleep 1
+done
+
+kill "$pid"
+exit "$exit_status"