Python tutorial: container image and Gitea Actions stages, stages 3 to 6 marked optional

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
babic_aandClaude Fable 5.2 committed 2026-11-25 15:14:17 +01:00
1 parent b663a2e4fa
commit 20ad2d1bfa
3 files changed
+374 -118

No files matched your search

@@ -9,9 +9,20 @@ tags:
# PSI Python Environment
In this tutorial you build `pvshow`, a small Python tool that reads PVs over Channel Access and prints their value and timestamp. You start with a ten-line script and grow it in four stages into a package with a command, tests, a version tag and the files to package it. Every stage runs before you go on. The tool only reads PVs. Plan about an hour.
In this tutorial you build `pvshow`, a small Python tool that reads PVs over Channel Access and prints their value and timestamp. You start with a ten-line script and grow it in six stages into a package with a command, tests, a release, an RPM spec, a container image and automatic builds in Gitea. Every stage runs before you go on. The tool only reads PVs.
![The four stages: 1 one script, read_pv.py; 2 a package with a command, pyproject.toml and pvshow/cli.py, installed with pip install -e .; 3 a tool you can rely on, with several PVs, JSON, follow mode, logs on stderr and unit tests; 4 ready to hand over, with version 1.0.0, python -m build and pvshow.spec for an RPM](images/02_python_overview.svg)
You do not need all of this. The tutorial shows how to set up everything a tool might need; a real tool uses only the parts it needs, and many stop after stage 2 or 3. Stages 1 and 2 are the base. After that, take only the stages you need; stage 6 automates what you set up in stages 3 to 5, so leave out the workflow steps for parts you do not have.
![The six stages: 1 one script; 2 a package with a command; optional: 3 a tool you can rely on, with tests; 4 ready to hand over, with version, tag, wheel, sdist and RPM spec; 5 a container image; 6 automatic builds with Gitea Actions. Take only the optional stages your tool needs; the tool reaches Controls hosts with autodeploy](images/02_python_overview.svg)
| Stage | What you get | When you need it |
| --- | --- | --- |
| 1. One script | a script that reads a PV | to try something out |
| 2. A package with a command | the command `pvshow`, installed with pip, with options and exit codes | for every tool that others install; the base for the rest |
| 3. A tool you can rely on (optional) | several PVs, JSON, follow mode, logging, unit tests | when others depend on the tool or it runs as a service |
| 4. Ready to hand over (optional) | version and tag, wheel and sdist, RPM spec | when you release it to others |
| 5. A container image (optional) | an image in the Gitea registry | when the tool runs in a container |
| 6. Automatic builds (optional) | tests on every push, a release built and published from a tag | when you release often or several people work on the tool |
## Before you start
@@ -78,7 +89,7 @@ Put the project under Git from the start. Create `.gitignore`, so the venv stays
A script is run by its path. A package with a command is installed into the venv and run by its name, with options, a help text and exit codes that other programs can check. The finished project looks like this; in this stage you create `pyproject.toml` and the folder `pvshow/` with `__init__.py` and `cli.py`. The package folder sits directly next to `pyproject.toml` (a flat layout): nothing more to learn for a package of this size.
![Layout of the finished project: pyproject.toml, README.md, .gitignore, pvshow.spec, the package folder pvshow with __init__.py, cli.py and reader.py, the folder tests and .venv, which is not in Git; the line pvshow = "pvshow.cli:main" in pyproject.toml makes pip write .venv/bin/pvshow, which calls main() in pvshow/cli.py](images/02_python_layout.svg)
![Layout of the finished project: pyproject.toml, README.md, .gitignore, pvshow.spec, Containerfile, .containerignore, the package folder pvshow with __init__.py, cli.py and reader.py, the folders tests and .gitea/workflows with ci.yml and release.yml, and .venv, which is not in Git; the line pvshow = "pvshow.cli:main" in pyproject.toml makes pip write .venv/bin/pvshow, which calls main() in pvshow/cli.py](images/02_python_layout.svg)
The command replaces the script. Remove it, create the package folder and its empty `__init__.py`, which makes the folder a package:
@@ -174,7 +185,7 @@ Run it:
The first prints name, value and timestamp, for example `<PV> 21.5 2026-11-25 14:04:47.849`. The second prints `pvshow: TUT:DOES-NOT-EXIST: no connection within 1.0 s` and exit code `1`. `which pvshow` shows where the command lives: `/psi.ch/<your folder>/git/pvshow/.venv/bin/pvshow`. Because the install is editable, a change in `cli.py` takes effect at the next run, without installing again. Commit the stage.
## Stage 3: a tool you can rely on
## Stage 3: a tool you can rely on (optional)
Now the tool reads several PVs at once, prints JSON for other programs, can keep running and print every change, logs what goes wrong, and has tests. The reading moves into its own module, `pvshow/reader.py`, so that it can be tested without the command line:
@@ -395,7 +406,7 @@ Give the stage a new version: in `pyproject.toml`, change `version = "0.1.0"` to
Commit the stage.
## Stage 4: ready to hand over
## Stage 4: ready to hand over (optional)
Before others use the tool, it gets a version they can ask for, a tag in Git, and the files to package it. How you package and deliver it is your choice; this stage shows two ways briefly.
@@ -484,16 +495,261 @@ Commit, then publish the repository. In Gitea, create an empty repository `pvsho
The repository page in Gitea shows your files and the tag `1.0.0`.
Getting the tool onto Controls hosts is done with [Autodeploy](../../2._Services_Portfolio/Services/11_autodeploy.md); the policy for Python software on the Controls platform is in [Python software](../../2._Services_Portfolio/Services/03_devops.md#python-software).
## Stage 5: a container image (optional)
Package the tool as a container image when it should run in a container, for example as a service on a container host. This stage keeps to the essentials; everything else about images, the registry and running containers is in [How-To: Use Containers](../03_how_to/09_containers.md). Give the release a new version first: set `version = "1.1.0"` in `pyproject.toml` and `%define version 1.1.0` in `pvshow.spec`.
Create `Containerfile` in the project folder:
# Build for linux/amd64: pyepics bundles its Channel Access library (libca)
# for linux64 only, and the Controls hosts are x86_64.
#
# podman build --platform linux/amd64 -t pvshow:dev .
FROM python:3.11-slim
WORKDIR /app
COPY pyproject.toml README.md ./
COPY pvshow/ pvshow/
RUN pip install --no-cache-dir .
ENV PYTHONUNBUFFERED=1
RUN useradd --create-home --uid 10001 appuser
USER appuser
ENTRYPOINT ["pvshow"]
Line by line:
- `FROM python:3.11-slim`: a small Debian image with Python 3.11, pinned to that version so a rebuild gives the same Python.
- `COPY` and `RUN pip install --no-cache-dir .`: copy only what the package needs and install it with pip, as in a venv; `--no-cache-dir` keeps pip's cache out of the image.
- `ENV PYTHONUNBUFFERED=1`: output is written at once and reaches the journal.
- `useradd --uid 10001` and `USER appuser`: the tool runs as an ordinary user with a fixed uid, not as root.
- `ENTRYPOINT ["pvshow"]`: the container runs the command, and the arguments of `podman run` after the image name go to `pvshow`. The list form makes `pvshow` the main process, so it receives the stop signal directly.
Create `.containerignore`, which keeps Git data, the venv, the tests and build output out of the build:
.git
.gitea
.venv
__pycache__
*.pyc
*.egg-info
build
dist
RPMS
tests
.env
On a machine with Podman, build the image for `linux/amd64` and run it. The platform matters: pyepics brings its Channel Access library for 64-bit Linux on x86 only, and the Controls hosts are x86_64, so an image built for arm64 on a Mac with Apple Silicon cannot open a single channel.
podman build --platform linux/amd64 -t pvshow:dev .
podman run --rm pvshow:dev --help
The second command prints the same help as `pvshow --help`. To read a PV, the container needs what the tool uses on the host: the Channel Access environment and the network. `-e NAME` without a value copies the variable from your shell; `--network host` lets the container search on the same networks as the host, including the CA gateway named in `EPICS_CA_ADDR_LIST`:
podman run --rm --network host -e EPICS_CA_ADDR_LIST -e EPICS_CA_AUTO_ADDR_LIST pvshow:dev <PV>
Publish the image by hand to the Gitea registry `gitea.psi.ch`, under your group's organisation and the version. Log in with your Gitea user and, as password, a Gitea access token with the scope `write:package` (**Settings → Applications → Access Tokens**):
podman login gitea.psi.ch -u <your Gitea user>
podman tag pvshow:dev gitea.psi.ch/<organisation>/pvshow:1.1.0
podman push gitea.psi.ch/<organisation>/pvshow:1.1.0
The image is then listed in the **Packages** tab of the organisation in Gitea. Commit, tag and push the release:
git add .
git commit -m "Stage 5: container image, version 1.1.0"
git tag 1.1.0
git push origin HEAD 1.1.0
## Stage 6: automatic builds with Gitea Actions (optional)
Until now you ran the tests and built the packages and the image by hand. Gitea Actions does it for you: Gitea runs the workflows in `.gitea/workflows/` of your repository on its runners. This stage adds two workflows, modelled on the ones that build and release the gfa-monitoring application on this Gitea:
- `ci.yml` checks every push to `main` and every pull request.
- `release.yml` builds and publishes a release when you push a version tag.
Create `.gitea/workflows/ci.yml`:
name: CI
# On every push to main and every pull request: install the package, run the
# tests, build the wheel and sdist, and check that the container image builds.
# Nothing is published.
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install
run: pip install --no-cache-dir .
- name: Tests
run: python -m unittest -v
- name: Build wheel and sdist
run: |
pip install --no-cache-dir build
python -m build
container:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -f Containerfile -t pvshow:ci .
- The job `test` checks out the commit, sets up Python 3.11, installs the package, runs the unit tests and builds the wheel and the sdist.
- The job `container` builds the image with Docker on the runner, to show that the `Containerfile` still works. Nothing is published.
Create `.gitea/workflows/release.yml`:
name: Release
# On a version tag (the bare version number) that is on main:
#
# git tag 1.2.0 && git push origin 1.2.0
#
# test, build the wheel and sdist and keep them as artifacts of the run, then
# build the image for linux/amd64 and push it to the Gitea registry with the
# tags :1.2.0, :1.2, :latest and :sha-<short>.
#
# Requires a repository secret REGISTRY_TOKEN holding a Gitea access token
# with write:package. The built-in token has no package scope.
on:
push:
tags: ["[0-9]*"]
permissions:
contents: read
packages: write
env:
REGISTRY: gitea.psi.ch
IMAGE_NAME: ${{ gitea.repository }}
jobs:
guard:
name: Verify the tag is on main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Reject tags that are not contained in main
run: |
set -euo pipefail
git fetch --quiet origin main
TAG_SHA="$(git rev-list -n 1 "${{ gitea.ref }}")"
if git merge-base --is-ancestor "$TAG_SHA" origin/main; then
echo "Tag ${{ gitea.ref_name }} is on main. Proceeding."
else
echo "::error::Tag ${{ gitea.ref_name }} is not on main. Only tags on main are released."
exit 1
fi
packages:
name: Test and build wheel and sdist
needs: guard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install --no-cache-dir .
- run: python -m unittest -v
- run: |
pip install --no-cache-dir build
python -m build
- uses: actions/upload-artifact@v3
with:
name: pvshow-${{ gitea.ref_name }}
path: dist/
image:
name: Build and push the image
needs: packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Fail early if no registry token is configured
run: |
if [ -z "${{ secrets.REGISTRY_TOKEN }}" ]; then
echo "::error::REGISTRY_TOKEN is not set; the push would fail with 'unauthorized'."
exit 1
fi
- name: Log in to the Gitea registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Derive tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-,format=short
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Containerfile
push: true
# pyepics bundles libca for linux64 only; the Controls hosts are x86_64.
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- `on: push: tags: ["[0-9]*"]`: the workflow runs for tags that start with a digit, so for version tags like `1.2.0`.
- The job `guard` stops the release when the tag points at a commit that is not on `main`; a tag can be pushed from any commit.
- The job `packages` runs the tests, builds the wheel and the sdist, and keeps `dist/` as an artifact of the run, named after the tag.
- The job `image` logs in to `gitea.psi.ch` with the token from the secret `REGISTRY_TOKEN`, derives the image tags from the version tag (`1.2.0`, `1.2`, `latest`, `sha-<commit>`), builds the image for `linux/amd64` and pushes it to `gitea.psi.ch/<organisation>/pvshow`. It stops at once with an error when the secret is missing.
The RPM is not built here: build it by hand as in stage 4.
Set up the repository once in Gitea:
1. In the repository settings, enable Actions for the repository.
2. Create an access token with the scope `write:package` under **Settings → Applications → Access Tokens**. The built-in token of Gitea Actions has no package scope, so the push needs a token of its own.
3. Store the token in the repository under **Settings → Actions → Secrets** as `REGISTRY_TOKEN`.
Commit and push the workflows:
git add .gitea
git commit -m "Stage 6: Gitea Actions for CI and release"
git push
In the **Actions** tab of the repository, a run of **CI** appears with the jobs `test` and `container`; when both are green, the commit passed. A pull request shows the same checks. Now release with a version tag. Set the version `1.2.0` in `pyproject.toml` and `pvshow.spec`, commit, tag and push:
git commit -am "Version 1.2.0"
git push
git tag 1.2.0
git push origin 1.2.0
A run of **Release** appears with the jobs `guard`, `packages` and `image`. When it is green, the run page offers the artifact `pvshow-1.2.0` with the wheel and the sdist for download, and the organisation's **Packages** tab lists the image `pvshow` with the tags `1.2.0`, `1.2`, `latest` and `sha-<commit>`.
## What you have learned
You have grown a script into a Python tool the Controls way: a package with standard metadata in `pyproject.toml` and a command, installed with pip into a venv in editable mode; output on stdout and log messages on stderr, so that it works as a service; tests that run without an EPICS network; a README with the requirements per install route; a version and a tag in Gitea; and a wheel, a source archive and an RPM spec, ready for the packaging you choose.
You have grown a script into a Python tool the Controls way: a package with standard metadata in `pyproject.toml` and a command, installed with pip into a venv in editable mode; output on stdout and log messages on stderr, so that it works as a service; tests that run without an EPICS network; a README with the requirements per install route; a version and a tag in Gitea; a wheel, a source archive and an RPM spec; a container image in the Gitea registry; and workflows that test every push and publish a release from a tag.
Again: you do not need all of it. Keep the stages your tool needs and leave out the rest. Getting the tool onto Controls hosts is done with [Autodeploy](../../2._Services_Portfolio/Services/11_autodeploy.md); the policy for Python software on the Controls platform is in [Python software](../../2._Services_Portfolio/Services/03_devops.md#python-software).
Where to go next:
- [How-To: Manage Virtual Python Environments](../03_how_to/08_python_venv.md): reproduce an environment on another machine, run a tool from a service, pixi as an alternative.
- [Python software](../../2._Services_Portfolio/Services/03_devops.md#python-software): the policy and the install routes.
- [IOC Utils](../../2._Services_Portfolio/Tools/01_ioc_utils.md): a Controls Python tool in daily use.
- [How-To: Use Containers](../03_how_to/09_containers.md): run a Python service in a container.
- [How-To: Use Containers](../03_how_to/09_containers.md): images, the registry and running containers on a container host.
- [How-To: Build and Deploy RPMs](../03_how_to/07_build_deploy_rpms.md).
@@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 460" role="img" aria-labelledby="t d">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 582" role="img" aria-labelledby="t d">
<title id="t">Layout of the pvshow project and how the command finds its code</title>
<desc id="d">The finished project folder pvshow holds pyproject.toml (name, version, dependencies, command), README.md (requirements per install route), .gitignore (keeps .venv and build output out of Git), pvshow.spec (RPM, if you choose one), the package folder pvshow with __init__.py, cli.py (main: options and output) and reader.py (reads PVs, follows changes), the folder tests with test_pvshow.py, which needs no EPICS network, and .venv, which is not in Git. The line pvshow = "pvshow.cli:main" in pyproject.toml makes pip write the script .venv/bin/pvshow, which calls main() in pvshow/cli.py.</desc>
<desc id="d">The finished project folder pvshow holds pyproject.toml (metadata and the command), README.md (requirements per install route), .gitignore, pvshow.spec (RPM, stage 4), Containerfile and .containerignore (container image, stage 5), the package folder pvshow with __init__.py, cli.py (main: options and output) and reader.py (reads PVs, follows changes), the folder tests, the folder .gitea/workflows with ci.yml (on push and pull request) and release.yml (on a version tag), stage 6, and .venv, which is not in Git. The line pvshow = "pvshow.cli:main" in pyproject.toml makes pip write the script .venv/bin/pvshow, which calls main() in pvshow/cli.py.</desc>
<style>
text { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; fill: #212121; }
.mono { font-family: "JetBrains Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
@@ -22,40 +22,50 @@
<marker id="ah" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M1 1l8 4-8 4z" fill="#4051b5"/></marker>
</defs>
<rect x="1" y="1" width="958" height="458" rx="10" fill="#ffffff" stroke="#e0e0e0" stroke-width="1.5"/>
<rect x="1" y="1" width="958" height="580" rx="10" fill="#ffffff" stroke="#e0e0e0" stroke-width="1.5"/>
<!-- left card: the tree -->
<g transform="translate(24 24)">
<rect class="card" width="520" height="412" rx="8"/>
<rect class="card" width="520" height="534" rx="8"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-folder" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="46" class="h">Project <tspan class="mono" style="fill:#212121">pvshow/</tspan></text>
<path d="M30 80v304M30 106h14M30 138h14M30 170h14M30 202h14M30 234h14M30 350h14M30 382h14M70 250v68M70 262h12M70 290h12M70 318h12" class="wire"/>
<use href="#i-file" class="icm" x="48" y="98" width="18" height="18"/><text x="74" y="112" class="mono code">pyproject.toml</text>
<text x="256" y="112" class="cap">metadata and the command</text>
<use href="#i-file" class="icm" x="48" y="130" width="18" height="18"/><text x="74" y="144" class="mono code">README.md</text>
<text x="256" y="144" class="cap">requirements per install route</text>
<use href="#i-file" class="icm" x="48" y="162" width="18" height="18"/><text x="74" y="176" class="mono code">.gitignore</text>
<text x="256" y="176" class="cap">keeps .venv/ and builds out of Git</text>
<use href="#i-file" class="icm" x="48" y="194" width="18" height="18"/><text x="74" y="208" class="mono code">pvshow.spec</text>
<text x="256" y="208" class="cap">RPM, if you choose one (stage 4)</text>
<use href="#i-folder" class="icm" x="48" y="226" width="18" height="18"/><text x="74" y="240" class="mono code">pvshow/</text>
<text x="256" y="240" class="cap">the package</text>
<use href="#i-file" class="icm" x="86" y="254" width="18" height="18"/><text x="112" y="268" class="mono code">__init__.py</text>
<text x="256" y="268" class="cap">makes pvshow a package</text>
<use href="#i-file" class="ic" x="86" y="282" width="18" height="18"/><text x="112" y="296" class="mono code" font-weight="600">cli.py</text>
<text x="256" y="296" class="t">main(): options and output</text>
<use href="#i-file" class="icm" x="86" y="310" width="18" height="18"/><text x="112" y="324" class="mono code">reader.py</text>
<text x="256" y="324" class="cap">reads PVs, follows changes</text>
<use href="#i-folder" class="icm" x="48" y="342" width="18" height="18"/><text x="74" y="356" class="mono code">tests/</text>
<text x="256" y="356" class="cap">test_pvshow.py, no EPICS needed</text>
<use href="#i-folder" class="icm" x="48" y="374" width="18" height="18"/><text x="74" y="388" class="mono code" style="fill:#757575">.venv/</text>
<text x="256" y="388" class="cap">virtual environment, not in Git</text>
<path d="M30 80v410M30 98h14M30 126h14M30 154h14M30 182h14M30 210h14M30 238h14M30 266h14M30 378h14M30 406h14M30 490h14M70 278v72M70 294h12M70 322h12M70 350h12M70 418v44M70 434h12M70 462h12" class="wire"/>
<use href="#i-file" class="icm" x="48" y="90" width="18" height="18"/><text x="74" y="104" class="mono code">pyproject.toml</text>
<text x="256" y="104" class="cap">metadata and the command</text>
<use href="#i-file" class="icm" x="48" y="118" width="18" height="18"/><text x="74" y="132" class="mono code">README.md</text>
<text x="256" y="132" class="cap">requirements per install route</text>
<use href="#i-file" class="icm" x="48" y="146" width="18" height="18"/><text x="74" y="160" class="mono code">.gitignore</text>
<text x="256" y="160" class="cap">keeps .venv/ and builds out of Git</text>
<use href="#i-file" class="icm" x="48" y="174" width="18" height="18"/><text x="74" y="188" class="mono code">pvshow.spec</text>
<text x="256" y="188" class="cap">RPM (stage 4)</text>
<use href="#i-file" class="icm" x="48" y="202" width="18" height="18"/><text x="74" y="216" class="mono code">Containerfile</text>
<text x="256" y="216" class="cap">container image (stage 5)</text>
<use href="#i-file" class="icm" x="48" y="230" width="18" height="18"/><text x="74" y="244" class="mono code">.containerignore</text>
<text x="256" y="244" class="cap">keeps files out of the image</text>
<use href="#i-folder" class="icm" x="48" y="258" width="18" height="18"/><text x="74" y="272" class="mono code">pvshow/</text>
<text x="256" y="272" class="cap">the package</text>
<use href="#i-file" class="icm" x="86" y="286" width="18" height="18"/><text x="112" y="300" class="mono code">__init__.py</text>
<text x="256" y="300" class="cap">makes pvshow a package</text>
<use href="#i-file" class="ic" x="86" y="314" width="18" height="18"/><text x="112" y="328" class="mono code" font-weight="600">cli.py</text>
<text x="256" y="328" class="t">main(): options and output</text>
<use href="#i-file" class="icm" x="86" y="342" width="18" height="18"/><text x="112" y="356" class="mono code">reader.py</text>
<text x="256" y="356" class="cap">reads PVs, follows changes</text>
<use href="#i-folder" class="icm" x="48" y="370" width="18" height="18"/><text x="74" y="384" class="mono code">tests/</text>
<text x="256" y="384" class="cap">test_pvshow.py, no EPICS needed</text>
<use href="#i-folder" class="icm" x="48" y="398" width="18" height="18"/><text x="74" y="412" class="mono code">.gitea/workflows/</text>
<text x="256" y="412" class="cap">Gitea Actions (stage 6)</text>
<use href="#i-file" class="icm" x="86" y="426" width="18" height="18"/><text x="112" y="440" class="mono code">ci.yml</text>
<text x="256" y="440" class="cap">on push and pull request</text>
<use href="#i-file" class="icm" x="86" y="454" width="18" height="18"/><text x="112" y="468" class="mono code">release.yml</text>
<text x="256" y="468" class="cap">on a version tag</text>
<use href="#i-folder" class="icm" x="48" y="482" width="18" height="18"/><text x="74" y="496" class="mono code" style="fill:#757575">.venv/</text>
<text x="256" y="496" class="cap">virtual environment, not in Git</text>
</g>
<!-- right card: entry point mechanism -->
<g transform="translate(568 24)">
<rect width="368" height="412" rx="8" fill="#f7f8fc" stroke="#4051b5" stroke-width="2"/>
<rect width="368" height="534" rx="8" fill="#f7f8fc" stroke="#4051b5" stroke-width="2"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-link" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="38" class="h">How the command</text>
<text x="74" y="60" class="h">finds your code</text>

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

@@ -1,102 +1,92 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 470" role="img" aria-labelledby="t d">
<title id="t">The four stages of the pvshow tool</title>
<desc id="d">Stage 1, one script: read_pv.py reads one PV, run with python3 read_pv.py PV in a venv. Stage 2, a package with a command: pyproject.toml and pvshow/cli.py, installed with pip install -e ., run as pvshow PV with a timeout and exit codes. Stage 3, a tool you can rely on: several PVs, --json, --follow, log messages on stderr, and unit tests in tests/ that run with python -m unittest without an EPICS network. Stage 4, ready to hand over: version 1.0.0 with a tag, python -m build for a wheel and a source archive, and pvshow.spec for an RPM. How you package it is your choice; it reaches Controls hosts with autodeploy.</desc>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 456" role="img" aria-labelledby="t d">
<title id="t">The six stages of the pvshow tool</title>
<desc id="d">Stage 1, one script: read_pv.py, run with python3 read_pv.py. Stage 2, a package with a command: pyproject.toml and pvshow/cli.py, installed with pip install -e . and run as pvshow. Stages 1 and 2 are the base. Optional stages: 3, a tool you can rely on, with reader.py, tests, JSON, follow mode and logs, checked with python -m unittest; 4, ready to hand over, with a version and tag, wheel, sdist and an RPM spec, built with python -m build; 5, a container image from a Containerfile, built and pushed with podman; 6, Gitea Actions with ci.yml on every push and release.yml on a version tag. Take only the optional stages you need. The tool reaches Controls hosts with autodeploy.</desc>
<style>
text { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; fill: #212121; }
.mono { font-family: "JetBrains Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.h { font-size: 18px; font-weight: 600; }
.h { font-size: 17px; font-weight: 600; }
.t { font-size: 15px; }
.cap { font-size: 15px; fill: #5f6368; }
.code { font-size: 14px; fill: #303fa1; }
.card { fill: #f7f8fc; stroke: #e1e4f2; stroke-width: 1.5; }
.tile { fill: #e8eaf6; }
.ic { fill: none; stroke: #4051b5; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icm { fill: none; stroke: #757575; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wire { fill: none; stroke: #9fa8da; stroke-width: 2; }
.opt { fill: #ffffff; stroke: #9fa8da; stroke-width: 1.5; stroke-dasharray: 6 5; }
.track { fill: none; stroke: #4051b5; stroke-width: 2.5; }
.num { font-size: 15px; font-weight: 700; fill: #fff; }
.pill { fill: #e8eaf6; }
.pilltext { font-size: 12px; font-weight: 600; fill: #303fa1; }
</style>
<defs>
<symbol id="i-file" viewBox="0 0 24 24"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></symbol>
<symbol id="i-box" viewBox="0 0 24 24"><path d="M12 3l8 4.5v9L12 21l-8-4.5v-9z"/><path d="M4 7.5l8 4.5 8-4.5M12 12v9"/></symbol>
<symbol id="i-check" viewBox="0 0 24 24"><path d="M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6z"/><path d="M8.5 12l2.5 2.5 4.5-5"/></symbol>
<symbol id="i-pkg" viewBox="0 0 24 24"><rect x="3" y="7" width="18" height="13" rx="2"/><path d="M3 11h18M9 4h6l2 3H7z"/></symbol>
<marker id="ah" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M1 1l8 4-8 4z" fill="#4051b5"/></marker>
</defs>
<rect x="1" y="1" width="958" height="468" rx="10" fill="#ffffff" stroke="#e0e0e0" stroke-width="1.5"/>
<rect x="1" y="1" width="958" height="454" rx="10" fill="#ffffff" stroke="#e0e0e0" stroke-width="1.5"/>
<!-- track on top -->
<path class="track" d="M143 44h204" marker-end="url(#ah)"/><path class="track" d="M377 44h204" marker-end="url(#ah)"/><path class="track" d="M611 44h204" marker-end="url(#ah)"/>
<g font-size="15" font-weight="700" text-anchor="middle">
<circle cx="129" cy="44" r="14" fill="#4051b5"/><text x="129" y="49.5" style="fill:#fff">1</text>
<circle cx="363" cy="44" r="14" fill="#4051b5"/><text x="363" y="49.5" style="fill:#fff">2</text>
<circle cx="597" cy="44" r="14" fill="#4051b5"/><text x="597" y="49.5" style="fill:#fff">3</text>
<circle cx="831" cy="44" r="14" fill="#4051b5"/><text x="831" y="49.5" style="fill:#fff">4</text>
<!-- connectors -->
<path class="track" d="M310 99h22" marker-end="url(#ah)"/>
<path class="track" d="M624 99h22" marker-end="url(#ah)"/>
<path class="track" d="M794 176v14H166v16" marker-end="url(#ah)"/>
<path class="track" d="M310 289h22" marker-end="url(#ah)"/>
<path class="track" d="M624 289h22" marker-end="url(#ah)"/>
<!-- 1 -->
<g transform="translate(24 24)">
<rect class="card" width="284" height="150" rx="8"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">1</text>
<text x="54" y="36" class="h">One script</text>
<text x="18" y="76" class="mono code">read_pv.py</text>
<text x="18" y="102" class="t">reads one PV and prints it</text>
<text x="18" y="132" class="mono code">python3 read_pv.py &lt;PV&gt;</text>
</g>
<path class="wire" d="M129 58v16M363 58v16M597 58v16M831 58v16" stroke-dasharray="3 4"/>
<!-- card 1 -->
<g transform="translate(24 76)">
<rect class="card" width="210" height="300" rx="8"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-file" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="38" class="h">One</text>
<text x="74" y="60" class="h">script</text>
<text x="18" y="100" class="mono code">read_pv.py</text>
<text x="18" y="130" class="t">reads one PV</text>
<text x="18" y="150" class="t">and prints it</text>
<path d="M18 236h174" stroke="#e1e4f2" stroke-width="1.5"/>
<text x="18" y="262" class="mono code">python3 read_pv.py</text>
<text x="18" y="282" class="mono code"> &lt;PV&gt;</text>
<!-- 2 -->
<g transform="translate(338 24)">
<rect width="284" height="150" rx="8" fill="#f7f8fc" stroke="#4051b5" stroke-width="2"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">2</text>
<text x="54" y="36" class="h">Package with a command</text>
<text x="18" y="76" class="mono code">pyproject.toml pvshow/cli.py</text>
<text x="18" y="102" class="t">options, timeout, exit codes</text>
<text x="18" y="132" class="mono code">pip install -e .</text>
</g>
<!-- 3 -->
<g transform="translate(652 24)">
<rect class="opt" width="284" height="150" rx="8"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">3</text>
<text x="54" y="36" class="h">A tool you can rely on</text>
<text x="18" y="76" class="mono code">reader.py tests/</text>
<text x="18" y="102" class="t">JSON, follow mode, logs</text>
<text x="18" y="132" class="mono code">python -m unittest</text>
<rect class="pill" x="200" y="112" width="70" height="24" rx="12"/><text x="235" y="128.5" text-anchor="middle" class="pilltext">optional</text>
</g>
<!-- 4 -->
<g transform="translate(24 214)">
<rect class="opt" width="284" height="150" rx="8"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">4</text>
<text x="54" y="36" class="h">Ready to hand over</text>
<text x="18" y="76" class="t">version and tag <tspan class="mono code">1.0.0</tspan></text>
<text x="18" y="102" class="t">wheel, sdist, RPM spec</text>
<text x="18" y="132" class="mono code">python -m build</text>
<rect class="pill" x="200" y="112" width="70" height="24" rx="12"/><text x="235" y="128.5" text-anchor="middle" class="pilltext">optional</text>
</g>
<!-- 5 -->
<g transform="translate(338 214)">
<rect class="opt" width="284" height="150" rx="8"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">5</text>
<text x="54" y="36" class="h">A container image</text>
<text x="18" y="76" class="mono code">Containerfile</text>
<text x="18" y="102" class="t">pushed to gitea.psi.ch</text>
<text x="18" y="132" class="mono code">podman build</text>
<rect class="pill" x="200" y="112" width="70" height="24" rx="12"/><text x="235" y="128.5" text-anchor="middle" class="pilltext">optional</text>
</g>
<!-- 6 -->
<g transform="translate(652 214)">
<rect class="opt" width="284" height="150" rx="8"/>
<circle cx="30" cy="30" r="14" fill="#4051b5"/><text x="30" y="35.5" text-anchor="middle" class="num">6</text>
<text x="54" y="36" class="h">Automatic builds</text>
<text x="18" y="76" class="mono code">ci.yml release.yml</text>
<text x="18" y="102" class="t">tests on push, release on tag</text>
<text x="18" y="132" class="mono code">.gitea/workflows/</text>
<rect class="pill" x="200" y="112" width="70" height="24" rx="12"/><text x="235" y="128.5" text-anchor="middle" class="pilltext">optional</text>
</g>
<!-- card 2 -->
<g transform="translate(258 76)">
<rect class="card" width="210" height="300" rx="8"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-box" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="38" class="h">A package with</text>
<text x="74" y="60" class="h">a command</text>
<text x="18" y="100" class="mono code">pyproject.toml</text>
<text x="18" y="122" class="mono code">pvshow/cli.py</text>
<text x="18" y="152" class="t">timeout, exit codes,</text>
<text x="18" y="172" class="t">--help</text>
<path d="M18 236h174" stroke="#e1e4f2" stroke-width="1.5"/>
<text x="18" y="262" class="mono code">pip install -e .</text>
<text x="18" y="284" class="mono code">pvshow &lt;PV&gt;</text>
</g>
<!-- card 3 -->
<g transform="translate(492 76)">
<rect class="card" width="210" height="300" rx="8"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-check" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="38" class="h">A tool you</text>
<text x="74" y="60" class="h">can rely on</text>
<text x="18" y="100" class="mono code">pvshow/reader.py</text>
<text x="18" y="122" class="mono code">tests/</text>
<text x="18" y="152" class="t">several PVs, JSON,</text>
<text x="18" y="172" class="t">follow mode, logs</text>
<text x="18" y="192" class="t">on stderr</text>
<path d="M18 236h174" stroke="#e1e4f2" stroke-width="1.5"/>
<text x="18" y="262" class="mono code">python -m unittest</text>
<text x="18" y="284" class="cap">no EPICS network needed</text>
</g>
<!-- card 4 -->
<g transform="translate(726 76)">
<rect width="210" height="300" rx="8" fill="#f7f8fc" stroke="#4051b5" stroke-width="2"/>
<rect class="tile" x="18" y="18" width="44" height="44" rx="8"/><use href="#i-pkg" class="ic" x="28" y="28" width="24" height="24"/>
<text x="74" y="38" class="h">Ready to</text>
<text x="74" y="60" class="h">hand over</text>
<text x="18" y="100" class="t">version and tag</text>
<text x="18" y="122" class="mono code">1.0.0</text>
<text x="18" y="152" class="t">wheel and source</text>
<text x="18" y="172" class="t">archive, or an RPM</text>
<text x="18" y="194" class="mono code">pvshow.spec</text>
<path d="M18 236h174" stroke="#e1e4f2" stroke-width="1.5"/>
<text x="18" y="262" class="mono code">python -m build</text>
<text x="18" y="284" class="mono code">rpmbuild -bb</text>
</g>
<!-- footer -->
<text x="480" y="420" text-anchor="middle" class="cap">Each stage runs. How you package the tool is your choice;</text>
<text x="480" y="442" text-anchor="middle" class="cap">it reaches Controls hosts with autodeploy.</text>
<text x="480" y="404" text-anchor="middle" class="cap">Stages 1 and 2 are the base. Take only the optional stages your tool needs.</text>
<text x="480" y="428" text-anchor="middle" class="cap">The tool reaches Controls hosts with autodeploy.</text>
</svg>

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB