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

gitstats: add support for python3 #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gktrk
Copy link

@gktrk gktrk commented Sep 25, 2020

Most of the work is done by the 2to3 script. Popen required the
passing of 'universal_newlines=True', otherwise it returns a byte
stream in python3. future import is added for backwards
compatibility. Lightly tested with python2.7, python3.{6,7,8}.

Most of the work is done by the 2to3 script. Popen required the
passing of 'universal_newlines=True', otherwise it returns a byte
stream in python3. __future__ import is added for backwards
compatibility. Lightly tested with python2.7, python3.{6,7,8}.
@@ -86,11 +89,11 @@ def getcommitrange(defaultrange = 'HEAD', end_only = False):
return defaultrange

def getkeyssortedbyvalues(dict):
return map(lambda el : el[1], sorted(map(lambda el : (el[1], el[0]), dict.items())))
return [el[1] for el in sorted([(el[1], el[0]) for el in list(dict.items())])]
Copy link

@penguinolog penguinolog Nov 4, 2020

Choose a reason for hiding this comment

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

	return [el[1] for el in sorted(((val, key) for key, val in dict.items()))]

@@ -1153,7 +1156,7 @@ class HTMLReportCreator(ReportCreator):
f.write('<table class="tags">')
f.write('<tr><th>Name</th><th>Date</th><th>Commits</th><th>Authors</th></tr>')
# sort the tags by date desc
tags_sorted_by_date_desc = map(lambda el : el[1], reversed(sorted(map(lambda el : (el[1]['date'], el[0]), data.tags.items()))))
tags_sorted_by_date_desc = [el[1] for el in reversed(sorted([(el[1]['date'], el[0]) for el in list(data.tags.items())]))]
Copy link

@penguinolog penguinolog Nov 4, 2020

Choose a reason for hiding this comment

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

tags_sorted_by_date_desc = [(el[1] for el in sorted((v['date'], k) for k, v in data.tags.items()), reverse=True)]

@@ -1006,7 +1009,7 @@ class HTMLReportCreator(ReportCreator):
fgl.write('%d' % stamp)
fgc.write('%d' % stamp)
for author in self.authors_to_plot:
if author in data.changes_by_date_by_author[stamp].keys():
if author in list(data.changes_by_date_by_author[stamp].keys()):

Choose a reason for hiding this comment

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

if author in data.changes_by_date_by_author[stamp]:

keys is checked for in expression

@@ -942,7 +945,7 @@ class HTMLReportCreator(ReportCreator):
f.write('<th>Timezone</th><th>Commits</th>')
f.write('</tr>')
max_commits_on_tz = max(data.commits_by_timezone.values())
for i in sorted(data.commits_by_timezone.keys(), key = lambda n : int(n)):
for i in sorted(list(data.commits_by_timezone.keys()), key = lambda n : int(n)):

Choose a reason for hiding this comment

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

use generator expression: more memory efficient & faster


# dict['author'] = { 'commits': 512 } - ...key(dict, 'commits')
def getkeyssortedbyvaluekey(d, key):
return map(lambda el : el[1], sorted(map(lambda el : (d[el][key], el), d.keys())))
return [el[1] for el in sorted([(d[el][key], el) for el in list(d.keys())])]

Choose a reason for hiding this comment

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

	return [el[1] for el in sorted(((v[key], k) for k, v in d.items()))]

@penguinolog
Copy link

looks like 2to3 still produces code, which "just run"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants