# HG changeset patch
# User Philippe Pepiot <philippe.pepiot@logilab.fr>
# Date 1523541530 -7200
#      Thu Apr 12 15:58:50 2018 +0200
# Node ID 5ea9f59e7dacfb904f45cef6972aae3442536e51
# Parent  5f4d909fe90b5d91c0ff72102364ebed93fd34c2
Use local hg when using asv dev

When running "asv dev" there is no virtualenv managed by asv, so use the local
installation in ./mercurial

diff --git a/benchmarks/utils.py b/benchmarks/utils.py
--- a/benchmarks/utils.py
+++ b/benchmarks/utils.py
@@ -145,7 +145,13 @@
     def setup(self, repo_name, *args, **kwargs):
         venv = os.path.abspath(os.path.join(os.path.dirname(sys.executable), ".."))
         self.repo_name = repo_name
-        self.hgpath = os.path.join(venv, "bin", "hg")
+        if os.path.isdir(os.path.join(venv, "project")):
+            # use hg in virtualenv for "asv run"
+            self.hgpath = os.path.join(venv, "bin", "hg")
+        else:
+            # use local hg for "asv dev"
+            sys.path.insert(0, os.path.join(BASEDIR, 'mercurial'))
+            self.hgpath = os.path.join(os.path.join(BASEDIR, 'mercurial', 'hg'))
         self.repo_path = os.path.join(REPOS_DIR, self.repo_name)
 
         # Use a clean environ to run command