-
Notifications
You must be signed in to change notification settings - Fork 45
Description
As a long-time aggdraw user (and contributor!) I've always been a little annoyed that things like docstrings and API hints in IDEs don't work correctly with the package because it's a pure C++ module. Rewriting in Cython has been proposed (and would be much easier to maintain I'm sure), but that's a big undertaking with a lot of potential for breaking compatibility!
As I was doing some aggdraw stuff the other day I thought of a potential simpler solution: instead of rewriting the Aggdraw C++ code itself, simply migrate it into a module inside of a traditional Python package layout and then write some thin wrapper functions around all classes & functions in pure Python that internally calls the C++ stuff. For example, instead of exporting the C++ created Pen() object to the user directly, have a Pen() class in Python instead that internally creates a C++ Pen() instance and exposes its attributes with getters.
Imagining something like this:
class Draw(object):
def __init__(self, image_or_mode, size=None, color=WHITE):
if size:
self._draw = aggdraw.cpp.Draw(image_or_mode, size, color)
else:
self._draw = aggdraw.cpp.Draw(image_or_mode)
def arc(self, xy, start, end, pen=None):
self._draw.arc(xy, start, end, pen)The user-facing API should be able to stay the exact same, so it should be possible to migrate to this sort of setup without breaking backwards compatibility. Would also allow for things like better type checking too. It might take a while for me to find time, but if you're interested I could try putting together a proof-of-concept PR. Let me know what you think!