-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnoxfile.py
143 lines (116 loc) · 4.78 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from enum import Enum
import nox
class Result(Enum):
SUCCESS = "Success"
FAILURE = "Failure"
SKIPPED = "Skipped"
PYDANTIC = ["2.0.3", "2.4.2", "2.5.0", "2.9.2"]
PYARROW = [
"11.0.0",
"12.0.1",
"13.0.0",
"14.0.2",
"15.0.2",
"16.1.0",
"17.0.0",
"18.0.0",
]
NUMPY = ["1.24.4", "1.26.4", "2.0.2", "2.1.3"]
@nox.session(python=False)
def test_pydantic_versions(session) -> None:
"""
Pydantic has a change in alias behavior in 2.5.0, where
the serialization_alias will use the alias_generator even
when validation_alias is set (before 2.5, the serialization_alias
would be None unless explicitly set when validation_alias was set, even
when an alias_generator was set).
The code tests for this, so running on multiple versions of pydantic
checks that this is handled correctly.
"""
session.run("uv", "sync")
value = session.run("uv", "run", "--no-sync", "python", "--version", silent=True)
version_list = value.lstrip("Python ").split(".")[0:2]
version = ".".join(version_list)
print(f"Python version: {version}")
results = {}
for pydantic in PYDANTIC:
name = f"pydantic=={pydantic}"
deps = {"pydantic": pydantic}
result = Result.SKIPPED
if version < "3.13":
result = run_tests(session, deps)
if version == "3.13":
# pydantic 2.8 is the first version to work with python 3.13
if pydantic >= "2.8.0":
result = run_tests(session, deps)
results[name] = result
print_results(results)
if any(result == Result.FAILURE for result in results.values()):
raise Exception("Test failed")
@nox.session(python=False)
def test_pyarrow_versions(session) -> None:
session.run("uv", "sync")
value = session.run("uv", "run", "--no-sync", "python", "--version", silent=True)
version_list = value.lstrip("Python ").split(".")[0:2]
version = ".".join(version_list)
print(f"Python version: {version}")
results = {}
for pyarrow in PYARROW:
for numpy in NUMPY:
name = f"pyarrow=={pyarrow} & numpy=={numpy}"
deps = {"pyarrow": pyarrow, "numpy": numpy}
result = Result.SKIPPED
if version == "3.8":
# All dependency constraints correctly expressed by pyarrow and numpy
# ie numpy < 1.25 and pyarrow < 18
if pyarrow < "18.0.0" and numpy == "1.24.4":
result = run_tests(session, deps)
if version == "3.9":
# Pyarrow < 15 does not correctly specify numpy < 2 constraint
# Pyarrow 15 only runs with numpy 1.x
# Pyarrow 16 and above can run with numpy 1.x or 2.x
# Python 3.9 has numpy < 2.1
if (pyarrow < "16.0.0" and numpy < "2.0") or (
pyarrow >= "16.0.0" and numpy < "2.1"
):
result = run_tests(session, deps)
if version in ["3.10", "3.11"]:
# Pyarrow < 15 does not correctly specify numpy < 2 constraint
# pyarrow 15 only runs with numpy 1.x
if (pyarrow < "16.0.0" and numpy < "2.0") or pyarrow >= "16.0.0":
result = run_tests(session, deps)
if version == "3.12":
# Pyarrow < 15 does not correctly specify numpy < 2 constraint
# pyarrow 15 only runs with numpy 1.x
# No binary builds for pyarrow < 14 for python 3.12
# numpy 1.24.4 won't install on python 3.12+
if not (pyarrow < "16.0.0" and numpy >= "2.0") and (
pyarrow > "14.0" and numpy >= "1.25"
):
result = run_tests(session, deps)
if version == "3.13":
# No binary builds for pyarrow < 18 for python 3.13
# numpy 1.24.4 won't install on python 3.12+
if pyarrow >= "18.0" and numpy >= "1.25":
result = run_tests(session, deps)
results[name] = result
print_results(results)
if any(result == Result.FAILURE for result in results.values()):
raise Exception("Test failed")
def run_tests(session, deps) -> Result:
session.run("uv", "sync")
dep_list = [f"{k}=={v}" for k, v in deps.items()]
try:
session.run("uv", "pip", "install", *dep_list)
session.run("uv", "run", "python", "-m", "pytest")
return Result.SUCCESS
except Exception:
return Result.FAILURE
def print_results(results) -> None:
for k, v in results.items():
if v == Result.SUCCESS:
print(f"\033[32m{k}: {v}\033[0m")
elif v == Result.FAILURE:
print(f"\033[31m{k}: {v}\033[0m")
else:
print(f"\033[33m{k}: {v}\033[0m")