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

Use setup.py directly rather than pip install #203

Merged
merged 15 commits into from
Feb 9, 2015
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ install:
fi

script:
- pip install virtualenv==1.10
- pip install virtualenv
- python setup.py test
5 changes: 1 addition & 4 deletions asv/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from .console import log, truncate_left
from .environment import get_environments
from .repo import get_repo
from . import util


Expand Down Expand Up @@ -194,9 +193,7 @@ def disc_benchmarks(cls, conf):

log.info("Discovering benchmarks")
with log.indent():
repo = get_repo(conf)
repo.checkout()

env.create()
env.install_project(conf)

output = env.run(
Expand Down
3 changes: 1 addition & 2 deletions asv/commands/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def do_benchmark(i):
"For {0} commit hash {1}:".format(
conf.project, commit_hash[:8]))

repo.checkout(commit_hash)
env.install_project(conf)
env.install_project(conf, commit_hash)
x = benchmarks.run_benchmarks(
env, show_stderr=show_stderr)
results[i] = list(x.values())[0]['result']
Expand Down
3 changes: 1 addition & 2 deletions asv/commands/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ def run(cls, conf, benchmark, revision=None, gui=None, output=None,
else:
log.info("Running profiler")
with log.indent():
repo.checkout(commit_hash)
env.install_project(conf)
env.install_project(conf, commit_hash)

results = benchmarks.run_benchmarks(
env, show_stderr=True, quick=False, profile=True)
Expand Down
15 changes: 7 additions & 8 deletions asv/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import six

import logging

from . import Command
from ..benchmarks import Benchmarks
from ..console import log
Expand All @@ -18,9 +20,10 @@


def _do_build(args):
env, conf = args
env, conf, commit_hash = args
try:
env.install_project(conf)
with log.set_level(logging.WARN):
env.install_project(conf, commit_hash)
except util.ProcessError:
return False
return True
Expand Down Expand Up @@ -78,9 +81,7 @@ def setup_arguments(cls, subparsers):
"--parallel", "-j", nargs='?', type=int, default=1, const=-1,
help="""Build (but don't benchmark) in parallel. The
value is the number of CPUs to use, or if no number
provided, use the number of cores on this machine. NOTE:
parallel building is still experimental and may not work
in all cases.""")
provided, use the number of cores on this machine.""")
parser.add_argument(
"--show-stderr", "-e", action="store_true",
help="""Display the stderr output from the benchmarks.""")
Expand Down Expand Up @@ -222,13 +223,11 @@ def run(cls, conf, range_spec="master", steps=0, bench=None, parallel=1,
"For {0} commit hash {1}:".format(
conf.project, commit_hash[:8]))
with log.indent():
repo.checkout(commit_hash)

for subenv in util.iter_chunks(environments, parallel):
log.info("Building for {0}".format(
', '.join([x.name for x in subenv])))
with log.indent():
args = [(env, conf) for env in subenv]
args = [(env, conf, commit_hash) for env in subenv]
if parallel != 1:
pool = multiprocessing.Pool(parallel)
successes = pool.map(_do_build_multiprocess, args)
Expand Down
12 changes: 7 additions & 5 deletions asv/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import logging

from . import Command
from ..console import log
from .. import environment
from ..repo import get_repo
from .. import util


def _install_requirements(env):
try:
env.install_requirements()
with log.set_level(logging.WARN):
env.install_requirements()
except:
import traceback
traceback.print_exc()
Expand Down Expand Up @@ -43,9 +47,7 @@ def setup_arguments(cls, subparsers):
"--parallel", "-j", nargs='?', type=int, default=1, const=-1,
help="""Build (but don't benchmark) in parallel. The
value is the number of CPUs to use, or if no number
provided, use the number of cores on this machine. NOTE:
parallel building is still considered experimental and may
not work in all cases.""")
provided, use the number of cores on this machine.""")

parser.set_defaults(func=cls.run_from_args)

Expand All @@ -64,7 +66,7 @@ def run(cls, conf, parallel=-1):
log.info("Creating environments")
with log.indent():
for env in environments:
env.setup()
env.create()

log.info("Installing dependencies")
with log.indent():
Expand Down
7 changes: 7 additions & 0 deletions asv/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ def enable(self, verbose=False):
else:
self._logger.setLevel(logging.INFO)

@contextlib.contextmanager
def set_level(self, level):
orig_level = self._logger.level
self._logger.setLevel(level)
yield
self._logger.setLevel(orig_level)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't set the level back if an exception is raised (eg build failure), may be related to gh-209

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've cherry-picked 044b8d6 over to this branch.

Copy link
Collaborator

@pv pv Feb 9, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def is_debug_enabled(self):
return self._logger.getEffectiveLevel() <= logging.DEBUG

Expand Down
83 changes: 74 additions & 9 deletions asv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

import hashlib
import os
import shutil
import sys

import six

from .console import log
from .repo import get_repo
from . import util
from . import wheel_cache


def iter_configuration_matrix(matrix):
Expand Down Expand Up @@ -61,7 +64,6 @@ def get_env_name(python, requirements):
return '-'.join(name)



def get_environments(conf):
"""
Iterator returning `Environment` objects for all of the
Expand Down Expand Up @@ -161,8 +163,16 @@ class Environment(object):
"""
tool_name = None

def __init__(self):
raise NotImplementedError()
def __init__(self, conf):
self._env_dir = conf.env_dir
self._path = os.path.abspath(os.path.join(
self._env_dir, self.hashname))

self._is_setup = False
self._requirements_installed = False

self._source_repo = get_repo(conf)
self._cache = wheel_cache.WheelCache(conf, self._path)

@classmethod
def get_environments(cls, conf, python):
Expand Down Expand Up @@ -212,6 +222,42 @@ def requirements(self):
def python(self):
return self._python

@property
def repo(self):
if not self._is_setup:
raise ValueError("No repo set up yet")
return self._repo

def create(self):
"""
Create the outer layers of the environment, including an
information file and a local clone of the project repository.
Calls `setup` internally to setup a specific kind of
environment.
"""
if self._is_setup:
return

if not os.path.exists(self._env_dir):
os.makedirs(self._env_dir)

if not os.path.exists(self._path):
try:
self.setup()
except:
log.error("Failure creating environment for {0}".format(self.name))
if os.path.exists(self._path):
shutil.rmtree(self._path)
raise

self.save_info_file(self._path)
if self._source_repo is not None: # For testing only
self._repo = self._source_repo.__class__(
self._source_repo.path, os.path.join(self._path, 'project'),
shared=True)

self._is_setup = True

def setup(self):
"""
Setup the environment on disk. If it doesn't exist, it is
Expand All @@ -222,7 +268,7 @@ def setup(self):
def install_requirements(self):
raise NotImplementedError()

def install(self, package, editable=False):
def install(self, package):
"""
Install a package into the environment.
"""
Expand All @@ -241,15 +287,32 @@ def run(self, args, **kwargs):
"""
raise NotImplementedError()

def install_project(self, conf):
def build_project(self, commit_hash):
log.info("Building for {0}".format(self.name))
build_root = os.path.abspath(self.repo.path)
self.repo.checkout(commit_hash)
self.run(['setup.py', 'build'], cwd=build_root)
return build_root

def install_project(self, conf, commit_hash=None):
"""
Install a working copy of the benchmarked project into the
environment. Uninstalls any installed copy of the project
first.
"""
if commit_hash is None:
commit_hash = self.repo.get_hash_from_head()

self.install_requirements()
self.uninstall(conf.project)
self.install(os.path.abspath(conf.project))

build_root = self._cache.build_project_cached(
self, conf, commit_hash)

if build_root is None:
build_root = self.build_project(commit_hash)

self.install(build_root)

def can_install_project(self):
"""
Expand All @@ -274,7 +337,9 @@ def save_info_file(self, path):
class ExistingEnvironment(Environment):
tool_name = "existing"

def __init__(self, executable):
def __init__(self, conf, executable):
super(ExistingEnvironment, self).__init__(conf)

self._executable = executable
self._python = util.check_output(
[executable,
Expand All @@ -289,7 +354,7 @@ def get_environments(cls, conf, python):
if python == 'same':
python = sys.executable

yield cls(util.which(python))
yield cls(conf, util.which(python))

@classmethod
def matches(cls, python):
Expand All @@ -313,7 +378,7 @@ def setup(self):
def install_requirements(self):
pass

def install_project(self, conf):
def install_project(self, conf, commit_hash):
pass

def can_install_project(self):
Expand Down
Loading