pydot / pydot-ng

Python interface to Graphviz's Dot language compatible with Python 2 nad Python 3
MIT License
22 stars 10 forks source link

Restore compliance with the crusty "pydot" API #59

Open leycec opened 5 years ago

leycec commented 5 years ago

README.rst boldly claims that:

This library is API compatible with original pydot so you can use it like this: import pydot_ng as pydot

Of course, this hasn't been true for over three years; pydot-ng only adheres to the old pydot API. The new pydot API is considerably different. Downstream consumers that actually try to import pydot_ng as pydot are gonna have a Bad Time™.

Just Shoot Me Now

Notably, most top-level pydot functions and methods (e.g., pydot.graph_from_dot_data()) now unconditionally return a list of one or more Graph objects rather than conditionally returning either a single Graph object or a list of two or more Graph objects. To quote @johnyf in an ancient pydot issue:

An earlier version of the API used to return a graph object when the dot file defined one graph, and a list of graphs otherwise (in the case of more graphs). However, I found that the inhomogeneous behavior is more complex (simple is better than complex, PEP 20), so I changed it to return a list in all cases (e.g., a list containing one graph). This simplifies also user code, because there no case distinction needs to be made.

These are useful changes – but they do break backward compatibility. For conformance with the modern pydot API, it's critical that the pydot-ng API be refactored to behave similarly.

But... Can It Be Done?

It can! With perseverance and hideous suffering, anything is possible.

Since these API changes are largely undocumented, the simplest solution might be to:

  1. Integrate the most recent pydot test suite into the existing pydot-ng test suite.
  2. Manually fix each broken test – one by one.

For these purposes, test/pydot_unittest.py is the only useful file. Relevant unit tests include:

Godspeed You Intrepid Coder!

Best of luck, @prmtl. I'd submit a pull request resolving this, but we have our hands full just trying to survive the oncoming Canadian winter. Because in Canada, winter is always coming.

Perpetual snow and unyielding darkness. It isn't easy, folks. :snowflake: :snowman_with_snow: :mountain_snow: