1
+ """Get minimum versions of dependencies from a pyproject.toml file."""
2
+
1
3
import sys
2
4
from collections import defaultdict
3
5
from typing import Optional
4
6
5
7
if sys .version_info >= (3 , 11 ):
6
8
import tomllib
7
9
else :
8
- # for python 3.10 and below, which doesnt have stdlib tomllib
10
+ # For Python 3.10 and below, which doesnt have stdlib tomllib
9
11
import tomli as tomllib
10
12
11
13
import re
34
36
35
37
36
38
def get_pypi_versions (package_name : str ) -> List [str ]:
37
- """
38
- Fetch all available versions for a package from PyPI.
39
+ """Fetch all available versions for a package from PyPI.
39
40
40
41
Args:
41
- package_name (str) : Name of the package
42
+ package_name: Name of the package
42
43
43
44
Returns:
44
- List[str]: List of all available versions
45
+ List of all available versions
45
46
46
47
Raises:
47
48
requests.exceptions.RequestException: If PyPI API request fails
@@ -54,24 +55,23 @@ def get_pypi_versions(package_name: str) -> List[str]:
54
55
55
56
56
57
def get_minimum_version (package_name : str , spec_string : str ) -> Optional [str ]:
57
- """
58
- Find the minimum published version that satisfies the given constraints.
58
+ """Find the minimum published version that satisfies the given constraints.
59
59
60
60
Args:
61
- package_name (str) : Name of the package
62
- spec_string (str) : Version specification string (e.g., ">=0.2.43,<0.4.0,!=0.3.0")
61
+ package_name: Name of the package
62
+ spec_string: Version specification string (e.g., ">=0.2.43,<0.4.0,!=0.3.0")
63
63
64
64
Returns:
65
- Optional[str]: Minimum compatible version or None if no compatible version found
65
+ Minimum compatible version or None if no compatible version found
66
66
"""
67
- # rewrite occurrences of ^0.0.z to 0.0.z (can be anywhere in constraint string)
67
+ # Rewrite occurrences of ^0.0.z to 0.0.z (can be anywhere in constraint string)
68
68
spec_string = re .sub (r"\^0\.0\.(\d+)" , r"0.0.\1" , spec_string )
69
- # rewrite occurrences of ^0.y.z to >=0.y.z,<0.y+1 (can be anywhere in constraint string)
69
+ # Rewrite occurrences of ^0.y.z to >=0.y.z,<0.y+1 (can be anywhere in constraint string)
70
70
for y in range (1 , 10 ):
71
71
spec_string = re .sub (
72
72
rf"\^0\.{ y } \.(\d+)" , rf">=0.{ y } .\1,<0.{ y + 1 } " , spec_string
73
73
)
74
- # rewrite occurrences of ^x.y.z to >=x.y.z,<x+1.0.0 (can be anywhere in constraint string)
74
+ # Rewrite occurrences of ^x.y.z to >=x.y.z,<x+1.0.0 (can be anywhere in constraint string)
75
75
for x in range (1 , 10 ):
76
76
spec_string = re .sub (
77
77
rf"\^{ x } \.(\d+)\.(\d+)" , rf">={ x } .\1.\2,<{ x + 1 } " , spec_string
@@ -154,22 +154,25 @@ def get_min_version_from_toml(
154
154
155
155
156
156
def check_python_version (version_string , constraint_string ):
157
- """
158
- Check if the given Python version matches the given constraints.
157
+ """Check if the given Python version matches the given constraints.
159
158
160
- :param version_string: A string representing the Python version (e.g. "3.8.5").
161
- :param constraint_string: A string representing the package's Python version constraints (e.g. ">=3.6, <4.0").
162
- :return: True if the version matches the constraints, False otherwise.
159
+ Args:
160
+ version_string: A string representing the Python version (e.g. "3.8.5").
161
+ constraint_string: A string representing the package's Python version
162
+ constraints (e.g. ">=3.6, <4.0").
163
+
164
+ Returns:
165
+ True if the version matches the constraints
163
166
"""
164
167
165
- # rewrite occurrences of ^0.0.z to 0.0.z (can be anywhere in constraint string)
168
+ # Rewrite occurrences of ^0.0.z to 0.0.z (can be anywhere in constraint string)
166
169
constraint_string = re .sub (r"\^0\.0\.(\d+)" , r"0.0.\1" , constraint_string )
167
- # rewrite occurrences of ^0.y.z to >=0.y.z,<0.y+1.0 (can be anywhere in constraint string)
170
+ # Rewrite occurrences of ^0.y.z to >=0.y.z,<0.y+1.0 (can be anywhere in constraint string)
168
171
for y in range (1 , 10 ):
169
172
constraint_string = re .sub (
170
173
rf"\^0\.{ y } \.(\d+)" , rf">=0.{ y } .\1,<0.{ y + 1 } .0" , constraint_string
171
174
)
172
- # rewrite occurrences of ^x.y.z to >=x.y.z,<x+1.0.0 (can be anywhere in constraint string)
175
+ # Rewrite occurrences of ^x.y.z to >=x.y.z,<x+1.0.0 (can be anywhere in constraint string)
173
176
for x in range (1 , 10 ):
174
177
constraint_string = re .sub (
175
178
rf"\^{ x } \.0\.(\d+)" , rf">={ x } .0.\1,<{ x + 1 } .0.0" , constraint_string
0 commit comments