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

BUG: Allow tag commit hashes for graphs #1227

Merged
merged 10 commits into from
Jan 2, 2023
15 changes: 11 additions & 4 deletions asv/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,18 @@ def copy_ignore(src, names):
branches_for_commit = [branch for branch, commits in branches.items() if
results.commit_hash in commits]

# Print a warning message if we couldn't find the branch of a commit
# Print a warning message if the commit isn't from a tag
if not len(branches_for_commit):
msg = "Couldn't find {} in branches ({})"
log.warning(msg.format(results.commit_hash[:conf.hash_length],
", ".join(str(branch) for branch in branches.keys())))
# Assume that these must be tags
repo_tags = repo.get_tags()
branches_for_commit = [branch for branch, commits in branches.items() if
results.commit_hash in repo_tags.values()]
if not len(branches_for_commit):
# Not tags, print a warning
msg = "Couldn't find {} in branches ({})"
log.warning(msg.format(results.commit_hash[:conf.hash_length],
", ".join(str(branch) for
branch in branches.keys())))

for key in results.get_result_keys(benchmarks):
b = benchmarks[key]
Expand Down
17 changes: 13 additions & 4 deletions asv/plugins/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@

class Git(Repo):
dvcs = "git"
_default_branch = "master"

def __init__(self, url, mirror_path):
self._git = util.which("git")
self._path = os.path.abspath(mirror_path)
self._pulled = False
# default branch
try:
self._default_branch = self._run_git(['config',
'init.defaultBranch',
], display_error=False,
cwd=None).strip()
except util.ProcessError:
self._default_branch = 'master'

if self.is_local_repo(url):
# Local repository, no need for mirror
Expand Down Expand Up @@ -87,13 +94,15 @@ def pull(self):
def checkout(self, path, commit_hash):
def checkout_existing(display_error):
# Deinit fails if no submodules, so ignore its failure
self._run_git(['-c','protocol.file.allow=always', 'submodule', 'deinit', '-f', '.'],
self._run_git(['-c', 'protocol.file.allow=always',
'submodule', 'deinit', '-f', '.'],
cwd=path, display_error=False, valid_return_codes=None)
self._run_git(['checkout', '-f', commit_hash],
cwd=path, display_error=display_error)
self._run_git(['clean', '-fdx'],
cwd=path, display_error=display_error)
self._run_git(['-c','protocol.file.allow=always', 'submodule', 'update', '--init', '--recursive'],
self._run_git(['-c', 'protocol.file.allow=always',
'submodule', 'update', '--init', '--recursive'],
cwd=path, display_error=display_error)

if os.path.isdir(path):
Expand Down Expand Up @@ -161,7 +170,7 @@ def get_name_from_hash(self, commit):

def get_tags(self):
tags = {}
for tag in self._run_git(["tag", "-l"]).splitlines():
for tag in self._run_git(["tag", "-l", "--sort=taggerdate"]).splitlines():
tags[tag] = self._run_git(["rev-list", "-n", "1", tag]).strip()
return tags

Expand Down
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ addopts=-p no:logging
[flake8]
max-line-length = 99
ignore =
W504, # W504: Line break occurred after a binary operator
E741 # E741: Do not use variables named 'I', 'O', or 'l'
# W504: Line break occurred after a binary operator
W504,
# E741: Do not use variables named 'I', 'O', or 'l'
E741
exclude = asv/extern

[isort]
Expand Down
13 changes: 10 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import selenium

from asv import config, environment, repo, step_detect
from asv import config, environment, repo, step_detect, util
from asv.repo import get_repo
from asv.step_detect import L1Dist

Expand All @@ -29,13 +29,20 @@
except ImportError:
HAVE_RANGEMEDIAN = False


DUMMY_VALUES = (
(6, 1),
(6, 6),
(6, 6),
)

# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config', 'init.defaultBranch'],
display_error=False).strip()
except util.ProcessError:
defaultBranch = 'master'


def pytest_addoption(parser):
parser.addoption("--webdriver", action="store", default="None",
Expand Down Expand Up @@ -166,7 +173,7 @@ def two_branch_repo_case(request, tmpdir):
dvcs_type = request.param
tmpdir = str(tmpdir)
if dvcs_type == "git":
master = "master"
master = f"{defaultBranch}"
elif dvcs_type == "hg":
master = "default"
dvcs = tools.generate_repo_from_ops(tmpdir, dvcs_type, [
Expand Down
11 changes: 10 additions & 1 deletion test/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

from . import tools

# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config', 'init.defaultBranch'
], display_error=False).strip()
except util.ProcessError:
defaultBranch = 'master'


BENCHMARK_DIR = join(dirname(__file__), 'benchmark')

INVALID_BENCHMARK_DIR = join(
Expand All @@ -38,7 +47,7 @@ def test_discover_benchmarks(benchmarks_fixture):
assert len(b) == 6

old_branches = conf.branches
conf.branches = ["master", "some-missing-branch"] # missing branches ignored
conf.branches = [f"{defaultBranch}", "some-missing-branch"] # missing branches ignored
b = benchmarks.Benchmarks.discover(conf, repo, envs, [commit_hash],
regex='example')
conf.branches = old_branches
Expand Down
12 changes: 11 additions & 1 deletion test/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,17 @@ def test_compare_name_lookup(dvcs_type, capsys, tmpdir, example_results):
os.chdir(tmpdir)

repo = tools.generate_test_repo(tmpdir, dvcs_type=dvcs_type)
branch_name = 'master' if dvcs_type == 'git' else 'default'

# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config',
'init.defaultBranch'],
display_error=False).strip()
except util.ProcessError:
defaultBranch = 'master'

branch_name = defaultBranch if dvcs_type == 'git' else 'default'
commit_hash = repo.get_branch_hashes(branch_name)[0]

result_dir = os.path.join(tmpdir, 'results')
Expand Down
12 changes: 11 additions & 1 deletion test/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
import re

from asv.results import iter_results_for_machine
from asv import util

from . import tools
from .tools import get_default_environment_type

# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config', 'init.defaultBranch'],
display_error=False
).strip()
except util.ProcessError:
defaultBranch = 'master'


def test_continuous(capfd, basic_conf_2):
tmpdir, local, conf, machine_file = basic_conf_2
Expand All @@ -17,7 +27,7 @@ def test_continuous(capfd, basic_conf_2):
env_spec = ("-E", env_type + ":" + python)

# Check that asv continuous runs
tools.run_asv_with_conf(conf, 'continuous', "master^", '--show-stderr',
tools.run_asv_with_conf(conf, 'continuous', f"{defaultBranch}^", '--show-stderr',
'--bench=params_examples.track_find_test',
'--bench=params_examples.track_param',
'--bench=time_examples.TimeSuite.time_example_benchmark_1',
Expand Down
10 changes: 9 additions & 1 deletion test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,15 @@ def test_build_isolation(tmpdir):
'requires = ["wheel", "setuptools"]')
dvcs.add(fn)
dvcs.commit("Add pyproject.toml")
commit_hash = dvcs.get_hash("master")
# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config', 'init.defaultBranch'],
display_error=False).strip()
except util.ProcessError:
defaultBranch = 'master'

commit_hash = dvcs.get_hash(f"{defaultBranch}")

# Setup config
conf = config.Config()
Expand Down
26 changes: 19 additions & 7 deletions test/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

import pytest

from asv.util import check_output, which
from asv.util import check_output, which, ProcessError

from . import tools
from .conftest import generate_basic_conf

WIN = (os.name == 'nt')

# Variables
try:
defaultBranch = check_output([which('git'),
'config', 'init.defaultBranch'],
display_error=False).strip()
except ProcessError:
defaultBranch = 'master'


def test_find(capfd, tmpdir):
values = [
Expand All @@ -31,14 +39,16 @@ def test_find(capfd, tmpdir):
dummy_packages=False)

# Test find at least runs
tools.run_asv_with_conf(conf, 'find', "master~5..master", "params_examples.track_find_test",
tools.run_asv_with_conf(conf, 'find',
f"{defaultBranch}~5..{defaultBranch}",
"params_examples.track_find_test",
_machine_file=machine_file)

# Check it found the first commit after the initially tested one
output, err = capfd.readouterr()

regression_hash = check_output(
[which('git'), 'rev-parse', 'master^'], cwd=conf.repo)
[which('git'), 'rev-parse', f'{defaultBranch}^'], cwd=conf.repo)

assert "Greatest regression found: {0}".format(regression_hash[:8]) in output

Expand All @@ -56,14 +66,16 @@ def test_find_timeout(capfd, tmpdir):
dummy_packages=False)

# Test find at least runs
tools.run_asv_with_conf(conf, 'find', "-e", "master", "params_examples.time_find_test_timeout",
tools.run_asv_with_conf(conf, 'find', "-e",
f"{defaultBranch}",
"params_examples.time_find_test_timeout",
_machine_file=machine_file)

# Check it found the first commit after the initially tested one
output, err = capfd.readouterr()

regression_hash = check_output(
[which('git'), 'rev-parse', 'master'], cwd=conf.repo)
[which('git'), 'rev-parse', f'{defaultBranch}'], cwd=conf.repo)

assert "Greatest regression found: {0}".format(regression_hash[:8]) in output
assert "asv: benchmark timed out (timeout 1.0s)" in output
Expand All @@ -82,14 +94,14 @@ def test_find_inverted(capfd, tmpdir):
values=values,
dummy_packages=False)
tools.run_asv_with_conf(*[conf, 'find',
"-i", "master~4..master",
"-i", f"{defaultBranch}~4..{defaultBranch}",
"params_examples.track_find_test"],
_machine_file=machine_file)

output, err = capfd.readouterr()

regression_hash = check_output(
[which('git'), 'rev-parse', 'master^'], cwd=conf.repo)
[which('git'), 'rev-parse', f'{defaultBranch}^'], cwd=conf.repo)

formatted = "Greatest improvement found: {0}".format(regression_hash[:8])
assert formatted in output
18 changes: 13 additions & 5 deletions test/test_gh_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

import pytest

import asv.util
from asv import util

from . import tools

# Variables
try:
defaultBranch = util.check_output([util.which('git'),
'config', 'init.defaultBranch'],
display_error=False).strip()
except util.ProcessError:
defaultBranch = 'master'


@pytest.mark.parametrize("rewrite", [False, True], ids=["no-rewrite", "rewrite"])
def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch):
Expand Down Expand Up @@ -43,7 +51,7 @@ def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch):
dvcs.checkout('gh-pages')
assert os.path.isfile(os.path.join(dvcs_dir, 'index.html'))
assert len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines()) == 1
dvcs.checkout('master')
dvcs.checkout(f"{defaultBranch}")
assert not os.path.isfile(os.path.join(dvcs_dir, 'index.html'))

# Check with existing (and checked out) gh-pages branch, with no changes
Expand All @@ -55,13 +63,13 @@ def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch):
else:
# Timestamp may have changed
assert len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines()) <= 2
dvcs.checkout('master')
dvcs.checkout(f"{defaultBranch}")

# Check with existing (not checked out) gh-pages branch, with some changes
benchmarks_json = os.path.join(conf.results_dir, 'benchmarks.json')
data = asv.util.load_json(benchmarks_json)
data = util.load_json(benchmarks_json)
data['time_func']['pretty_name'] = 'something changed'
asv.util.write_json(benchmarks_json, data)
util.write_json(benchmarks_json, data)

prev_len = len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines())
tools.run_asv_with_conf(conf, "gh-pages", "--no-push", *rewrite_args)
Expand Down
Loading