@@ -37,7 +37,7 @@ def get_tox_envs(tox_ini_path: Path) -> list:
37
37
return core_config_set .load ("env_list" )
38
38
39
39
40
- def get_test_jobs_data (tox_envs : list , operating_systems : list ) -> list :
40
+ def get_test_job_datas (tox_envs : list , operating_systems : list ) -> list :
41
41
42
42
os_alias = {
43
43
"ubuntu-latest" : "Ubuntu" ,
@@ -53,7 +53,7 @@ def get_test_jobs_data(tox_envs: list, operating_systems: list) -> list:
53
53
"py312" : "3.12" ,
54
54
}
55
55
56
- test_jobs_data = []
56
+ test_job_datas = []
57
57
58
58
tox_test_env_regex = re_compile (
59
59
r"(?P<python_version>py\w+)-test-"
@@ -83,7 +83,7 @@ def get_test_jobs_data(tox_envs: list, operating_systems: list) -> list:
83
83
else :
84
84
test_requirements = f"-{ test_requirements } "
85
85
86
- test_jobs_data .append (
86
+ test_job_datas .append (
87
87
{
88
88
"name" : f"{ tox_env } _{ operating_system } " ,
89
89
"ui_name" : (
@@ -99,12 +99,12 @@ def get_test_jobs_data(tox_envs: list, operating_systems: list) -> list:
99
99
100
100
)
101
101
102
- return test_jobs_data
102
+ return test_job_datas
103
103
104
104
105
- def get_lint_jobs_data (tox_envs : list ) -> list :
105
+ def get_lint_job_datas (tox_envs : list ) -> list :
106
106
107
- lint_jobs_data = []
107
+ lint_job_datas = []
108
108
109
109
tox_lint_env_regex = re_compile (r"lint-(?P<name>[-\w]+)" )
110
110
@@ -117,7 +117,7 @@ def get_lint_jobs_data(tox_envs: list) -> list:
117
117
118
118
tox_env = tox_lint_env_match .string
119
119
120
- lint_jobs_data .append (
120
+ lint_job_datas .append (
121
121
{
122
122
"name" : f"{ tox_env } " ,
123
123
"ui_name" : f"{ tox_lint_env_match .groupdict ()['name' ]} " ,
@@ -126,12 +126,12 @@ def get_lint_jobs_data(tox_envs: list) -> list:
126
126
127
127
)
128
128
129
- return lint_jobs_data
129
+ return lint_job_datas
130
130
131
131
132
- def get_contrib_jobs_data (tox_envs : list ) -> list :
132
+ def get_contrib_job_datas (tox_envs : list ) -> list :
133
133
134
- contrib_jobs_data = []
134
+ contrib_job_datas = []
135
135
136
136
tox_contrib_env_regex = re_compile (
137
137
r"py38-test-(?P<name>[-\w]+\w)-?(?P<contrib_requirements>\d+)?"
@@ -156,7 +156,7 @@ def get_contrib_jobs_data(tox_envs: list) -> list:
156
156
else :
157
157
contrib_requirements = f"-{ contrib_requirements } "
158
158
159
- contrib_jobs_data .append (
159
+ contrib_job_datas .append (
160
160
{
161
161
"ui_name" : (
162
162
f"{ groups ['name' ]} "
@@ -167,7 +167,35 @@ def get_contrib_jobs_data(tox_envs: list) -> list:
167
167
168
168
)
169
169
170
- return contrib_jobs_data
170
+ return contrib_job_datas
171
+
172
+
173
+ def _generate_workflow (
174
+ job_datas : list , name : str , workflow_directory_path : Path
175
+ ):
176
+
177
+ # Github seems to limit the amount of jobs in a workflow file, that is why
178
+ # they are split in groups of 250 per workflow file.
179
+ for file_number , job_datas in enumerate (
180
+ [
181
+ job_datas [index :index + 250 ]
182
+ for index in range (0 , len (job_datas ), 250 )
183
+ ]
184
+ ):
185
+
186
+ with open (
187
+ workflow_directory_path .joinpath (f"{ name } _{ file_number } .yml" ),
188
+ "w"
189
+ ) as test_yml_file :
190
+
191
+ test_yml_file .write (
192
+ Environment (
193
+ loader = FileSystemLoader (Path (__file__ ).parent )
194
+ ).get_template (f"{ name } .yml.j2" ).render (
195
+ job_datas = job_datas , file_number = file_number
196
+ )
197
+ )
198
+ test_yml_file .write ("\n " )
171
199
172
200
173
201
def generate_test_workflow (
@@ -176,69 +204,33 @@ def generate_test_workflow(
176
204
* operating_systems
177
205
) -> None :
178
206
179
- jobs = get_test_jobs_data (get_tox_envs (tox_ini_path ), operating_systems )
180
-
181
- with (
182
- open (workflow_directory_path .joinpath ("test_0.yml" ), "w" ) as
183
- test_yml_file
184
- ):
185
- test_yml_file .write (
186
- Environment (
187
- loader = FileSystemLoader (Path (__file__ ).parent )
188
- ).get_template ("test.yml.j2" ).render (
189
- jobs = jobs [:250 ], file_number = 0
190
- )
191
- )
192
- test_yml_file .write ("\n " )
193
-
194
- with (
195
- open (workflow_directory_path .joinpath ("test_1.yml" ), "w" ) as
196
- test_yml_file
197
- ):
198
- test_yml_file .write (
199
- Environment (
200
- loader = FileSystemLoader (Path (__file__ ).parent )
201
- ).get_template ("test.yml.j2" ).render (
202
- jobs = jobs [250 :], file_number = 1
203
- )
204
- )
205
- test_yml_file .write ("\n " )
207
+ _generate_workflow (
208
+ get_test_job_datas (get_tox_envs (tox_ini_path ), operating_systems ),
209
+ "test" ,
210
+ workflow_directory_path
211
+ )
206
212
207
213
208
214
def generate_lint_workflow (
209
215
tox_ini_path : Path ,
210
216
workflow_directory_path : Path ,
211
217
) -> None :
212
218
213
- with (
214
- open (workflow_directory_path .joinpath ("lint.yml" ), "w" ) as
215
- lint_yml_file
216
- ):
217
- lint_yml_file .write (
218
- Environment (
219
- loader = FileSystemLoader (Path (__file__ ).parent )
220
- ).get_template ("lint.yml.j2" ).render (
221
- jobs = get_lint_jobs_data (get_tox_envs (tox_ini_path ))
222
- )
223
- )
224
- lint_yml_file .write ("\n " )
219
+ _generate_workflow (
220
+ get_lint_job_datas (get_tox_envs (tox_ini_path )),
221
+ "lint" ,
222
+ workflow_directory_path
223
+ )
225
224
226
225
227
226
def generate_contrib_workflow (
228
227
workflow_directory_path : Path ,
229
228
) -> None :
230
229
231
- with (
232
- open (workflow_directory_path .joinpath ("contrib.yml" ), "w" ) as
233
- contrib_yml_file
234
- ):
235
- contrib_yml_file .write (
236
- Environment (
237
- loader = FileSystemLoader (Path (__file__ ).parent )
238
- ).get_template ("contrib.yml.j2" ).render (
239
- jobs = get_contrib_jobs_data (
240
- get_tox_envs (Path (__file__ ).parent .joinpath ("tox.ini" ))
241
- )
242
- )
243
- )
244
- contrib_yml_file .write ("\n " )
230
+ _generate_workflow (
231
+ get_contrib_job_datas (
232
+ get_tox_envs (Path (__file__ ).parent .joinpath ("tox.ini" ))
233
+ ),
234
+ "contrib" ,
235
+ workflow_directory_path
236
+ )
0 commit comments