Skip to content

Reorganize to provide pure-Python wrappers around C++ functions/objects? #118

@a-hurst

Description

@a-hurst

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!

Relevant to #72 and #43.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions