check_python_version¶
rhiza_hooks.check_python_version
¶
Check that Python version is consistent across project files.
check_version_consistency(repo_root)
¶
Check Python version consistency across project files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if consistent) |
Source code in rhiza_hooks/check_python_version.py
get_pyproject_requires_python(repo_root)
¶
Read requires-python constraint(s) from pyproject.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]] | None
|
List of (operator, version) clauses, or None if not specified or |
list[tuple[str, str]] | None
|
unparseable. A compound specifier yields one entry per comma-separated |
list[tuple[str, str]] | None
|
clause, e.g. ">=3.11,<3.14" -> [(">=", "3.11"), ("<", "3.14")]. |
Source code in rhiza_hooks/check_python_version.py
get_python_version_file(repo_root)
¶
Read Python version from .python-version file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Python version string or None if file doesn't exist |
Source code in rhiza_hooks/check_python_version.py
main(argv=None)
¶
Main entry point for the hook.
Source code in rhiza_hooks/check_python_version.py
parse_version(version_str)
¶
Parse a version string into a tuple of (major, minor).
This is deliberately not :func:rhiza_hooks._version.parse_version, which the
Rust and Go hooks share. That one is lenient: it accepts any number of
components, reads the leading digits of "1.21rc1", and returns None for
text with no version in it. This one has a narrower contract: the comparators
in _COMPARATORS are typed on tuple[int, int] and compare exactly
major.minor, the granularity requires-python is checked at, so it
returns a pair and raises on anything else rather than returning a sentinel
that every comparison would need to handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_str
|
str
|
Version string like "3.11" or "3.12" |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (major, minor) integers |
parse_version("3.11") (3, 11) parse_version("3.12") (3, 12)
Source code in rhiza_hooks/check_python_version.py
version_satisfies_constraint(version, operator, constraint_version)
¶
Check if a version satisfies a constraint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
The version to check (e.g., "3.12") |
required |
operator
|
str
|
The comparison operator (e.g., ">=", "==") |
required |
constraint_version
|
str
|
The version in the constraint (e.g., "3.11") |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version satisfies the constraint |
version_satisfies_constraint("3.12", ">=", "3.11") True version_satisfies_constraint("3.10", ">=", "3.11") False
~= additionally pins the major component:
version_satisfies_constraint("3.12", "~=", "3.11") True version_satisfies_constraint("4.0", "~=", "3.11") False
An operator this hook does not model is treated permissively rather than as a violation — the hook reports disagreements it is sure about, not everything it cannot parse:
version_satisfies_constraint("3.10", "<>", "3.11") True