Skip to content

python2-to-3: port python to python3; auto-install a python3 gitdm for git-stats#1125

Closed
bhouse-nexthop wants to merge 3 commits into
opencomputeproject:onie-modernization-2026from
bhouse-nexthop:bhouse.python3-port
Closed

python2-to-3: port python to python3; auto-install a python3 gitdm for git-stats#1125
bhouse-nexthop wants to merge 3 commits into
opencomputeproject:onie-modernization-2026from
bhouse-nexthop:bhouse.python3-port

Conversation

@bhouse-nexthop

Copy link
Copy Markdown

Rebased onto onie-modernization-2026 (replaces #1116, which targeted master and stacked on the SBOM work; the SBOM content is not included here).

What this does

1. Port all python from python2 to python3

python2-to-3: port all python from python2 to python3 — ports the remaining python2 code (build-config Makefile/scripts, contrib/oce, contrib/onie-server, machine DUT test helpers) to python3. $(PYTHON) now defaults to python3. All ported files compile under python3.

2. git-stats: drop the vendored python2 gitdm, auto-install a python3 gitdm

The contrib/git-stats tooling vendored a full copy of gitdm (from git.lwn.net), which is python2 and effectively unmaintained. Per maintainer request, rather than port/maintain a copy in-tree:

  • Removed the vendored contrib/git-stats/gitdm/ engine.
  • Kept the ONIE-specific onie-git-stats wrapper, the gitdm-config/ maps, and the README.
  • onie-git-stats now auto-installs a python3 gitdm on demand: on first run it clones a pinned python3 port (OSSystems/gitdm, a straight python3 port of Corbet's gitdm) into a git-ignored cache (contrib/git-stats/.gitdm) and reuses it thereafter. So onie-git-stats runs as-is with only git + python3 present.
  • Source/revision are pinned and overridable via GITDM_REPO / GITDM_REF.
  • A user who already has a python3 gitdm can set GITDM to point at it; the wrapper then uses it directly and skips the clone entirely.
  • gitdm is now invoked with python3 (was python), and the pinned upstream's harmless SyntaxWarnings are silenced.
  • README.md documents the auto-install, the pinning/override knobs, and the pre-existing-gitdm path.

Testing

  • onie-git-stats <range> <prefix> exercised end-to-end: fresh auto-clone → python3 gitdm → valid results.txt/.html.
  • Verified the GITDM override skips the clone.
  • python3 -m py_compile passes on all ported .py files.

ONIE still shipped python2-only code throughout the tree.  Port every
python asset to python3 so the build no longer needs a python2
interpreter (a prerequisite for moving to a modern Debian build host)
and so nothing in contrib/ or the machine tests is left on a dead
runtime.  This change deliberately does NOT touch the CI Dockerfile, so
the cross-toolchain cache key is preserved (the Debian-13 build-host
bump is deferred to the toolchain-upgrade step, where it must land
alongside crosstool-NG/GCC -- the current GCC 8.3.0 toolchain cannot be
built on a GCC 14 host).

Build path:
  - build-config/scripts/mk-part-table.py (the only python invoked by
    the image build -- it writes the recovery ISO MBR partition table):
    env python3 shebang, integer division (/ -> //) so CHS values stay
    ints, and the ISO opened in binary mode ('r+b') so struct.pack()
    bytes are written correctly.  A shebang-only change is insufficient;
    without the // and binary fixes the script silently writes a wrong
    partition table under python3.  Verified to emit a correct MBR
    (0xaa55 signature, 0x80 boot flag, 0xEF EFI type) on a test image.
  - build-config/Makefile: retarget $(PYTHON) from python2 to python3.
    grub's autogen.sh invokes "${PYTHON:-python}", and a bare "python"
    no longer exists once python2 is gone, so the build must export
    PYTHON=python3 (grub's gentpl.py/import_gcry.py are python3-safe).
    The old block only set PYTHON=python2 when "python" was absent;
    replace it with an exported `PYTHON ?= python3`.  Also switch
    DEBIAN_BUILD_HOST_PACKAGES from python-all-dev/python-sphinx to
    python3-all-dev/python3-sphinx.

Tooling and tests (mechanical 2to3, behaviour preserved):
  - contrib/oce, contrib/onie-server, contrib/git-stats/gitdm (vendored),
    and the machine/*/test DUT scripts: python3 shebangs; print()
    functions; `except E, e` -> `except E as e`; iteritems/iterkeys/
    itervalues -> items/keys/values; has_key -> `in`; raw_input -> input;
    cStringIO/StringIO -> io; py2 stdlib renames (Queue->queue,
    SimpleHTTPServer/SocketServer->http.server/socketserver, thread->
    _thread); sort(cmp=...) -> key=cmp_to_key(...); list() wrapping of
    views/maps that are indexed or sorted; onie-server.py spawns its
    helpers with "python3" instead of "python".
  - contrib/onie-server/proxy-server.py was cp1252-encoded; re-encode it
    as UTF-8 and update the coding declaration so its (Portuguese)
    comments survive the python3 port intact.

Every python file in the tree now passes `python3 -m py_compile`, all
shebang scripts use `#!/usr/bin/env python3`, and no python2-only syntax
remains.

Signed-off-by: Brad House <bhouse@nexthop.ai>
…n3 gitdm

The git-stats tooling vendored a full copy of gitdm (git.lwn.net) under
contrib/git-stats/gitdm.  That copy is python2 and effectively
unmaintained, so it does not survive the python2-to-3 port.

Rather than carry (and port/maintain) a copy of gitdm in this tree,
remove the vendored gitdm and have onie-git-stats obtain a python3 port
of gitdm on demand:

  - On first run, onie-git-stats clones a pinned python3 gitdm
    (OSSystems/gitdm, which is a straight python3 port of Corbet's
    gitdm) into a local, git-ignored cache directory
    (contrib/git-stats/.gitdm) and reuses it thereafter.  The source and
    revision are pinned and overridable via GITDM_REPO / GITDM_REF.

  - A user who already has a python3-capable gitdm can set GITDM to point
    at it; onie-git-stats then uses it directly and skips the clone
    entirely.

  - gitdm is now invoked with python3 (was python2), and the pinned
    upstream's harmless SyntaxWarnings are silenced.

The ONIE-specific gitdm configuration (gitdm-config/) and the
onie-git-stats wrapper are kept; only the vendored gitdm engine is
removed.  README.md documents the auto-install, the pinning/override
knobs, and how to use a pre-existing gitdm.

Signed-off-by: Brad House <bhouse@nexthop.ai>
Add a path-scoped GitHub Action that exercises onie-git-stats end-to-end
so the git-stats change can be trusted without manual testing:

  - Auto-install path: run onie-git-stats with no $GITDM set, asserting it
    clones the pinned python3 gitdm and produces a non-empty report.

  - Override path: run again with $GITDM pointing at a pre-existing gitdm,
    asserting the auto-install cache is NOT re-created and a report is
    still produced.

Triggers only when contrib/git-stats (or this workflow) changes, since
nothing else affects the result.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@bhouse-nexthop

Copy link
Copy Markdown
Author

Added a small, path-scoped CI check (ci: validate contrib/git-stats gitdm tooling) so this doesn't rely on manual testing: it runs onie-git-stats end-to-end and asserts a report is actually generated, covering both the auto-install path (clones the pinned python3 gitdm) and the GITDM override path (uses a pre-existing gitdm, skips the clone). It only triggers when contrib/git-stats/** (or the workflow itself) changes.

bhouse-nexthop added a commit to bhouse-nexthop/onie that referenced this pull request Jul 9, 2026
Squashed baseline of PR opencomputeproject#1125, on which this PR is stacked. Drops out once PR opencomputeproject#1125 merges into onie-modernization-2026.

Signed-off-by: Brad House <bhouse@nexthop.ai>
bhouse-nexthop added a commit to bhouse-nexthop/onie that referenced this pull request Jul 9, 2026
…3 gitdm)

Squashed content of PR opencomputeproject#1125, pulled in as a dependency for the toolchain milestone.

Signed-off-by: Brad House <bhouse@nexthop.ai>
bhouse-nexthop added a commit to bhouse-nexthop/onie that referenced this pull request Jul 10, 2026
…3 gitdm)

Squashed content of PR opencomputeproject#1125, pulled in as a dependency for the toolchain milestone.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@mshych

mshych commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Thank you, pushed to onie-modernization-2026 branch.

@mshych mshych closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants