The build, the lints and what is missing
The last page is the part a reader needs to reproduce the project and the part a reviewer needs to trust it: the scripts, the lint runs, the deployment question, and an honest list of what was not run here.
The three scripts
build.sh is the compiler command and nothing else, so that the library can be rebuilt by hand from the page:
#!/bin/sh # Build the shared library the Python side loads. set -e cd "$(dirname "$0")" gfortran -Wall -Wextra -std=f2018 -shared -fPIC core/stats.f90 -o libstats.so echo "built libstats.so"
test_core.sh builds the library, builds the Fortran test against it and runs it:
#!/bin/sh # Build and run the Fortran tests against the shared library. set -e cd "$(dirname "$0")" ./build.sh gfortran -Wall -Wextra -std=f2018 core/test_core.f90 -L. -lstats -Wl,-rpath,'$ORIGIN' -o test_core ./test_core
run-tests.sh runs both sides:
#!/bin/sh # Run both sides of the test suite and keep the worst status. set -e cd "$(dirname "$0")" ./test_core.sh cd python python3 -m unittest
Each script begins with cd "$(dirname "$0")", so that it works from any directory a build system happens to call it from, and set -e, so that a failure stops it and becomes the status of the script. The three are the whole build system: no make, no CMake, no fpm. A project of this size does not need one, and a project that grows past it replaces test_core.sh with a Makefile rule and keeps the same three commands.
The Python gates
The four Python files were checked with the three tools this image carries, from the python directory:
ruff format --check .
ruff check --no-cache .
mypy --cache-dir /tmp/mypy .
pylint --score=y numerics.py service.py wsgi.py test_numerics.py test_service.py
5 files already formatted
All checks passed!
Success: no issues found in 5 source files
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
The mypy cache goes to /tmp/mypy and ruff's to a cache directory beside the files, which is deleted before and after a run, so nothing generated lands in the project. The files the gates see are the five that are shown on the pages of this group, byte for byte.
Two findings from the first runs are worth recording because they are the kind a gate exists for. mypy refused the service tests until the server, the base URL and the thread were declared as class attributes, because it cannot see that setUpClass assigns them. And pylint reported the log_message override twice: shadowing the builtin format (the base class's parameter name, kept with a one-line disable) and then for using a different name, which breaks the override. The first version of the file also leaked an HTTPError object, which Python 3.14 reports as a ResourceWarning; the test that reads a 404 body closes it now.
Behind a WSGI server
http.server is a development server. The same routing as a WSGI callable is twenty lines, and the numerical core does not change at all: only the transport does. The file python/wsgi.py:
"""A WSGI adapter for the service, for a server that speaks WSGI. The handler of service.py is written for http.server; this module turns the same routing into a plain WSGI callable so that a general-purpose server can run it. The numerical core is untouched: only the transport changes. """ from __future__ import annotations import json from collections.abc import Callable from typing import Any from urllib.parse import parse_qs import numerics import service StartResponse = Callable[[str, list[tuple[str, str]]], None] def application(environ: dict[str, Any], start_response: StartResponse) -> list[bytes]: """Answer one request: /health and /stats, as JSON, without http.server.""" path = environ.get("PATH_INFO", "/") query = parse_qs(environ.get("QUERY_STRING", "")) if path == "/health": status, body = "200 OK", b'{"status": "ok"}' elif path == "/stats": try: values = service.parse_values(query.get("values", [""])[0]) status, body = "200 OK", json.dumps(service.summary(values)).encode() except (ValueError, numerics.CoreError) as error: status, body = "400 Bad Request", json.dumps({"error": str(error)}).encode() else: status, body = ( "404 Not Found", json.dumps({"error": f"no route for {path}"}).encode(), ) headers = [("Content-Type", "application/json"), ("Content-Length", str(len(body)))] start_response(status, headers) return [body]
The adapter was run under wsgiref.simple_server, which is part of the standard library, and answered a real request:
python3 -c "from wsgiref.simple_server import make_server; import wsgi; make_server('127.0.0.1', 8766, wsgi.application).serve_forever()"
curl -s -i "http://127.0.0.1:8766/stats?values=2,4,4,5"
HTTP/1.0 200 OK
Date: Wed, 18 Nov 2026 21:26:17 GMT
Server: WSGIServer/0.2 CPython/3.14.10
Content-Type: application/json
Content-Length: 63
{"n": 4, "mean": 3.75, "sd": 1.2583057392117916, "median": 4.0}
The production command is a WSGI server with workers, and the adapter has to answer through one. gunicorn 27.0.1 was installed with pip into a virtual environment at /tmp/v, outside the project, and started from the python directory:
python3 -m venv /tmp/v && /tmp/v/bin/pip install gunicorn
cd python
/tmp/v/bin/gunicorn --workers 4 --bind 127.0.0.1:8000 wsgi:application &
It logged Starting gunicorn 27.0.1, Listening at: http://127.0.0.1:8000, Using worker: sync and four Booting worker with pid: lines, so the four workers were up. The same four questions as on the service page, now against port 8000:
curl -s -i "http://127.0.0.1:8000/health"
curl -s -i "http://127.0.0.1:8000/stats?values=2,4,4,5"
curl -s -i "http://127.0.0.1:8000/stats?values=2,four,5"
curl -s -i "http://127.0.0.1:8000/nothing"
HTTP/1.1 200 OK
Server: gunicorn
Date: Thu, 19 Nov 2026 06:33:38 GMT
Connection: close
Content-Type: application/json
Content-Length: 16
{"status": "ok"}
HTTP/1.1 200 OK
Server: gunicorn
Date: Thu, 19 Nov 2026 06:33:38 GMT
Connection: close
Content-Type: application/json
Content-Length: 63
{"n": 4, "mean": 3.75, "sd": 1.2583057392117916, "median": 4.0}
HTTP/1.1 400 Bad Request
Server: gunicorn
Date: Thu, 19 Nov 2026 06:33:38 GMT
Connection: close
Content-Type: application/json
Content-Length: 54
{"error": "could not convert string to float: 'four'"}
HTTP/1.1 404 Not Found
Server: gunicorn
Date: Thu, 19 Nov 2026 06:33:38 GMT
Connection: close
Content-Type: application/json
Content-Length: 34
{"error": "no route for /nothing"}
The four bodies are the ones the http.server session on the service page returned: the same numbers, the same two error messages, the same status codes. The wsgiref run above showed the /stats body, identical too. The header lines are where the server shows itself: HTTP/1.1 instead of HTTP/1.0, Server: gunicorn instead of BaseHTTP/0.6 Python/3.14.10 or WSGIServer/0.2 CPython/3.14.10, and a Connection: close line. Nothing between the adapter and the core changed for it.
uwsgi was not run here, so no output of it appears on this page and no claim is made about it: the four responses above are gunicorn's, and the adapter they went through is the file above.
What is missing
| tool or library | used for | state here |
|---|---|---|
| numpy | the independent check of the arithmetic, and f2py | installed in a virtual environment for one run, see the wrapper page |
| f2py | generating the ctypes layer from the Fortran source | ships with numpy, not run here |
| gunicorn | serving the WSGI adapter with workers | installed in a virtual environment for one run, see above |
| uwsgi | serving the WSGI adapter with workers | not run here |
| pytest | a test runner with fixtures and plugins | installed, but the project uses unittest, which is in the standard library |
Nothing else was needed. The Fortran side required gfortran and nothing else, the Python side the standard library, and the two lints that are not part of Python (ruff, mypy) are in this image and were run. A project that ships this shape to a server needs the two packages the runs above used, numpy and gunicorn, and each is one line in a requirements file, pinned to the version it was run with; f2py comes with numpy, and uwsgi was not run here.
Copying the project
The nine files are on the five pages of this group. A reader who wants the project in one directory creates this layout and copies the blocks:
.
├── build.sh
├── core
│ ├── stats.f90
│ └── test_core.f90
├── python
│ ├── numerics.py
│ ├── service.py
│ ├── wsgi.py
│ ├── test_numerics.py
│ └── test_service.py
├── run-tests.sh
└── test_core.sh
Then chmod +x *.sh and ./run-tests.sh. The library is built into the project directory, the Fortran test finds it through its rpath and the Python wrapper through the path it computes from __file__, so no environment variable is needed for either. Here the project lived in /tmp/proj; every path in the files is relative to the project root and nothing depends on that choice.
Exercises
- Replace the three scripts with one Makefile that has all, test and clean targets. Which parts of the shell scripts survive as recipe lines?
- Add the WSGI adapter to the test suite with wsgiref.util.setup_testing_defaults. What does the test call, and which of the four routes does it cover?
- Run pylint on the Fortran side by installing a Fortran analyser. Which one is in this image, and what does it report on the core?
- Pin the Python dependencies in a requirements file that contains only what the project imports. How many lines does it have, and why is that a feature?
The programs on this page were built with GNU Fortran (Alpine 15.2.0) 15.2.0 and run with Python 3.14.10, ruff, mypy and pylint on Alpine Linux 3.24.3 (x86_64) in a Docker container. The gunicorn run used gunicorn 27.0.1 with Python 3.14.10, installed with pip in a virtual environment outside the project, in a container of the same image.
Article author: Arthur Isaev