Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobami committed Jul 31, 2016
1 parent 5c8d6b3 commit 17d4a84
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions codespeed/commits/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals


class CommitLogError(Exception):
"""An error when trying to display commit log messages"""
12 changes: 6 additions & 6 deletions codespeed/commits/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def updaterepo(project, update=True):
return

p = Popen(['git', 'pull'], stdout=PIPE, stderr=PIPE,
cwd=project.working_copy)
cwd=project.working_copy)

stdout, stderr = p.communicate()
if p.returncode != 0:
Expand All @@ -27,7 +27,7 @@ def updaterepo(project, update=True):
else:
cmd = ['git', 'clone', project.repo_path, project.repo_name]
p = Popen(cmd, stdout=PIPE, stderr=PIPE,
cwd=settings.REPOSITORY_BASE_PATH)
cwd=settings.REPOSITORY_BASE_PATH)
logger.debug('Cloning Git repo {0} for project {1}'.format(
project.repo_path, project))
stdout, stderr = p.communicate()
Expand All @@ -43,9 +43,9 @@ def getlogs(endrev, startrev):
updaterepo(endrev.branch.project, update=False)

cmd = ["git", "log",
# NULL separated values delimited by 0x1e record separators
# See PRETTY FORMATS in git-log(1):
'--format=format:%h%x00%H%x00%at%x00%an%x00%ae%x00%s%x00%b%x1e']
# NULL separated values delimited by 0x1e record separators
# See PRETTY FORMATS in git-log(1):
'--format=format:%h%x00%H%x00%at%x00%an%x00%ae%x00%s%x00%b%x1e']

if endrev.commitid != startrev.commitid:
cmd.append("%s...%s" % (startrev.commitid, endrev.commitid))
Expand All @@ -67,7 +67,7 @@ def getlogs(endrev, startrev):
subject, body) = log.split("\x00", 7)

date = datetime.datetime.fromtimestamp(
int(date_t)).strftime("%Y-%m-%d %H:%M:%S")
int(date_t)).strftime("%Y-%m-%d %H:%M:%S")

logs.append({'date': date, 'message': subject, 'commitid': commit_id,
'author': author_name, 'author_email': author_email,
Expand Down
27 changes: 18 additions & 9 deletions codespeed/commits/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ def retrieve_revision(commit_id, username, project, revision=None):
raise e

if commit_json["message"] in ("Not Found", "Server Error",):
# We'll still cache these for a brief period of time to avoid making too many requests:
# We'll still cache these for a brief period of time to avoid
# making too many requests:
cache.set(commit_url, commit_json, 300)
else:
# We'll cache successes for a very long period of time since
# SCM diffs shouldn't change:
cache.set(commit_url, commit_json, 86400 * 30)

if commit_json["message"] in ("Not Found", "Server Error",):
raise CommitLogError("Unable to load %s: %s" % (commit_url, commit_json["message"]))
raise CommitLogError(
"Unable to load %s: %s" % (commit_url, commit_json["message"]))

date = isodate.parse_datetime(commit_json['committer']['date'])

Expand All @@ -66,7 +68,8 @@ def retrieve_revision(commit_id, username, project, revision=None):

# We need to convert the timezone-aware date to a naive (i.e.
# timezone-less) date in UTC to avoid killing MySQL:
revision.date = date.astimezone(isodate.tzinfo.Utc()).replace(tzinfo=None)
revision.date = date.astimezone(
isodate.tzinfo.Utc()).replace(tzinfo=None)
revision.author = commit_json['author']['name']
revision.message = commit_json['message']
revision.full_clean()
Expand All @@ -85,7 +88,7 @@ def retrieve_revision(commit_id, username, project, revision=None):
def getlogs(endrev, startrev):
if endrev != startrev:
revisions = endrev.branch.revisions.filter(
date__lte=endrev.date, date__gte=startrev.date)
date__lte=endrev.date, date__gte=startrev.date)
else:
revisions = [i for i in (startrev, endrev) if i.commitid]

Expand All @@ -105,23 +108,29 @@ def getlogs(endrev, startrev):
last_rev_data = None
revision_count = 0
ancestor_found = False
#TODO: get all revisions between endrev and startrev,
# TODO: get all revisions between endrev and startrev,
# not only those present in the Codespeed DB

for revision in revisions:
last_rev_data = retrieve_revision(revision.commitid, username, project, revision)
last_rev_data = retrieve_revision(
revision.commitid, username, project, revision)
logs.append(last_rev_data)
revision_count += 1
ancestor_found = (startrev.commitid in [rev['sha'] for rev in last_rev_data['parents']])
ancestor_found = (
startrev.commitid in [
rev['sha'] for rev in last_rev_data['parents']])

# Simple approach to find the startrev, stop after found or after
# #GITHUB_REVISION_LIMIT revisions are fetched
while (revision_count < GITHUB_REVISION_LIMIT
and not ancestor_found
and len(last_rev_data['parents']) > 0):
last_rev_data = retrieve_revision(last_rev_data['parents'][0]['sha'], username, project)
last_rev_data = retrieve_revision(
last_rev_data['parents'][0]['sha'], username, project)
logs.append(last_rev_data)
revision_count += 1
ancestor_found = (startrev.commitid in [rev['sha'] for rev in last_rev_data['parents']])
ancestor_found = (
startrev.commitid in [
rev['sha'] for rev in last_rev_data['parents']])

return sorted(logs, key=lambda i: i['date'], reverse=True)
12 changes: 6 additions & 6 deletions codespeed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def save(self, *args, **kwargs):

super(Report, self).save(*args, **kwargs)

def updown(self,val):
#Substitute plus/minus with up/down
def updown(self, val):
"""Substitutes plus/minus with up/down"""
direction = val >= 0 and "up" or "down"
aval = abs(val)
if aval == float("inf"):
Expand All @@ -343,8 +343,8 @@ def is_big_change(self, val, color, current_val, current_color):
return True
elif color == "red" and abs(val) > abs(current_val):
return True
elif (color == "green" and current_color != "red"
and abs(val) > abs(current_val)):
elif (color == "green" and current_color != "red" and
abs(val) > abs(current_val)):
return True
else:
return False
Expand Down Expand Up @@ -402,7 +402,8 @@ def get_changes_table(self, trend_depth=10, force_save=False):
)

tablelist = []
for units_title in Benchmark.objects.all().values_list('units_title', flat=True).distinct():
for units_title in Benchmark.objects.all().values_list(
'units_title', flat=True).distinct():
currentlist = []
units = ""
hasmin = False
Expand Down Expand Up @@ -550,4 +551,3 @@ def _get_tablecache(self):
if self._tablecache == '':
return {}
return json.loads(self._tablecache)

4 changes: 3 additions & 1 deletion codespeed/templatetags/percentages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

register = template.Library()


@register.filter
def percentage(value):
if value == "-":
Expand All @@ -13,9 +14,10 @@ def percentage(value):
else:
return "%.2f" % value


@register.filter
def fix_infinity(value):
'''Python’s ∞ prints "inf", but JavaScript wants "Infinity"'''
"""Python’s ∞ prints 'inf', but JavaScript wants 'Infinity'"""
if value == float("inf"):
return "Infinity"
elif value == float("-inf"):
Expand Down
14 changes: 7 additions & 7 deletions codespeed/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.core.urlresolvers import reverse
from django.conf.urls import patterns, url
from django.views.generic import TemplateView

from codespeed.feeds import LatestEntries, LatestSignificantEntries


urlpatterns = patterns('',
(r'^$', TemplateView.as_view(template_name='home.html')),
(r'^about/$', TemplateView.as_view(template_name='about.html')),
url(r'^$', TemplateView.as_view(template_name='home.html')),
url(r'^about/$', TemplateView.as_view(template_name='about.html')),
# RSS for reports
url(r'^feeds/latest/$', LatestEntries(), name='latest_feeds'),
url(r'^feeds/latest_significant/$', LatestSignificantEntries(), name='latest_significant_feeds'),
url(r'^feeds/latest_significant/$', LatestSignificantEntries(),
name='latest_significant_feeds'),
)

urlpatterns += patterns('codespeed.views',
Expand All @@ -27,6 +27,6 @@

urlpatterns += patterns('codespeed.views',
# URLs for adding results
(r'^result/add/json/$', 'add_json_results'),
(r'^result/add/$', 'add_result'),
url(r'^result/add/json/$', 'add_json_results'),
url(r'^result/add/$', 'add_result'),
)
3 changes: 1 addition & 2 deletions codespeed/views_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from django.conf import settings

from codespeed.models import (Executable, Revision, Project, Branch, Benchmark,
Result, Report)
from codespeed.models import Executable, Revision, Project, Branch


def get_default_environment(enviros, data, multi=False):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Django>=1.6,<1.9
isodate>=0.4.7,<0.6

0 comments on commit 17d4a84

Please sign in to comment.