4
4
import shutil
5
5
import sys
6
6
import textwrap
7
- from datetime import datetime
8
7
from os import PathLike , environ
9
8
from pathlib import Path
10
9
from pprint import pprint
15
14
16
15
import pytest
17
16
from benchmark import run_benchmarks
18
- from flaky import flaky
19
17
from modflow_devtools .build import meson_build
20
18
from modflow_devtools .download import (
21
19
download_and_unzip ,
22
- download_artifact ,
23
20
get_release ,
24
- list_artifacts ,
25
21
)
26
- from modflow_devtools .markers import no_parallel , requires_exe , requires_github
22
+ from modflow_devtools .markers import no_parallel , requires_exe
27
23
from modflow_devtools .misc import run_cmd , run_py_script , set_dir
28
24
29
25
from utils import assert_match , convert_line_endings , get_project_root_path , glob , match
71
67
]
72
68
73
69
74
- def download_benchmarks (
75
- output_path : PathLike ,
76
- verbose : bool = False ,
77
- repo_owner : str = "MODFLOW-USGS" ,
78
- ) -> Optional [Path ]:
79
- """Try to download MF6 benchmarks from GitHub Actions."""
80
-
81
- output_path = Path (output_path ).expanduser ().absolute ()
82
- name = "run-time-comparison" # todo make configurable
83
- repo = f"{ repo_owner } /modflow6" # todo make configurable, add pytest/cli args
84
- artifacts = list_artifacts (repo , name = name , verbose = verbose )
85
- artifacts = sorted (
86
- artifacts ,
87
- key = lambda a : datetime .strptime (a ["created_at" ], "%Y-%m-%dT%H:%M:%SZ" ),
88
- reverse = True ,
89
- )
90
- artifacts = [
91
- a
92
- for a in artifacts
93
- if a ["workflow_run" ]["head_branch" ] == "develop" # todo make configurable
94
- ]
95
- most_recent = next (iter (artifacts ), None )
96
- print (f"Found most recent benchmarks (artifact { most_recent ['id' ]} )" )
97
- if most_recent :
98
- print (f"Downloading benchmarks (artifact { most_recent ['id' ]} )" )
99
- download_artifact (repo , id = most_recent ["id" ], path = output_path , verbose = verbose )
100
- print (f"Downloaded benchmarks to { output_path } " )
101
- path = output_path / f"{ name } .md"
102
- assert path .is_file ()
103
- return path
104
- else :
105
- print ("No benchmarks found" )
106
- return None
107
-
108
-
109
70
@pytest .fixture
110
71
def github_user () -> Optional [str ]:
111
72
return environ .get ("GITHUB_USER" , None )
112
73
113
74
114
- @flaky
115
- @no_parallel
116
- @requires_github
117
- def test_download_benchmarks (tmp_path , github_user ):
118
- path = download_benchmarks (
119
- tmp_path ,
120
- verbose = True ,
121
- repo_owner = github_user if github_user else "MODFLOW-USGS" ,
122
- )
123
- if path :
124
- assert path .name == "run-time-comparison.md"
125
-
126
-
127
75
def build_benchmark_tex (
128
76
output_path : PathLike ,
129
77
force : bool = False ,
130
- repo_owner : str = "MODFLOW-USGS" ,
131
78
):
132
79
"""Build LaTeX files for MF6 performance benchmarks to go into the release notes."""
133
80
134
81
BENCHMARKS_PATH .mkdir (parents = True , exist_ok = True )
135
82
benchmarks_path = BENCHMARKS_PATH / "run-time-comparison.md"
136
83
137
- # download benchmark artifacts if any exist on GitHub
138
- if not benchmarks_path .is_file ():
139
- benchmarks_path = download_benchmarks (BENCHMARKS_PATH , repo_owner = repo_owner )
140
-
141
84
# run benchmarks again if no benchmarks found on GitHub or overwrite requested
142
85
if force or not benchmarks_path .is_file ():
143
86
run_benchmarks (
@@ -162,20 +105,6 @@ def build_benchmark_tex(
162
105
assert (RELEASE_NOTES_PATH / f"{ benchmarks_path .stem } .tex" ).is_file ()
163
106
164
107
165
- @flaky
166
- @no_parallel
167
- @requires_github
168
- def test_build_benchmark_tex (tmp_path ):
169
- benchmarks_path = BENCHMARKS_PATH / "run-time-comparison.md"
170
- tex_path = DISTRIBUTION_PATH / f"{ benchmarks_path .stem } .tex"
171
-
172
- try :
173
- build_benchmark_tex (tmp_path )
174
- assert benchmarks_path .is_file ()
175
- finally :
176
- tex_path .unlink (missing_ok = True )
177
-
178
-
179
108
def build_deprecations_tex (force : bool = False ):
180
109
"""Build LaTeX files for the deprecations table to go into the release notes."""
181
110
0 commit comments