Skip to content

Commit ef8dbb8

Browse files
committed
Add compatibility for Python 2.7
1 parent 28b5c6d commit ef8dbb8

5 files changed

Lines changed: 17 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ src/dist/
77
build/
88
dist/
99
*.egg-info/
10+
*.pyc

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf8 -*-
2+
13
"""
24
Setup script.
35

src/gitolog/build.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
import sys
24
from datetime import datetime
35
from subprocess import check_output
@@ -199,23 +201,23 @@ def __init__(self, repository, provider=None, style=None):
199201
base=last_version.previous_version.tag, target=last_version.planned_tag)
200202

201203
def get_remote_url(self):
202-
git_url = str(check_output(
204+
git_url = check_output(
203205
['git', 'config', '--get', 'remote.origin.url'],
204-
cwd=self.repository))[2:-1].rstrip('\\n')
206+
cwd=self.repository
207+
).decode('utf-8').rstrip('\n')
205208
if git_url.startswith('git@'):
206209
git_url = git_url.replace(':', '/', 1).replace('git@', 'https://', 1)
207210
if git_url.endswith('.git'):
208211
git_url = git_url[:-4]
209212
return git_url
210213

211214
def get_log(self):
212-
# remove enclosing b-quotes (b'' or b"")
213-
return str(check_output(
215+
return check_output(
214216
['git', 'log', '--date=unix', '--format=' + self.FORMAT],
215-
cwd=self.repository))[2:-1].replace("\\'", "'")
217+
cwd=self.repository).decode('utf-8')
216218

217219
def parse_commits(self):
218-
lines = self.raw_log.split('\\n')
220+
lines = self.raw_log.split('\n')
219221
size = len(lines) - 1 # don't count last blank line
220222
commits = []
221223
pos = 0
@@ -293,7 +295,8 @@ def group_commits_by_version(self, dates):
293295
versions_dict[commit.version].sections_list.append(section)
294296
versions_dict[commit.version].sections_dict = versions_types_dict[commit.version]
295297
versions_types_dict[commit.version][commit.style['type']].commits.append(commit)
296-
next_version.compare_url = self.provider.get_compare_url(
297-
base=versions_list[-1].commits[-1].hash, target=next_version.tag or 'HEAD')
298+
if next_version is not None:
299+
next_version.compare_url = self.provider.get_compare_url(
300+
base=versions_list[-1].commits[-1].hash, target=next_version.tag or 'HEAD')
298301
return {'as_list': versions_list, 'as_dict': versions_dict}
299302

src/gitolog/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
1616
"""
1717

18+
from __future__ import print_function
19+
1820
import argparse
1921
import sys
2022

src/gitolog/providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __str__(self):
2222
return self.ref + ': ' + self.url
2323

2424

25-
class ProviderRefParser:
25+
class ProviderRefParser(object):
2626
REF = {}
2727

2828
def get_refs(self, ref_type, text):

0 commit comments

Comments
 (0)