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 src/rhiza_hooks/check_python_version.py
find_repo_root()
¶
Find the repository root directory.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the repository root |
Source code in src/rhiza_hooks/check_python_version.py
get_pyproject_requires_python(repo_root)
¶
Read requires-python constraint from pyproject.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str] | None
|
Tuple of (operator, version) or None if not specified. |
tuple[str, str] | None
|
For example: (">=", "3.11") or ("==", "3.12") |
Source code in src/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 src/rhiza_hooks/check_python_version.py
main(argv=None)
¶
Main entry point for the hook.
Source code in src/rhiza_hooks/check_python_version.py
parse_version(version_str)
¶
Parse a version string into a tuple of (major, minor).
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 src/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 |