Skip to content

Commit ad1fdb8

Browse files
committed
Travis CI: Lint for Python syntax errors and undefined names
Several things were changed between Python 2 and Python 3. There are a few Python 3 incompatibilities to work on. Here we are making changes to make the code run on both Py2 and Py3. We are doing this because the end of life of Python 2 is in 167 days. We are using print() function because legacy print statements are syntax errors on Py3. reduce() was moved in Python 3 and raw_input() was removed so we make changes to avoid NameErrors being raised at runtime. We are also putting flake8 lint tests in place on Travis CI to avoid any backsliding on future pull requests. Signed-off-by: cclauss <cclauss@me.com>
1 parent 9d41860 commit ad1fdb8

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ matrix:
3939
compiler:
4040
script: ci/test-documentation.sh
4141
after_failure:
42+
- env: jobname=LintPython
43+
language: python
44+
before_install: pip install flake8
45+
script: flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
4246

4347
before_install: ci/install-dependencies.sh
4448
script: ci/run-build-and-tests.sh

contrib/fast-import/import-zips.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
## python import-zips.py *.zip
99
## git log --stat import-zips
1010

11+
from __future__ import print_function
1112
from os import popen, path
1213
from sys import argv, exit, hexversion, stderr
1314
from time import mktime
@@ -19,7 +20,7 @@
1920
exit(1)
2021

2122
if len(argv) < 2:
22-
print 'usage:', argv[0], '<zipfile>...'
23+
print('usage:', argv[0], '<zipfile>...')
2324
exit(1)
2425

2526
branch_ref = 'refs/heads/import-zips'

contrib/hg-to-git/hg-to-git.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
along with this program; if not, see <http://www.gnu.org/licenses/>.
1919
"""
2020

21+
from __future__ import print_function
2122
import os, os.path, sys
2223
import tempfile, pickle, getopt
2324
import re
@@ -42,7 +43,7 @@
4243

4344
def usage():
4445

45-
print """\
46+
print("""\
4647
%s: [OPTIONS] <hgprj>
4748
4849
options:
@@ -54,7 +55,7 @@ def usage():
5455
5556
required:
5657
hgprj: name of the HG project to import (directory)
57-
""" % sys.argv[0]
58+
""" % sys.argv[0])
5859

5960
#------------------------------------------------------------------------------
6061

@@ -104,22 +105,22 @@ def getgitenv(user, date):
104105
if state:
105106
if os.path.exists(state):
106107
if verbose:
107-
print 'State does exist, reading'
108+
print('State does exist, reading')
108109
f = open(state, 'r')
109110
hgvers = pickle.load(f)
110111
else:
111-
print 'State does not exist, first run'
112+
print('State does not exist, first run')
112113

113114
sock = os.popen('hg tip --template "{rev}"')
114115
tip = sock.read()
115116
if sock.close():
116117
sys.exit(1)
117118
if verbose:
118-
print 'tip is', tip
119+
print('tip is', tip)
119120

120121
# Calculate the branches
121122
if verbose:
122-
print 'analysing the branches...'
123+
print('analysing the branches...')
123124
hgchildren["0"] = ()
124125
hgparents["0"] = (None, None)
125126
hgbranch["0"] = "master"
@@ -155,7 +156,7 @@ def getgitenv(user, date):
155156
hgbranch[str(cset)] = "branch-" + str(cset)
156157

157158
if not hgvers.has_key("0"):
158-
print 'creating repository'
159+
print('creating repository')
159160
os.system('git init')
160161

161162
# loop through every hg changeset
@@ -180,27 +181,27 @@ def getgitenv(user, date):
180181
os.write(fdcomment, csetcomment)
181182
os.close(fdcomment)
182183

183-
print '-----------------------------------------'
184-
print 'cset:', cset
185-
print 'branch:', hgbranch[str(cset)]
186-
print 'user:', user
187-
print 'date:', date
188-
print 'comment:', csetcomment
184+
print('-----------------------------------------')
185+
print('cset:', cset)
186+
print('branch:', hgbranch[str(cset)])
187+
print('user:', user)
188+
print('date:', date)
189+
print('comment:', csetcomment)
189190
if parent:
190-
print 'parent:', parent
191+
print('parent:', parent)
191192
if mparent:
192-
print 'mparent:', mparent
193+
print('mparent:', mparent)
193194
if tag:
194-
print 'tag:', tag
195-
print '-----------------------------------------'
195+
print('tag:', tag)
196+
print('-----------------------------------------')
196197

197198
# checkout the parent if necessary
198199
if cset != 0:
199200
if hgbranch[str(cset)] == "branch-" + str(cset):
200-
print 'creating new branch', hgbranch[str(cset)]
201+
print('creating new branch', hgbranch[str(cset)])
201202
os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
202203
else:
203-
print 'checking out branch', hgbranch[str(cset)]
204+
print('checking out branch', hgbranch[str(cset)])
204205
os.system('git checkout %s' % hgbranch[str(cset)])
205206

206207
# merge
@@ -209,7 +210,7 @@ def getgitenv(user, date):
209210
otherbranch = hgbranch[mparent]
210211
else:
211212
otherbranch = hgbranch[parent]
212-
print 'merging', otherbranch, 'into', hgbranch[str(cset)]
213+
print('merging', otherbranch, 'into', hgbranch[str(cset)])
213214
os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
214215

215216
# remove everything except .git and .hg directories
@@ -233,12 +234,12 @@ def getgitenv(user, date):
233234

234235
# delete branch if not used anymore...
235236
if mparent and len(hgchildren[str(cset)]):
236-
print "Deleting unused branch:", otherbranch
237+
print("Deleting unused branch:", otherbranch)
237238
os.system('git branch -d %s' % otherbranch)
238239

239240
# retrieve and record the version
240241
vvv = os.popen('git show --quiet --pretty=format:%H').read()
241-
print 'record', cset, '->', vvv
242+
print('record', cset, '->', vvv)
242243
hgvers[str(cset)] = vvv
243244

244245
if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
@@ -247,7 +248,7 @@ def getgitenv(user, date):
247248
# write the state for incrementals
248249
if state:
249250
if verbose:
250-
print 'Writing state'
251+
print('Writing state')
251252
f = open(state, 'w')
252253
pickle.dump(hgvers, f)
253254

git-p4.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
unicode = str
3737
bytes = bytes
3838
basestring = (str,bytes)
39+
raw_input = input
40+
from functools import reduce
3941
else:
4042
# 'unicode' exists, must be Python 2
4143
str = str
@@ -3968,6 +3970,7 @@ def renameBranch(self, branch_name):
39683970
break
39693971

39703972
if not found:
3973+
sync = P4Sync()
39713974
sys.exit("gave up trying to rename existing branch {0}".format(sync.branch))
39723975

39733976
def findLastP4Revision(self, starting_point):

0 commit comments

Comments
 (0)