Permalink
Browse files

Reviving OPy: run it on the Oil repository.

First problem: Convert print functions to use Python 3 style with
opy/fix.sh.

- Document how to get started.
- Remove a function related to Python 3, which we won't support.
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 24, 2018
1 parent 34c67e9 commit 69c0a077bcb70b8f3991a937708584919a5113f9
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
arith_ast_test.py: Tests for arith_ast.py
"""
@@ -121,9 +122,9 @@ def testConstructorType(self):
raise AssertionError("Should have failed")
def testProductType(self):
print
print '-- PRODUCT --'
print
print()
print('-- PRODUCT --')
print()
s = source_location()
s.path = 'hi'
@@ -141,9 +142,9 @@ def testSimpleSumType(self):
# TODO: Should be op_id_i.Plus -- instance
# Should be op_id_s.Plus
print
print '-- SIMPLE SUM --'
print
print()
print('-- SIMPLE SUM --')
print()
o = op_id_e.Plus
assert isinstance(o, py_meta.SimpleObj)
@@ -152,9 +153,9 @@ def testSimpleSumType(self):
assert isinstance(o.ASDL_TYPE, asdl_.Sum)
def testCompoundSumType(self):
print
print '-- COMPOUND SUM --'
print
print()
print('-- COMPOUND SUM --')
print()
# TODO: Should be cflow_t.Break() and cflow_i.Break
c = arith_ast.Break()
@@ -169,9 +170,9 @@ def testOtherTypes(self):
c = Const(66)
print(c)
print(Slice(Const(1), Const(5), Const(2)))
print((Slice(Const(1), Const(5), Const(2))))
print(op_id_e.Plus)
print((op_id_e.Plus))
# Class for sum type
print(arith_expr)
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
from asdl import tdop
from asdl import arith_ast
from asdl import arith_parse # module under test
@@ -178,15 +179,15 @@ def VisitChildren(self, node):
# TODO: Use node.ASDL_TYPE.GetFields()
# Only compound children get visited?
print [name for name in dir(node) if not name.startswith('_')]
print([name for name in dir(node) if not name.startswith('_')])
# Call self.Visit()!
class PrettyPrinter(Visitor):
def Visit(self, node):
if node.tag == arith_expr_e.ArithUnary:
print 'ArithUnary %s' % node.child
print('ArithUnary %s' % node.child)
else:
self.VisitChildren(node)
View
@@ -19,6 +19,8 @@
# [1] "The Zephyr Abstract Syntax Description Language" by Wang, et. al. See
# http://asdl.sourceforge.net/
#-------------------------------------------------------------------------------
from __future__ import print_function
import cStringIO
import re
@@ -132,7 +134,7 @@ def ByTypeName(self, type_name):
type_name: string, e.g. 'word_part' or 'LiteralPart'
"""
if not type_name in self.compound_types:
print 'FATAL', self.compound_types.keys()
print('FATAL: %s' % self.compound_types.keys())
return self.compound_types[type_name]
def __repr__(self):
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
py_meta_test.py: Tests for py_meta.py
"""
@@ -10,7 +11,7 @@
class AsdlTest(unittest.TestCase):
def testPyMeta(self):
print py_meta
print(py_meta)
if __name__ == '__main__':
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
pytrace.py
"""
@@ -70,8 +71,8 @@ def Stop(self, path):
# TODO:
# - report number of events?
# - report number of bytes?
print >>sys.stderr, 'num_events: %d' % self.num_events
print >>sys.stderr, 'Writing to %r' % path
print('num_events: %d' % self.num_events, file=sys.stderr)
print('Writing to %r' % path, file=sys.stderr)
with open(path, 'w') as f:
f.write(self.event_strs.getvalue())
@@ -80,7 +81,7 @@ def main(argv):
t = Tracer()
import urlparse
t.Start()
print urlparse.urlparse('http://example.com/foo')
print(urlparse.urlparse('http://example.com/foo'))
t.Stop('demo.pytrace')
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
c_module_srcs.py
"""
@@ -27,32 +28,32 @@ def main(argv):
if mod_name in ('libc', 'fastlex'): # Our own modules
# Relative to Python-2.7.13 dir
print '../native/%s.c' % mod_name
print('../native/%s.c' % mod_name)
elif mod_name == 'math':
print 'Modules/mathmodule.c'
print 'Modules/_math.c'
print('Modules/mathmodule.c')
print('Modules/_math.c')
elif mod_name == '_io':
# This data is in setup.py and Modules/Setup.dist.
#_io -I$(srcdir)/Modules/_io _io/bufferedio.c _io/bytesio.c
# _io/fileio.c _io/iobase.c _io/_iomodule.c _io/stringio.c
# _io/textio.c
print 'Modules/_io/bufferedio.c'
print 'Modules/_io/bytesio.c'
print 'Modules/_io/fileio.c'
print 'Modules/_io/iobase.c'
print 'Modules/_io/_iomodule.c'
print 'Modules/_io/stringio.c'
print 'Modules/_io/textio.c'
print('Modules/_io/bufferedio.c')
print('Modules/_io/bytesio.c')
print('Modules/_io/fileio.c')
print('Modules/_io/iobase.c')
print('Modules/_io/_iomodule.c')
print('Modules/_io/stringio.c')
print('Modules/_io/textio.c')
else:
print manifest[mod_name]
print(manifest[mod_name])
if __name__ == '__main__':
try:
main(sys.argv)
except RuntimeError as e:
print >>sys.stderr, 'FATAL: %s' % e
print('FATAL: %s' % e, file=sys.stderr)
sys.exit(1)
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
c_module_toc.py
"""
@@ -19,7 +20,7 @@ def main(argv):
for c_path in glob.glob('Modules/*.c') + glob.glob('Modules/_io/*.c'):
m = PURE_C_RE.match(c_path)
if m:
print m.group(1), c_path
print(m.group(1), c_path)
continue
m = HELPER_C_RE.match(c_path)
@@ -28,12 +29,12 @@ def main(argv):
# Special case:
if name == '_hashopenssl':
name = '_hashlib'
print name, c_path
print(name, c_path)
if __name__ == '__main__':
try:
main(sys.argv)
except RuntimeError as e:
print >>sys.stderr, 'FATAL: %s' % e
print('FATAL: %s' % e, file=sys.stderr)
sys.exit(1)
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
quick_ref.py
"""
@@ -166,11 +167,11 @@ def TableOfContents(f):
# TODO: Add version and so forht?
title_line = f.readline()
print '<h1>%s</h1>' % cgi.escape(title_line)
print '<a name="toc"></a>'
print('<h1>%s</h1>' % cgi.escape(title_line))
print('<a name="toc"></a>')
# doc/run.sh must set environment.
print '<i>Version %s</i>' % os.environ['OIL_VERSION']
print '<pre>'
print('<i>Version %s</i>' % os.environ['OIL_VERSION'])
print('<pre>')
for line in f:
if not line.strip():
@@ -193,7 +194,7 @@ def TableOfContents(f):
sys.stdout.write(html_line)
print '</pre>'
print('</pre>')
# TODO:
# - group 1: # prefix determines h1, h2, h3
@@ -240,7 +241,7 @@ def WriteFile(self, section_id, topics, lines):
HEADING_RE = re.compile(r'(#+) <(.*)>(.*)')
def Pages(f, text_out):
print '<pre>'
print('<pre>')
section_id = [0, 0, 0] # L1, L2, L3
topics = []
@@ -279,12 +280,12 @@ def Pages(f, text_out):
else:
raise RuntimeError('Invalid level %r' % level)
print '</pre>'
print('</pre>')
for topic in topics:
print '<a name="%s"></a>' % topic
print '<h%d>%s</h%d>' % (htag, text, htag)
print '<!-- %d.%d.%d -->' % tuple(section_id)
print '<pre>'
print('<a name="%s"></a>' % topic)
print('<h%d>%s</h%d>' % (htag, text, htag))
print('<!-- %d.%d.%d -->' % tuple(section_id))
print('<pre>')
prev_topics = topics
@@ -298,7 +299,7 @@ def Pages(f, text_out):
prev_lines.append(line)
continue
print '</pre>'
print('</pre>')
@@ -323,7 +324,7 @@ def main(argv):
f.write('TOPIC_LOOKUP = ')
f.write(d)
print >>sys.stderr, 'Wrote %s/ and %s' % (text_dir, py_out_path)
print('Wrote %s/ and %s' % (text_dir, py_out_path), file=sys.stderr)
else:
raise RuntimeError('Invalid action %r' % action)
@@ -333,5 +334,5 @@ def main(argv):
try:
main(sys.argv)
except RuntimeError as e:
print >>sys.stderr, 'FATAL: %s' % e
print('FATAL: %s' % e, file=sys.stderr)
sys.exit(1)
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
args.py - Flag, option, and arg parsing for the shell.
@@ -366,10 +367,10 @@ def __init__(self):
def PrintHelp(self, f):
print('[0]')
for ch in self.arity0:
print ch
print(ch)
print('[1]')
for ch in self.arity1:
print ch
print(ch)
def ShortFlag(self, short_name, arg_type=None):
"""
View
@@ -1,4 +1,5 @@
#!/usr/bin/python -S
from __future__ import print_function
"""
builtin_test.py: Tests for builtin.py
"""
@@ -13,9 +14,9 @@ class BuiltinTest(unittest.TestCase):
def testEchoLexer(self):
lex = builtin.ECHO_LEXER
print list(lex.Tokens(r'newline \n NUL \0 octal \0377 hex \x00'))
print list(lex.Tokens(r'unicode \u0065 \U00000065'))
print list(lex.Tokens(r'\d \e \f \g'))
print(list(lex.Tokens(r'newline \n NUL \0 octal \0377 hex \x00')))
print(list(lex.Tokens(r'unicode \u0065 \U00000065')))
print(list(lex.Tokens(r'\d \e \f \g')))
def testAppendParts(self):
# allow_escape is True by default, but False when the user passes -r.
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
glob_test.py: Tests for glob.py
"""
@@ -111,7 +112,7 @@ def testPatSubRegexesLibc(self):
print(r)
# It matches. But we need to get the positions out!
print libc.regex_match('^(.*)git.*(.*)', '~/git/oil')
print(libc.regex_match('^(.*)git.*(.*)', '~/git/oil'))
# Or should we make a match in a loop?
# We have to keep advancing the string until there are no more matches.
Oops, something went wrong.

0 comments on commit 69c0a07

Please sign in to comment.