Skip to content

Commit 079f7bc

Browse files
author
y-p
committed
BLD: fix path handling, and possible import surprises in test_perf
1 parent 1b7f070 commit 079f7bc

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

vb_suite/test_perf.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import shutil
3030
import os
31+
import sys
3132
import argparse
3233
import tempfile
3334
import time
@@ -92,7 +93,6 @@ def get_results_df(db, rev):
9293
def prprint(s):
9394
print("*** %s" % s)
9495

95-
9696
def main():
9797
from pandas import DataFrame
9898
from vbench.api import BenchmarkRunner
@@ -109,18 +109,31 @@ def main():
109109
args.log_file = os.path.abspath(
110110
os.path.join(REPO_PATH, 'vb_suite.log'))
111111

112+
if args.outdf:
113+
# not bullet-proof but enough for us
114+
if os.path.sep not in args.outdf:
115+
args.outdf = os.path.join(os.curdir, args.outdf)
116+
117+
if args.log_file:
118+
# not bullet-proof but enough for us
119+
if os.path.sep not in args.log_file:
120+
args.log_file = os.path.join(os.curdir, args.log_file)
121+
112122
random.seed(args.seed)
113123
np.random.seed(args.seed)
114124

115125
TMP_DIR = tempfile.mkdtemp()
116126
prprint("TMP_DIR = %s" % TMP_DIR)
117127
prprint("LOG_FILE = %s\n" % args.log_file)
118128

129+
saved_dir = os.path.curdir
130+
# move away from the pandas root dit, to avoid possible import
131+
# surprises
132+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
133+
119134
benchmarks = [x for x in benchmarks if re.search(args.regex,x.name)]
120135

121136
try:
122-
logfile = open(args.log_file, 'w')
123-
124137
prprint("Opening DB at '%s'...\n" % DB_PATH)
125138
db = BenchmarkDB(DB_PATH)
126139

@@ -136,6 +149,8 @@ def main():
136149
module_dependencies=dependencies)
137150

138151
repo = runner.repo # (steal the parsed git repo used by runner)
152+
h_head = args.target_commit or repo.shas[-1]
153+
h_baseline = args.base_commit
139154

140155
# ARGH. reparse the repo, without discarding any commits,
141156
# then overwrite the previous parse results
@@ -144,9 +159,6 @@ def main():
144159
repo.timestamps, repo.authors) = _parse_commit_log(None,REPO_PATH,
145160
args.base_commit)
146161

147-
h_head = args.target_commit or repo.shas[-1]
148-
h_baseline = args.base_commit
149-
150162
prprint('Target [%s] : %s\n' % (h_head, repo.messages.get(h_head, "")))
151163
prprint('Baseline [%s] : %s\n' % (h_baseline,
152164
repo.messages.get(h_baseline, "")))
@@ -178,7 +190,6 @@ def main():
178190
totals = totals.dropna(
179191
).sort("ratio").set_index('name') # sort in ascending order
180192

181-
182193
hdr = ftr = """
183194
-----------------------------------------------------------------------
184195
Test name | target[ms] | base[ms] | ratio |
@@ -199,28 +210,28 @@ def main():
199210
s += 'Base [%s] : %s\n\n' % (
200211
h_baseline, repo.messages.get(h_baseline, ""))
201212

213+
logfile = open(args.log_file, 'w')
202214
logfile.write(s)
203215
logfile.close()
204216

205217
prprint(s)
206218
prprint("Results were also written to the logfile at '%s'" %
207219
args.log_file)
208220

221+
if args.outdf:
222+
prprint("The results DataFrame was written to '%s'\n" % args.outdf)
223+
totals.save(args.outdf)
224+
209225
finally:
210226
# print("Disposing of TMP_DIR: %s" % TMP_DIR)
211227
shutil.rmtree(TMP_DIR)
212-
logfile.close()
228+
os.chdir(saved_dir)
213229

214-
if args.outdf:
215230

216-
opath = os.path.abspath(os.path.join(os.curdir,args.outdf))
217-
prprint("The results DataFrame was written to '%s'\n" % opath)
218-
totals.save(opath)
219231

220232
# hack , vbench.git ignores some commits, but we
221233
# need to be able to reference any commit.
222234
# modified from vbench.git
223-
224235
def _parse_commit_log(this,repo_path,base_commit=None):
225236
from vbench.git import parser, _convert_timezones
226237
from pandas import Series

0 commit comments

Comments
 (0)