File: run_benchmarks.py

package info (click to toggle)
smart-open 7.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: python: 8,054; sh: 90; makefile: 14
file content (49 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download
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
"""Runs benchmarks.

We only do this is AWS credentials are available, because without them, it
is impossible to run the benchmarks at all.
"""
import os
import platform
import uuid
import subprocess

import smart_open

if os.environ.get('AWS_ACCESS_KEY_ID') and os.environ.get('AWS_SECRET_ACCESS_KEY'):

    required = ('SO_BUCKET', )
    for varname in required:
        assert varname in os.environ, 'the following env vars must be set: %s' % ', '.join(required)

    os.environ['PYTEST_ADDOPTS'] = "--reruns 3 --reruns-delay 1"

    commit_hash = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD']
    ).decode('utf-8').strip()

    #
    # This is a temporary key that test_s3 will use for I/O.
    #
    os.environ['SO_KEY'] = str(uuid.uuid4())
    subprocess.check_call(
        [
            'pytest',
            '-v',
            'integration-tests/test_s3.py',
            '--benchmark-save=%s' % commit_hash,
            '--numprocesses=0',  # disable pytest-xdist
        ]
    )

    url = 's3://%s/benchmark-results/%s' % (
        os.environ['SO_BUCKET'],
        commit_hash,
    )
    for root, subdirs, files in os.walk('.benchmarks'):
        for f in files:
            if f.endswith('%s.json' % commit_hash):
                out_url = '%s/%s.json' % (url, platform.python_version())
                with open(os.path.join(root, f), 'rt') as fin:
                    with smart_open.open(out_url, 'wt') as fout:
                        fout.write(fin.read())