cudadog / pydot

Automatically exported from code.google.com/p/pydot
MIT License
0 stars 0 forks source link

Python 3 compatibility #76

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The Python 3-compatible branch mentioned on the project home page is over a 
year old, so apparently it's not kept up-to-date with pydot development. The 
latest tag is for version 1.0.15, whereas 1.0.28 is the current version of 
pydot.

Python 3 is becoming more and more mainstream, especially for new projects. It 
would be very nice to be able to use pydot in Python 3.x projects too.

Original issue reported on code.google.com by syb...@stuvel.eu on 5 Nov 2012 at 1:43

GoogleCodeExporter commented 9 years ago
PS: the unittests on the mentioned Python 3 branch don't run on Python 3, so 
it's doubtful whether the port is actually compatible.

Original comment by syb...@stuvel.eu on 5 Nov 2012 at 2:19

GoogleCodeExporter commented 9 years ago
This is the patch I'm going to apply to the Debian packaging.

Original comment by sandro.tosi on 12 Mar 2014 at 10:01

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
in the above patch there's still a bug in the write* functions, bad playing 
with bytes/strings

Original comment by sandro.tosi on 12 Mar 2014 at 10:09

GoogleCodeExporter commented 9 years ago
I've improved the provious patch a bit by replacing file() with open()

Original comment by sandro.tosi on 22 Mar 2014 at 2:28

Attachments:

GoogleCodeExporter commented 9 years ago
here are some crashed with this patch (don't have time to fix them):

When I call pydot.graph_from_dot_data() with str, it fails with:

Traceback (most recent call last):
  File "routing/graph-reach-simple-add-state.py", line 19, in <module>
    graph = pydot.graph_from_dot_data(args.dot.read())
  File "/usr/lib/python3/dist-packages/pydot.py", line 220, in graph_from_dot_data
    return dot_parser.parse_dot_data(data)
  File "/usr/lib/python3/dist-packages/dot_parser.py", line 510, in parse_dot_data
    if data.startswith(codecs.BOM_UTF8):
TypeError: startswith first arg must be str or a tuple of str, not bytes

and when I call it with bytes, it fails with:

Traceback (most recent call last):
  File "routing/graph-reach-simple-add-state.py", line 19, in <module>
    graph = pydot.graph_from_dot_data(args.dot.read())
  File "/usr/lib/python3/dist-packages/pydot.py", line 220, in graph_from_dot_data
    return dot_parser.parse_dot_data(data)
  File "/usr/lib/python3/dist-packages/dot_parser.py", line 520, in parse_dot_data
    tokens = graphparser.parseString(data)
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 1031, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 899, in _parseNoCache
    preloc = self.preParse( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 856, in preParse
    loc = self._skipIgnorables( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 848, in _skipIgnorables
    loc,dummy = e._parse( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 905, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 2543, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 905, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 1758, in parseImpl
    result = self.re.match(instring,loc)
TypeError: can't use a string pattern on a bytes-like object

This worked in python2, because it autoconverted between str and unicode, but python3 does not. The test in the first failure is inappropriate if the passed object is of type str.


and

When I call pydot.graph_from_dot_data() with str argument, I get:

Traceback (most recent call last):
  File "routing/graph-reach-simple-add-state.py", line 19, in <module>
    graph = pydot.graph_from_dot_data(args.dot.read())
  File "/usr/lib/python3/dist-packages/pydot.py", line 220, in graph_from_dot_data
    return dot_parser.parse_dot_data(data)
  File "/usr/lib/python3/dist-packages/dot_parser.py", line 510, in parse_dot_data
    if data.startswith(codecs.BOM_UTF8):
TypeError: startswith first arg must be str or a tuple of str, not bytes

and when I call it with bytes argument, I get:

Traceback (most recent call last):
  File "routing/graph-reach-simple-add-state.py", line 19, in <module>
    graph = pydot.graph_from_dot_data(args.dot.read())
  File "/usr/lib/python3/dist-packages/pydot.py", line 220, in graph_from_dot_data
    return dot_parser.parse_dot_data(data)
  File "/usr/lib/python3/dist-packages/dot_parser.py", line 520, in parse_dot_data
    tokens = graphparser.parseString(data)
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 1031, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 899, in _parseNoCache
    preloc = self.preParse( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 856, in preParse
    loc = self._skipIgnorables( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 848, in _skipIgnorables
    loc,dummy = e._parse( instring, loc )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 905, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 2543, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 905, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 1758, in parseImpl
    result = self.re.match(instring,loc)
TypeError: can't use a string pattern on a bytes-like object

This worked in python2, because it auto-converted between str and unicode, but python3 does not.

Original comment by sandro.tosi on 19 Apr 2014 at 11:47

GoogleCodeExporter commented 9 years ago
Here is another vote. This little package is not Python3-compatible, and the 
allegedly Py3-compatible branch isn't either, nor is it maintained. I get the 
same errors ("data.startswith(codecs.BOM_UTF8)" bombs as shown, no matter which 
quick'n'dirty fix you try).

Original comment by twang...@gmail.com on 3 Jun 2014 at 12:50

GoogleCodeExporter commented 9 years ago
Any news? There are plenty of python3 compatible forks, but of course none of 
them in pypi. Is there any chance to get python3 compatible version in pypi?

Original comment by mike@chaliy.name on 10 Jul 2014 at 4:41

GoogleCodeExporter commented 9 years ago
+1 for a standard Python 3 pypi release please. I teach using Python 3, I use 
pydot for scikit learn decision tree output. I stopped using & teaching Python 
2.7 earlier this year, Py2.7 has 5 years or so to live as the sunset date is 
2020. Python 3.4+ is the sensible way forwards.

Original comment by ianozsv...@gmail.com on 28 Oct 2014 at 5:55

GoogleCodeExporter commented 9 years ago
Please just merge this fork and upload a Python 3 compatible version.

It's almost 2015!

https://github.com/nlhepler/pydot

Original comment by trueflyi...@gmail.com on 2 Dec 2014 at 7:56