Skip to content

Add pyproject.toml and require Python 3.12 for local dev - #717

Open
Odilhao wants to merge 3 commits into
theforeman:masterfrom
Odilhao:add-pyproject-toml
Open

Add pyproject.toml and require Python 3.12 for local dev#717
Odilhao wants to merge 3 commits into
theforeman:masterfrom
Odilhao:add-pyproject-toml

Conversation

@Odilhao

@Odilhao Odilhao commented Jul 31, 2026

Copy link
Copy Markdown
Member

Why are you introducing these changes? (Problem description, related links)

./setup-environment fails on CentOS Stream 9/RHEL 9/UBI9 because their default Python is 3.9, and development/requirements.txt pins pytest>=9.0, which dropped Python 3.9 support (requires 3.10+). Downgrading the pytest pin would just be papering over a version mismatch: downstream packaging already targets Python 3.12 (python-obsah builds against python3.12, foremanctl.spec requires python3.12-obsah) and CI already sets up Python 3.12 for every job. EL9's default 3.9 was never actually a supported target for this project, and EL10 ships 3.12 by default anyway.

What are the changes introduced in this pull request?

  • Add pyproject.toml declaring requires-python = ">=3.12" plus project metadata and dependencies. This is metadata-only (foremanctl/forge stay as bash wrappers, no console-script entry points, no bundling of src//development/ as package data). Version is resolved via setuptools_scm from git describe, mirroring what VERSION/export-subst does for release tarballs but working correctly from a plain checkout too (a custom tag_regex handles this repo's non-PEP-440 tags like 3.0.0-develop). The build backend (setuptools) is left unpinned so it uses whatever version already ships with the running system rather than one pip would fetch from PyPI.
  • setup-environment now checks for python3.12 explicitly (instead of relying on whatever python resolves to on PATH) and fails fast with a clear, actionable error if it's missing.
  • src/requirements.txt / development/requirements.txt are left unchanged for now — this is a first step, not a full migration.
  • DEVELOPMENT.md now lists Python - 3.12+ under Requirements.

How to test this pull request

Steps to reproduce:

  • On a machine/container without python3.12 on PATH (e.g. plain quay.io/centos/centos:stream9), run ./setup-environment and confirm it fails fast with Error: python3.12 is required ... instead of pip's confusing "no matching distribution" error.
  • Install python3.12/python3.12-devel (CS9) or just use CS10 (ships python3.12 as default python3), run ./setup-environment, and confirm .venv/bin/python --version reports 3.12 and pytest>=9.0 installs successfully.
  • In that venv, run pip install --upgrade setuptools setuptools_scm && pip install --no-build-isolation -e '.[dev]' and confirm it builds using the system's own setuptools (check pip show setuptools matches the OS package version) and resolves a valid version via pip show foremanctl.

This was verified end-to-end with podman run on both quay.io/centos/centos:stream9 and :stream10.

Checklist

  • Tests added/updated (if applicable) — verified manually via podman on CS9/CS10; no automated test suite covers setup-environment itself.
  • Documentation updated (if applicable) — DEVELOPMENT.md

setup-environment failed on CentOS Stream 9/RHEL 9/UBI9 because their
default Python is 3.9, and pytest>=9.0 dropped 3.9 support. Downstream
packaging already targets Python 3.12 (python-obsah builds against it,
foremanctl.spec requires python3.12-obsah) and CI already sets up 3.12,
so align local dev tooling with that instead of downgrading pytest.

pyproject.toml declares requires-python>=3.12 plus project metadata and
dependencies (metadata-only package, no console-script entry points),
using setuptools_scm for the version so it mirrors what VERSION/
export-subst does for release tarballs. setup-environment now enforces
python3.12 explicitly instead of relying on whatever "python" resolves
to on PATH.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread setup-environment Outdated

set -eou pipefail

REQUIRED_PYTHON=python3.12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup-environment now checks for python3.12 explicitly (instead of relying on whatever python resolves to on PATH) and fails fast with a clear, actionable error if it's missing.
src/requirements.txt / development/requirements.txt are left unchanged for now — this is a first step, not a full migration.
DEVELOPMENT.md now lists Python - 3.12+ under Requirements.

So which is it? 3.12+ or 3.12 exactly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to one dynamic resolution that will failed if it's not 3.12+, when I tried to run on CS9 with only python3.9 it failed, and later worked with 3.12.

Odilhao and others added 2 commits July 31, 2026 15:01
setup-environment checks command -v python3.12, which only matches a
binary literally named python3.12 -- it would never pick up a
hypothetical python3.13. requires-python (">=3.12") and DEVELOPMENT.md
("3.12+") implied a floor instead of an exact pin, which was
inconsistent with what the script actually enforces and with
downstream packaging (python-obsah.spec pins python3.12 specifically).

Reported in review: theforeman#717 (comment)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
command -v python3.12 only ever matches a binary literally named
python3.12 -- it would never pick up python3.13+ even though
pyproject.toml's requires-python (">=3.12") and DEVELOPMENT.md ("3.12+")
both say any 3.12-or-newer interpreter is fine. Search python3.12 (the
name EL9 ships it under, unaliased) then fall back to python3, checking
each candidate's actual version instead of just its name, so this keeps
working as newer Pythons become the default (e.g. future EL releases).

Verified via podman on CentOS Stream 9 (python3.12 package installed),
CentOS Stream 10 (python3 already 3.12), and CS9 with only the default
python3 (3.9) present, which still correctly fails with a clear error.

Reported in review: theforeman#717 (comment)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@ekohl ekohl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./setup-environment fails on CentOS Stream 9/RHEL 9/UBI9 because their default Python is 3.9, and development/requirements.txt pins pytest>=9.0, which dropped Python 3.9 support (requires 3.10+).

I'm sorry for adding that. I didn't realize it when I bumped it for the subtests feature.

I don't like duplicating the dependencies in 2 places. IMHO that needs to be solved.

Comment thread pyproject.toml
[project]
name = "foremanctl"
description = "Deployment tool for Foreman and Katello using Podman quadlets and Ansible"
requires-python = ">=3.12"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime wise I think this is lower. It's just for testing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants