Skip to content

feat: update Python version handling and refactor base images retrieval#60

Merged
vstirbu merged 5 commits intomainfrom
45-python-version-in-images
Jan 19, 2026
Merged

feat: update Python version handling and refactor base images retrieval#60
vstirbu merged 5 commits intomainfrom
45-python-version-in-images

Conversation

@vstirbu
Copy link
Contributor

@vstirbu vstirbu commented Dec 15, 2025

No description provided.

@vstirbu vstirbu linked an issue Dec 15, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/q8s/workload.py 89.47% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vstirbu vstirbu marked this pull request as ready for review January 19, 2026 10:46
@vstirbu vstirbu requested a review from Copilot January 19, 2026 10:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for configurable Python versions in Docker base images and refactors the project layout detection logic. The main purpose is to enable users to specify which Python version their project should use when building containers.

Changes:

  • Introduced a python_version field to Q8SPythonEnv dataclass with a default of "3.12"
  • Refactored base image definitions from constants to a dynamic function get_base_images() that interpolates Python versions
  • Added src-layout detection support for both config.cfg and pyproject.toml configuration files
  • Extracted shared test utility function write() into tests/utils.py for reuse across test files

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/utils.py New shared test utility file containing the write() helper function for creating test files
tests/test_workload.py New test suite for validating src-layout detection from configuration files
tests/test_multifiles.py Refactored to use shared write() utility instead of local implementation
src/q8s/workload.py Extended to detect src-layout from both config.cfg and pyproject.toml files
src/q8s/project.py Updated to use dynamic base images with configurable Python version
src/q8s/constants.py Converted BASE_IMAGES from constant to function supporting Python version parameter
pyproject.toml Version bumped to 0.12.0-dev1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +6
def get_base_images(python_version: str = "3.12") -> dict[str, str]:
return {
"cpu": f"python:{python_version}-slim",
"gpu": f"ghcr.io/qubernetes-dev/cuda:12.8.1-r2-py{python_version}",
"qpu": f"python:{python_version}-slim",
}
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The python_version parameter in get_base_images lacks input validation. Consider adding validation to ensure the version string is in the expected format (e.g., "3.12", "3.11") to prevent invalid Docker image tags from being generated.

Copilot uses AI. Check for mistakes.
if where == "src":
self.__pyproject_root = root
return True
cfg_path = root / "config.cfg"
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The filename should be "setup.cfg" not "config.cfg". The test in test_workload.py expects "config.cfg", but standard Python packaging uses "setup.cfg". This appears to be a bug - either the code should look for "setup.cfg" or the test should be updated to reflect a non-standard configuration filename.

Suggested change
cfg_path = root / "config.cfg"
cfg_path = root / "setup.cfg"

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +178
pyproject_path = root / "pyproject.toml"
if pyproject_path.exists():
config = configparser.ConfigParser()
config.read(pyproject_path)

if config.has_section("tool.setuptools.packages.find"):
where = config.get(
"tool.setuptools.packages.find", "where", fallback=""
).strip()
if where == '["src"]':
self.__pyproject_root = root
return True
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Using ConfigParser to parse TOML files is incorrect. TOML and INI formats are different and ConfigParser cannot properly parse TOML syntax. For example, TOML list syntax like ["src"] will be read as a literal string '["src"]' rather than being parsed as a list. You should use a TOML parser library like tomli or tomllib (built-in for Python 3.11+) instead.

Copilot uses AI. Check for mistakes.
where = config.get(
"tool.setuptools.packages.find", "where", fallback=""
).strip()
if where == '["src"]':
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Comparing the parsed value to the literal string '["src"]' indicates that ConfigParser is being used incorrectly for TOML parsing. In proper TOML parsing, the value would be a Python list, not a string. This string comparison will only work by accident because ConfigParser treats TOML as INI format and returns the raw value as a string.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +14
# BASE_IMAGES = {
# "cpu": "python:3.12-slim",
# "gpu": "ghcr.io/qubernetes-dev/cuda:12.8.1",
# "qpu": "python:3.12-slim",
# }
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Commented-out code should be removed rather than left in the codebase. If the old BASE_IMAGES definition is no longer needed, it should be deleted. If it's kept for reference, consider adding a clear comment explaining why it's preserved.

Suggested change
# BASE_IMAGES = {
# "cpu": "python:3.12-slim",
# "gpu": "ghcr.io/qubernetes-dev/cuda:12.8.1",
# "qpu": "python:3.12-slim",
# }

Copilot uses AI. Check for mistakes.
@dataclass
class Q8SPythonEnv:
dependencies: List[str]
python_version: str = "3.12"
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The new python_version parameter in Q8SPythonEnv and its usage in get_base_images lacks test coverage. Consider adding tests that verify different Python versions generate the correct base image strings, particularly for the GPU image where the version is interpolated into the image tag.

Copilot uses AI. Check for mistakes.
@vstirbu vstirbu merged commit 03b36ad into main Jan 19, 2026
9 checks passed
@vstirbu vstirbu deleted the 45-python-version-in-images branch January 19, 2026 11:49
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.

Python version in images

2 participants