-
Notifications
You must be signed in to change notification settings - Fork 0
Add versions command to extract supported Python versions from pyproject.toml #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ect.toml Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
|
|
@HarryCampion We can remove the .rhiza/utils folder by just calling this command |
There was a problem hiding this 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 PR implements a rhiza versions command to extract supported Python versions from pyproject.toml and output them as JSON, primarily for CI/CD test matrix generation. The command parses the requires-python field, evaluates candidate versions (3.11-3.14) against version specifiers, and outputs matching versions.
Changes:
- Adds
versionscommand implementation with version parsing and constraint checking logic - Integrates command into CLI with support for directory or file path arguments
- Provides comprehensive test coverage for parsing, validation, and CLI integration
- Documents command usage with GitHub Actions integration example
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/rhiza/commands/versions.py | Core implementation with version parsing, constraint checking, and JSON output generation |
| src/rhiza/cli.py | CLI integration adding versions subcommand with path argument support |
| tests/test_commands/test_versions.py | Comprehensive test suite covering parsing, validation, command behavior, and CLI integration |
| CLI.md | Documentation with usage examples and GitHub Actions integration pattern |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…arify comments - Add tests for missing operators (<=, >, ==, !=) - Add test for malformed TOML handling - Export versions command in __init__.py - Update module docstring to document versions command - Add clarifying comments for custom exceptions and CANDIDATES list Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Clarify parse_version docstring example for better understanding - Add security note and version pinning to GitHub Actions example in CLI.md Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Use ValueError and RuntimeError instead of custom VersionSpecifierError and PyProjectError classes to match exception handling patterns used in other commands (init.py, materialize.py). Also export versions command in __init__.py. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test cases for <=, >, ==, and != operators which were documented but not tested. Also add test for malformed TOML syntax to verify tomllib.TOMLDecodeError is raised appropriately. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add type annotation to operators dict to fix mypy error - Add match parameter to pytest.raises for more specific assertions - Remove unnecessary noqa comments (auto-cleaned by ruff) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Cover implicit equality specifiers and exception handlers in the versions function that were previously untested. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use match parameter in pytest.raises() instead of separate assertion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@HarryCampion I guess this should better be in rhiza-tools? |
Original prompt
This section details on the original issue you should resolve
<issue_title>I want a versions command</issue_title>
<issue_description>The version command should extract the feasible version from a script like the one below.
The pyproject file should either be in the local path right now, if called from this path or specified as an argument
#!/usr/bin/env python3
"""Emit the list of supported Python versions from pyproject.toml.
This helper is used in GitHub Actions to compute the test matrix.
"""
import json
import re
import tomllib
from pathlib import Path
PYPROJECT = Path(file).resolve().parents[2] / "pyproject.toml"
CANDIDATES = ["3.11", "3.12", "3.13", "3.14"] # extend as needed
class RhizaError(Exception):
"""Base exception for Rhiza-related errors."""
class VersionSpecifierError(RhizaError):
"""Raised when a version string or specifier is invalid."""
class PyProjectError(RhizaError):
"""Raised when there are issues with pyproject.toml configuration."""
def parse_version(v: str) -> tuple[int, ...]:
"""Parse a version string into a tuple of integers.
def _check_operator(version_tuple: tuple[int, ...], op: str, spec_v_tuple: tuple[int, ...]) -> bool:
"""Check if a version tuple satisfies an operator constraint."""
operators = {
">=": lambda v, s: v >= s,
"<=": lambda v, s: v <= s,
">": lambda v, s: v > s,
"<": lambda v, s: v < s,
"==": lambda v, s: v == s,
"!=": lambda v, s: v != s,
}
return operators[op](version_tuple, spec_v_tuple)
def satisfies(version: str, specifier: str) -> bool:
"""Check if a version satisfies a comma-separated list of specifiers.
def supported_versions() -> list[str]:
"""Return all supported Python versions declared in pyproject.toml.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.