Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Py3k-compatible print statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimgr committed Jun 30, 2014
1 parent 886aa48 commit a5627c0
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion mkformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
source = fh.read()

statements = pymake.parser.parsestring(source, filename)
print statements.to_source()
print(statements.to_source())
4 changes: 2 additions & 2 deletions mkparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pymake.parser

for f in sys.argv[1:]:
print "Parsing %s" % f
print("Parsing %s" % f)
fd = open(f, 'rU')
s = fd.read()
fd.close()
stmts = pymake.parser.parsestring(s, f)
print stmts
print(stmts)
20 changes: 10 additions & 10 deletions pymake/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def parsemakeflags(env):
return opts

def _version(*args):
print """pymake: GNU-compatible make program
print("""pymake: GNU-compatible make program
Copyright (C) 2009 The Mozilla Foundation <http://www.mozilla.org/>
This is free software; see the source for copying conditions.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Expand All @@ -71,7 +71,7 @@ def _version(*args):
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE."""
DEALINGS IN THE SOFTWARE.""")

_log = logging.getLogger('pymake.execution')

Expand All @@ -95,7 +95,7 @@ def __init__(self, makeflags, makelevel, workdir, context, env, targets, options

def remakecb(self, remade, error=None):
if error is not None:
print error
print(error)
self.context.defer(self.cb, 2)
return

Expand Down Expand Up @@ -125,14 +125,14 @@ def remakecb(self, remade, error=None):
self.makefile.finishparsing()
self.makefile.remakemakefiles(self.remakecb)
except util.MakeError, e:
print e
print(e)
self.context.defer(self.cb, 2)

return

if len(self.targets) == 0:
if self.makefile.defaulttarget is None:
print "No target specified and no default target found."
print("No target specified and no default target found.")
self.context.defer(self.cb, 2)
return

Expand All @@ -154,7 +154,7 @@ def makecb(self, error, didanything):

if not len(self.realtargets):
if self.options.printdir:
print "make.py[%i]: Leaving directory '%s'" % (self.makelevel, self.workdir)
print("make.py[%i]: Leaving directory '%s'" % (self.makelevel, self.workdir))
sys.stdout.flush()

self.context.defer(self.cb, 0)
Expand Down Expand Up @@ -255,24 +255,24 @@ def main(args, env, cwd, cb):
context = process.getcontext(options.jobcount)

if options.printdir:
print "make.py[%i]: Entering directory '%s'" % (makelevel, workdir)
print("make.py[%i]: Entering directory '%s'" % (makelevel, workdir))
sys.stdout.flush()

if len(options.makefiles) == 0:
if os.path.exists(util.normaljoin(workdir, 'Makefile')):
options.makefiles.append('Makefile')
else:
print "No makefile found"
print("No makefile found")
cb(2)
return

ostmts, targets, overrides = parserdata.parsecommandlineargs(arguments)

_MakeContext(makeflags, makelevel, workdir, context, env, targets, options, ostmts, overrides, cb)
except (util.MakeError), e:
print e
print(e)
if options.printdir:
print "make.py[%i]: Leaving directory '%s'" % (makelevel, workdir)
print("make.py[%i]: Leaving directory '%s'" % (makelevel, workdir))
sys.stdout.flush()
cb(2)
return
10 changes: 5 additions & 5 deletions pymake/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def _depfinishedparallel(self, error, didanything):
assert error in (True, False)

if error:
print "<%s>: Found error" % self.target.target
print("<%s>: Found error" % self.target.target)
self.error = True
if didanything:
self.didanything = True
Expand Down Expand Up @@ -951,7 +951,7 @@ def runcommands(self, indent, cb):
try:
self.commands = [c for c in self.rule.getcommands(self.target, self.makefile)]
except util.MakeError, e:
print e
print(e)
sys.stdout.flush()
cb(error=True)
return
Expand Down Expand Up @@ -1286,7 +1286,7 @@ def make(self, makefile, targetstack, cb, avoidremakeloop=False, printerror=True
self.resolvedeps(makefile, targetstack, [], False)
except util.MakeError, e:
if printerror:
print e
print(e)
self.error = True
self.notifydone(makefile)
return
Expand Down Expand Up @@ -1398,7 +1398,7 @@ def __init__(self, cline, ignoreErrors, loc, context, **kwargs):

def _cb(self, res):
if res != 0 and not self.ignoreErrors:
print "%s: command '%s' failed, return code %i" % (self.loc, self.cline, res)
print("%s: command '%s' failed, return code %i" % (self.loc, self.cline, res))
self.usercb(error=True)
else:
self.usercb(error=False)
Expand Down Expand Up @@ -1597,7 +1597,7 @@ def remakecb(self, error, didanything):
'Error remaking required makefiles'))
return
else:
print 'Error remaking makefiles (ignored)'
print('Error remaking makefiles (ignored)')

if len(self.toremake):
target, self.required = self.toremake.pop(0)
Expand Down
5 changes: 3 additions & 2 deletions pymake/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Makefile functions.
"""
from __future__ import print_function

import parser, util
import subprocess, os, logging, sys
Expand Down Expand Up @@ -786,7 +787,7 @@ def resolve(self, makefile, variables, fd, setting):
p = subprocess.Popen(cline, executable=executable, env=makefile.env, shell=False,
stdout=subprocess.PIPE, cwd=makefile.workdir)
except OSError, e:
print >>sys.stderr, "Error executing command %s" % cline[0], e
print("Error executing command %s" % cline[0], e, file=sys.stderr)
return
finally:
os.environ['PATH'] = oldpath
Expand Down Expand Up @@ -830,7 +831,7 @@ class InfoFunction(Function):

def resolve(self, makefile, variables, fd, setting):
v = self._arguments[0].resolvestr(makefile, variables, setting)
print v
print(v)

functionmap = {
'subst': SubstFunction,
Expand Down
28 changes: 15 additions & 13 deletions pymake/parserdata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import logging, re, os
import data, parser, functions, util
from cStringIO import StringIO
Expand Down Expand Up @@ -207,7 +209,7 @@ def _execute(self, makefile, context):
context.currule = rule

def dump(self, fd, indent):
print >>fd, "%sRule %s: %s" % (indent, self.targetexp, self.depexp)
print("%sRule %s: %s" % (indent, self.targetexp, self.depexp), file=fd)

def to_source(self):
sep = ':'
Expand Down Expand Up @@ -285,7 +287,7 @@ def execute(self, makefile, context):
context.currule = rule

def dump(self, fd, indent):
print >>fd, "%sStaticPatternRule %s: %s: %s" % (indent, self.targetexp, self.patternexp, self.depexp)
print("%sStaticPatternRule %s: %s: %s" % (indent, self.targetexp, self.patternexp, self.depexp), file=fd)

def to_source(self):
sep = ':'
Expand Down Expand Up @@ -339,7 +341,7 @@ def execute(self, makefile, context):
context.currule.addcommand(self.exp)

def dump(self, fd, indent):
print >>fd, "%sCommand %s" % (indent, self.exp,)
print("%sCommand %s" % (indent, self.exp,), file=fd)

def to_source(self):
# Commands have some interesting quirks when it comes to source
Expand Down Expand Up @@ -438,7 +440,7 @@ def execute(self, makefile, context):
v.set(vname, flavor, self.source, value)

def dump(self, fd, indent):
print >>fd, "%sSetVariable<%s> %s %s\n%s %r" % (indent, self.valueloc, self.vnameexp, self.token, indent, self.value)
print("%sSetVariable<%s> %s %s\n%s %r" % (indent, self.valueloc, self.vnameexp, self.token, indent, self.value), file=fd)

def __eq__(self, other):
if not isinstance(other, SetVariable):
Expand Down Expand Up @@ -651,14 +653,14 @@ def execute(self, makefile, context):
i += 1

def dump(self, fd, indent):
print >>fd, "%sConditionBlock" % (indent,)
print("%sConditionBlock" % (indent,), file=fd)

indent2 = indent + ' '
for c, statements in self._groups:
print >>fd, "%s Condition %s" % (indent, c)
print("%s Condition %s" % (indent, c), file=fd)
statements.dump(fd, indent2)
print >>fd, "%s ~Condition" % (indent,)
print >>fd, "%s~ConditionBlock" % (indent,)
print("%s ~Condition" % (indent,), file=fd)
print("%s~ConditionBlock" % (indent,), file=fd)

def to_source(self):
lines = []
Expand Down Expand Up @@ -793,7 +795,7 @@ def execute(self, makefile, context):
makefile.include(f, self.required, loc=self.exp.loc, weak=self.weak)

def dump(self, fd, indent):
print >>fd, "%sInclude %s" % (indent, self.exp)
print("%sInclude %s" % (indent, self.exp), file=fd)

def to_source(self):
prefix = ''
Expand Down Expand Up @@ -840,7 +842,7 @@ def execute(self, makefile, context):
makefile.addvpath(pattern, dirs)

def dump(self, fd, indent):
print >>fd, "%sVPath %s" % (indent, self.exp)
print("%sVPath %s" % (indent, self.exp), file=fd)

def to_source(self):
return 'vpath %s' % self.exp.to_source()
Expand Down Expand Up @@ -885,7 +887,7 @@ def execute(self, makefile, context):
makefile.exportedvars[v] = True

def dump(self, fd, indent):
print >>fd, "%sExport (single=%s) %s" % (indent, self.single, self.exp)
print("%sExport (single=%s) %s" % (indent, self.single, self.exp), file=fd)

def to_source(self):
return ('export %s' % self.exp.to_source()).rstrip()
Expand Down Expand Up @@ -915,7 +917,7 @@ def execute(self, makefile, context):
makefile.exportedvars[v] = False

def dump(self, fd, indent):
print >>fd, "%sUnexport %s" % (indent, self.exp)
print("%sUnexport %s" % (indent, self.exp), file=fd)

def to_source(self):
return 'unexport %s' % self.exp.to_source()
Expand Down Expand Up @@ -947,7 +949,7 @@ def execute(self, makefile, context):
raise data.DataError("Line expands to non-empty value", self.exp.loc)

def dump(self, fd, indent):
print >>fd, "%sEmptyDirective: %s" % (indent, self.exp)
print("%sEmptyDirective: %s" % (indent, self.exp), file=fd)

def to_source(self):
return self.exp.to_source()
Expand Down
19 changes: 10 additions & 9 deletions pymake/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Skipping shell invocations is good, when possible. This wrapper around subprocess does dirty work of
parsing command lines into argv and making sure that no shell magic is being used.
"""
from __future__ import print_function

#TODO: ship pyprocessing?
import multiprocessing
Expand Down Expand Up @@ -332,7 +333,7 @@ def run(self):
p = subprocess.Popen(self.argv, executable=self.executable, shell=self.shell, env=self.env, cwd=self.cwd)
return p.wait()
except OSError, e:
print >>sys.stderr, e
print(e, file=sys.stderr)
return -127
finally:
os.environ['PATH'] = oldpath
Expand Down Expand Up @@ -383,30 +384,30 @@ def run(self):
try:
__import__(self.module)
except Exception as e:
print >>sys.stderr, 'Error importing %s: %s' % (
self.module, e)
print('Error importing %s: %s' % (
self.module, e), file=sys.stderr)
return -127

m = sys.modules[self.module]
if self.method not in m.__dict__:
print >>sys.stderr, "No method named '%s' in module %s" % (self.method, self.module)
print("No method named '%s' in module %s" % (self.method, self.module), file=sys.stderr)
return -127
rv = m.__dict__[self.method](self.argv)
if rv != 0 and rv is not None:
print >>sys.stderr, (
print((
"Native command '%s %s' returned value '%s'" %
(self.module, self.method, rv))
(self.module, self.method, rv)), file=sys.stderr)
return (rv if isinstance(rv, int) else 1)

except PythonException, e:
print >>sys.stderr, e
print(e, file=sys.stderr)
return e.exitcode
except:
e = sys.exc_info()[1]
if isinstance(e, SystemExit) and (e.code == 0 or e.code is None):
pass # sys.exit(0) is not a failure
else:
print >>sys.stderr, e
print(e, file=sys.stderr)
traceback.print_exc()
return -127
finally:
Expand Down Expand Up @@ -461,7 +462,7 @@ def defer(self, cb, *args, **kwargs):

def _docall_generic(self, pool, job, cb, echo, justprint):
if echo is not None:
print echo
print(echo)
processcb = job.get_callback(ParallelContext._condition)
if justprint:
processcb(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/parsertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def runSingle(self, ifunc, idata, expected):
self.assertEqual(actual, expected)

if ifunc == pymake.parser.itermakefilechars:
print "testing %r" % expected
print("testing %r" % expected)
self.assertEqual(pymake.parser.flattenmakesyntax(d, 0), expected)

multitest(IterTest)
Expand Down
Loading

0 comments on commit a5627c0

Please sign in to comment.