Bug#614505: Patch for this feature request

Thomas Goirand zigo at debian.org
Tue Oct 24 21:43:57 UTC 2017


On 10/24/2017 10:02 PM, Emmanuel Bourg wrote:
> Le 24/10/2017 à 19:16, Thomas Goirand a écrit :
> 
>> Here's a patch adding Python 3 support to the package. This also patches
>> antlr.py, and also packages the proper way, ie with a produced egg-info
>> file as it should.
>>
>> Please consider uploading this fix. This is needed, and would allow
>> adding Python 3 support to 2 other packages which indirectly need this.
>>
>> Alternatively, please allow me to NMU.
> 
> Thank you for the help Thomas. I can't see the patch attached, could you
> send it again please?
> 
> A team upload would be preferable to a NMU. You are already a member of
> the pkg-java group, so feel free to commit to the repository directly
> and upload the update.
> 
> The repository has been migrated to Git today:
> 
> https://anonscm.debian.org/cgit/pkg-java/antlr.git

Here's the patch, sorry for this.

Let me know if I can upload as per this debdiff.

Cheers,

Thomas Goirand
-------------- next part --------------
diff -Nru antlr-2.7.7+dfsg/debian/changelog antlr-2.7.7+dfsg/debian/changelog
--- antlr-2.7.7+dfsg/debian/changelog	2016-01-27 08:27:30.000000000 +0000
+++ antlr-2.7.7+dfsg/debian/changelog	2017-10-24 14:46:42.000000000 +0000
@@ -1,3 +1,10 @@
+antlr (2.7.7+dfsg-7.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Add Python 3 support.
+
+ -- Thomas Goirand <zigo at debian.org>  Tue, 24 Oct 2017 14:46:42 +0000
+
 antlr (2.7.7+dfsg-7) unstable; urgency=medium
 
   * Team upload.
diff -Nru antlr-2.7.7+dfsg/debian/control antlr-2.7.7+dfsg/debian/control
--- antlr-2.7.7+dfsg/debian/control	2016-01-27 08:01:06.000000000 +0000
+++ antlr-2.7.7+dfsg/debian/control	2017-10-24 14:46:42.000000000 +0000
@@ -3,7 +3,7 @@
 Priority: optional
 Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.org>
 Uploaders: Torsten Werner <twerner at debian.org>
-Build-Depends: debhelper (>= 9), default-jdk, python (>= 2.6.6-3~), autotools-dev, python-all-dev (>= 2.3.5-11), sharutils
+Build-Depends: debhelper (>= 9), default-jdk, python (>= 2.6.6-3~), autotools-dev, python-all-dev (>= 2.3.5-11), sharutils, python3-all-dev, python-setuptools, python3-setuptools, dh-python
 Build-Depends-Indep: maven-repo-helper
 Standards-Version: 3.9.6
 Vcs-Svn: svn://anonscm.debian.org/pkg-java/trunk/antlr
@@ -74,12 +74,21 @@
 Package: python-antlr
 Section: python
 Architecture: all
-Depends: ${misc:Depends}, ${python:Depends}
+Depends: python-six, ${misc:Depends}, ${python:Depends}
 Replaces: antlr (<< 2.7.7-10)
 Breaks: antlr (<< 2.7.7-10)
-Description: language tool for constructing recognizers, compilers etc
- This package contains the Python version of antlr. ANTLR stands for
+Description: language tool for constructing recognizers, compilers etc - Python 2.7
+ This package contains the Python 2.7 version of antlr. ANTLR stands for
  ANother Tool for Language Recognition, (formerly PCCTS).
  .
  See antlr package for a complete description.
 
+Package: python3-antlr
+Section: python
+Architecture: all
+Depends: python3-six, ${misc:Depends}, ${python3:Depends}
+Description: language tool for constructing recognizers, compilers etc - Python 3.x
+ This package contains the Python 3.x version of antlr. ANTLR stands for
+ ANother Tool for Language Recognition, (formerly PCCTS).
+ .
+ See antlr package for a complete description.
diff -Nru antlr-2.7.7+dfsg/debian/patches/python3-compat.patch antlr-2.7.7+dfsg/debian/patches/python3-compat.patch
--- antlr-2.7.7+dfsg/debian/patches/python3-compat.patch	1970-01-01 00:00:00.000000000 +0000
+++ antlr-2.7.7+dfsg/debian/patches/python3-compat.patch	2017-10-24 14:46:42.000000000 +0000
@@ -0,0 +1,297 @@
+Description: Python3 compat
+Author: Thomas Goirand <zigo at debian.org>
+Bug-Debian: https://bugs.debian.org/614505
+Forwarded: no
+Last-Update: 2017-10-24
+
+--- antlr-2.7.7+dfsg.orig/lib/python/antlr/antlr.py
++++ antlr-2.7.7+dfsg/lib/python/antlr/antlr.py
+@@ -2,13 +2,11 @@
+ ## details..........Copyright (C) Wolfgang Haefelinger, 2004.
+ 
+ ## get sys module
++from __future__ import print_function
+ import sys
+ 
+-version = sys.version.split()[0]
+-if version < '2.2.1':
+-    False = 0
+-if version < '2.3':
+-    True = not False
++import six
++from six.moves import range
+ 
+ ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+ ###                     global symbols                             ###
+@@ -45,7 +43,7 @@ def version():
+ 
+ def error(fmt,*args):
+     if fmt:
+-        print "error: ", fmt % tuple(args)
++        print("error: ", fmt % tuple(args))
+ 
+ def ifelse(cond,_then,_else):
+     if cond :
+@@ -55,7 +53,7 @@ def ifelse(cond,_then,_else):
+     return r
+ 
+ def is_string_type(x):
+-    return  (isinstance(x,str) or isinstance(x,unicode))
++    return  (isinstance(x,str) or isinstance(x,six.text_type))
+ 
+ def assert_string_type(x):
+     assert is_string_type(x)
+@@ -549,9 +547,9 @@ class Token(object):
+ Token.badToken = Token( type=INVALID_TYPE, text="<no text>")
+ 
+ if __name__ == "__main__":
+-    print "testing .."
++    print("testing ..")
+     T = Token.badToken
+-    print T
++    print(T)
+ 
+ ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+ ###                       CommonToken                              ###
+@@ -622,16 +620,16 @@ class CommonToken(Token):
+ 
+ if __name__ == '__main__' :
+     T = CommonToken()
+-    print T
++    print(T)
+     T = CommonToken(col=15,line=1,text="some text", type=5)
+-    print T
++    print(T)
+     T = CommonToken()
+     T.setLine(1).setColumn(15).setText("some text").setType(5)
+-    print T
+-    print T.getLine()
+-    print T.getColumn()
+-    print T.getText()
+-    print T.getType()
++    print(T)
++    print(T.getLine())
++    print(T.getColumn())
++    print(T.getText())
++    print(T.getType())
+ 
+ ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+ ###                    CommonHiddenStreamToken                     ###
+@@ -811,7 +809,7 @@ class CharBuffer(InputBuffer):
+ 
+                 ### use unicode chars instead of ASCII ..
+                 self.queue.append(c)
+-        except Exception,e:
++        except Exception as e:
+             raise CharStreamIOException(e)
+         ##except: # (mk) Cannot happen ...
+             ##error ("unexpected exception caught ..")
+@@ -901,7 +899,7 @@ class TokenStreamSelector(TokenStream):
+         while 1:
+             try:
+                 return self._input.nextToken()
+-            except TokenStreamRetryException,r:
++            except TokenStreamRetryException as r:
+                 ### just retry "forever"
+                 pass
+ 
+@@ -1342,23 +1340,23 @@ class CharScanner(TokenStream):
+         self.setColumn(nc)
+ 
+     def panic(self,s='') :
+-        print "CharScanner: panic: " + s
++        print("CharScanner: panic: " + s)
+         sys.exit(1)
+ 
+     def reportError(self,ex) :
+-        print ex
++        print(ex)
+ 
+     def reportError(self,s) :
+         if not self.getFilename():
+-            print "error: " + str(s)
++            print("error: " + str(s))
+         else:
+-            print self.getFilename() + ": error: " + str(s)
++            print(self.getFilename() + ": error: " + str(s))
+ 
+     def reportWarning(self,s) :
+         if not self.getFilename():
+-            print "warning: " + str(s)
++            print("warning: " + str(s))
+         else:
+-            print self.getFilename() + ": warning: " + str(s)
++            print(self.getFilename() + ": warning: " + str(s))
+ 
+     def resetText(self) :
+         self.text.setLength(0)
+@@ -1418,16 +1416,16 @@ class CharScanner(TokenStream):
+         return c.__class__.lower()
+ 
+     def traceIndent(self):
+-        print ' ' * self.traceDepth
++        print(' ' * self.traceDepth)
+ 
+     def traceIn(self,rname):
+         self.traceDepth += 1
+         self.traceIndent()
+-        print "> lexer %s c== %s" % (rname,self.LA(1))
++        print("> lexer %s c== %s" % (rname,self.LA(1)))
+ 
+     def traceOut(self,rname):
+         self.traceIndent()
+-        print "< lexer %s c== %s" % (rname,self.LA(1))
++        print("< lexer %s c== %s" % (rname,self.LA(1)))
+         self.traceDepth -= 1
+ 
+     def uponEOF(self):
+@@ -1492,7 +1490,7 @@ class CharScanner(TokenStream):
+                 func=args[0]
+                 args=args[1:]
+                 apply(func,args)
+-            except RecognitionException, e:
++            except RecognitionException as e:
+                 ## catastrophic failure
+                 self.reportError(e);
+                 self.consume();
+@@ -1548,7 +1546,7 @@ class BitSet(object):
+ 
+     def __init__(self,data=None):
+         if not data:
+-            BitSet.__init__(self,[long(0)])
++            BitSet.__init__(self,[0])
+             return
+         if isinstance(data,int):
+             BitSet.__init__(self,[long(data)])
+@@ -1568,7 +1566,7 @@ class BitSet(object):
+     def __str__(self):
+         bits = len(self.data) * BitSet.BITS
+         s = ""
+-        for i in xrange(0,bits):
++        for i in range(0,bits):
+             if self.at(i):
+                 s += "1"
+             else:
+@@ -1607,7 +1605,7 @@ class BitSet(object):
+ 
+     def bitMask(self,bit):
+         pos = bit & BitSet.MOD_MASK  ## bit mod BITS
+-        return (1L << pos)
++        return (1 << pos)
+ 
+     def set(self,bit,on=True):
+         # grow bitset as required (use with care!)
+@@ -1615,8 +1613,8 @@ class BitSet(object):
+         mask = self.bitMask(bit)
+         if i>=len(self.data):
+             d = i - len(self.data) + 1
+-            for x in xrange(0,d):
+-                self.data.append(0L)
++            for x in range(0,d):
++                self.data.append(0)
+             assert len(self.data) == i+1
+         if on:
+             self.data[i] |=  mask
+@@ -1908,16 +1906,16 @@ class Parser(object):
+             col  = x.getLine()
+             text = x.getText()
+             fmt  = fmt + 'unexpected symbol at line %s (column %s) : "%s"'
+-            print >>sys.stderr, fmt % (line,col,text)
++            print(fmt % (line,col,text), file=sys.stderr)
+         else:
+-            print >>sys.stderr, fmt,str(x)
++            print(fmt,str(x), file=sys.stderr)
+ 
+     def reportWarning(self,s):
+         f = self.getFilename()
+         if f:
+-            print "%s:warning: %s" % (f,str(x))
++            print("%s:warning: %s" % (f,str(x)))
+         else:
+-            print "warning: %s" % (str(x))
++            print("warning: %s" % (str(x)))
+ 
+     def rewind(self, pos) :
+         self.inputState.input.rewind(pos)
+@@ -1945,7 +1943,7 @@ class Parser(object):
+         self.inputState.input = t
+ 
+     def traceIndent(self):
+-        print " " * self.traceDepth
++        print(" " * self.traceDepth)
+ 
+     def traceIn(self,rname):
+         self.traceDepth += 1
+@@ -2034,20 +2032,20 @@ class LLkParser(Parser):
+             self.k = 1
+ 
+     def trace(self,ee,rname):
+-        print type(self)
++        print(type(self))
+         self.traceIndent()
+         guess = ""
+         if self.inputState.guessing > 0:
+             guess = " [guessing]"
+         print(ee + rname + guess)
+-        for i in xrange(1,self.k+1):
++        for i in range(1,self.k+1):
+             if i != 1:
+                 print(", ")
+             if self.LT(i) :
+                 v = self.LT(i).getText()
+             else:
+                 v = "null"
+-            print "LA(%s) == %s" % (i,v)
++            print("LA(%s) == %s" % (i,v))
+         print("\n")
+ 
+     def traceIn(self,rname):
+@@ -2108,10 +2106,10 @@ class TreeParser(object):
+             raise MismatchedTokenException(getTokenNames(), t, ttype, True)
+ 
+     def reportError(self,ex):
+-        print >>sys.stderr,"error:",ex
++        print("error:",ex, file=sys.stderr)
+ 
+     def  reportWarning(self, s):
+-        print "warning:",s
++        print("warning:",s)
+ 
+     def setASTFactory(self,f):
+         self.astFactory = f
+@@ -2123,7 +2121,7 @@ class TreeParser(object):
+         self.astFactory.setASTNodeType(nodeType)
+ 
+     def traceIndent(self):
+-        print " " * self.traceDepth
++        print(" " * self.traceDepth)
+ 
+     def traceIn(self,rname,t):
+         self.traceDepth += 1
+@@ -2683,7 +2681,7 @@ class ASTFactory(object):
+ 
+     def error(self, e):
+         import sys
+-        print >> sys.stderr, e
++        print(e, file=sys.stderr)
+ 
+     def setTokenTypeASTNodeType(self, tokenType, className):
+         """
+@@ -2770,7 +2768,7 @@ def make(*nodes):
+     if not nodes:
+         return None
+ 
+-    for i in xrange(0,len(nodes)):
++    for i in range(0,len(nodes)):
+         node = nodes[i]
+         if node:
+             assert isinstance(node,AST)
+@@ -2780,7 +2778,7 @@ def make(*nodes):
+     if root:
+         root.setFirstChild(None)
+ 
+-    for i in xrange(1,len(nodes)):
++    for i in range(1,len(nodes)):
+         if not nodes[i]:
+             continue
+         if not root:
diff -Nru antlr-2.7.7+dfsg/debian/patches/series antlr-2.7.7+dfsg/debian/patches/series
--- antlr-2.7.7+dfsg/debian/patches/series	2016-01-27 08:02:02.000000000 +0000
+++ antlr-2.7.7+dfsg/debian/patches/series	2017-10-24 14:46:42.000000000 +0000
@@ -1,3 +1,4 @@
 gcc.diff
 bin___antlr.diff
 antlr-config.patch
+python3-compat.patch
diff -Nru antlr-2.7.7+dfsg/debian/rules antlr-2.7.7+dfsg/debian/rules
--- antlr-2.7.7+dfsg/debian/rules	2016-01-27 08:19:16.000000000 +0000
+++ antlr-2.7.7+dfsg/debian/rules	2017-10-24 14:46:42.000000000 +0000
@@ -3,6 +3,8 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
+PYTHON3S:=$(shell py3versions -vr 2>/dev/null)
+
 PACKAGE     := antlr
 VERSION		:= $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2 | cut -d- -f1 | cut -d+ -f1)
 
@@ -56,6 +58,8 @@
 	-rm -f debian/antlr.snk
 	-rm -rf debian/.wapi
 	-rm -rf debian/tmp
+	-rm -rf lib/python/build
+	-rm -rf scripts/run-antlr
 	dh_clean
 
 install-indep: build-indep
@@ -69,8 +73,11 @@
 	mv debian/antlr/usr/share/java/* debian/libantlr-java/usr/share/java/
 	rmdir debian/antlr/usr/share/java/
 	mkdir -p debian/python-antlr/usr/lib/$$(pyversions -d)/dist-packages
-	install -m644 lib/python/antlr/antlr.py \
-		debian/python-antlr/usr/lib/$$(pyversions -d)/dist-packages/.
+
+	set -e && cd lib/python && python setup.py install --install-layout=deb --root $(CURDIR)/debian/python-antlr && cd ..
+	set -e && cd lib/python && for pyvers in $(PYTHON3S); do \
+		python$$pyvers setup.py install --install-layout=deb --root $(CURDIR)/debian/python3-antlr ; \
+	done && cd ..
 	install -m644 -D CHANGES.txt debian/antlr/usr/share/doc/antlr/changelog
 	install -m644 -D CHANGES.txt debian/antlr-doc/usr/share/doc/antlr-doc/changelog
 	mh_installpoms -plib$(PACKAGE)-java
@@ -130,14 +137,23 @@
 	dh_builddeb -plibantlr-java
 	# python-antlr
 	dh_installdocs -ppython-antlr
+	dh_installdocs -ppython3-antlr
 	dh_installchangelogs -ppython-antlr
+	dh_installchangelogs -ppython3-antlr
 	dh_python2 -ppython-antlr
+	dh_python3 -ppython3-antlr
 	dh_compress -ppython-antlr
+	dh_compress -ppython3-antlr
 	dh_fixperms -ppython-antlr
+	dh_fixperms -ppython3-antlr
 	dh_installdeb -ppython-antlr
+	dh_installdeb -ppython3-antlr
 	dh_gencontrol -ppython-antlr
+	dh_gencontrol -ppython3-antlr
 	dh_md5sums -ppython-antlr
+	dh_md5sums -ppython3-antlr
 	dh_builddeb -ppython-antlr
+	dh_builddeb -ppython3-antlr
 
 
 binary-arch: build install


More information about the pkg-java-maintainers mailing list