Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting asv.conf.json on project top level #308

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions asv/commands/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,34 @@ def setup_arguments(cls, subparsers):
help="The destination directory for the new benchmarking "
"suite")

grp = parser.add_mutually_exclusive_group()
grp.add_argument(
"--top-level", action="store_true", dest="top_level", default=None,
help="Benchmarks are on the top level of the project's repository")
grp.add_argument(
"--no-top-level", action="store_false", dest="top_level", default=None,
help="Benchmarks are not in the project's repository top level")

parser.set_defaults(func=cls.run_from_args)

return parser

@classmethod
def run_from_args(cls, args):
return cls.run(dest=args.dest)
return cls.run(dest=args.dest, top_level=args.top_level)

@classmethod
def run(cls, dest="."):
def run(cls, dest=".", top_level=None):
if top_level is None:
while True:
answer = raw_input("Is this the top level of your project repository? [y/n] ")
if answer.lower()[:1] == "y":
top_level = True
break
elif answer.lower()[:1] == "n":
top_level = False
break

template_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', 'template')
for entry in os.listdir(template_path):
Expand All @@ -51,4 +69,20 @@ def run(cls, dest="."):
elif os.path.isfile(path):
shutil.copyfile(path, os.path.join(dest, entry))

if top_level:
conf_file = os.path.join(dest, 'asv.conf.json')

with open(conf_file, 'r') as f:
conf = f.read()

reps = [('"repo": "",', '"repo": ".",'),
('// "env_dir": "env",', '"env_dir": ".asv/env",'),
('// "results_dir": "results",', '"results_dir": ".asv/results",'),
('// "html_dir": "html",', '"html_dir": ".asv/html",')]
for src, dst in reps:
conf = conf.replace(src, dst)

with open(conf_file, 'w') as f:
f.write(conf)

log.info("Edit asv.conf.json to get started.")
4 changes: 4 additions & 0 deletions docs/source/using.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ benchmarking suite. Change to the directory where you would like your
new benchmarking suite to be created and run::

$ asv quickstart
Is this the top level of your project repository? [y/n] n
Edit asv.conf.json to get started.

Answer 'y' if you want a default configuration more suitable for
putting on the top level of your project's repository.

Now that you have the bare bones of a benchmarking suite, let's edit
the configuration file, ``asv.conf.json``. Like most files that
**airspeed velocity** uses and generates, it is a JSON file.
Expand Down
35 changes: 30 additions & 5 deletions test/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,43 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os
from os.path import isfile, join

import os
import six

from . import tools
from asv import util
import asv.commands.quickstart


def test_quickstart(tmpdir):
tmpdir = six.text_type(tmpdir)

tools.run_asv('quickstart', '--dest', tmpdir)

assert isfile(join(tmpdir, 'asv.conf.json'))
assert isfile(join(tmpdir, 'benchmarks', 'benchmarks.py'))
dest = join(tmpdir, 'separate')
os.makedirs(dest)

tools.run_asv('quickstart', '--no-top-level', '--dest', dest)

assert isfile(join(dest, 'asv.conf.json'))
assert isfile(join(dest, 'benchmarks', 'benchmarks.py'))
conf = util.load_json(join(dest, 'asv.conf.json'))
assert 'env_dir' not in conf
assert 'html_dir' not in conf
assert 'results_dir' not in conf

dest = join(tmpdir, 'same')
os.makedirs(dest)

try:
asv.commands.quickstart.raw_input = lambda msg: 'y'
tools.run_asv('quickstart', '--dest', dest)
finally:
del asv.commands.quickstart.raw_input

assert isfile(join(dest, 'asv.conf.json'))
assert isfile(join(dest, 'benchmarks', 'benchmarks.py'))
conf = util.load_json(join(dest, 'asv.conf.json'))
assert conf['env_dir'] != 'env'
assert conf['html_dir'] != 'html'
assert conf['results_dir'] != 'results'