Skip to content

ENH: better automatic code generation #155

@eriknw

Description

@eriknw

In the files grblas/_automethods.py and grblas/_infixmethods.py, we have code in the module docstrings that can be run to generate other code that is copy/pasted to other files.

It would be nice if this code generation were automated by e.g. running a Python file instead of error-prone copy/pasting. For example, in Scalar class, we could have:

    # Auto-generated from `python generate_automethods.py`: Scalar
    _get_value = _automethods._get_value
    __array__ = wrapdoc(Scalar.__array__)(property(_automethods.__array__))
    __bool__ = wrapdoc(Scalar.__bool__)(property(_automethods.__bool__))
    __complex__ = wrapdoc(Scalar.__complex__)(property(_automethods.__complex__))
    __eq__ = wrapdoc(Scalar.__eq__)(property(_automethods.__eq__))
    __float__ = wrapdoc(Scalar.__float__)(property(_automethods.__float__))
    __index__ = wrapdoc(Scalar.__index__)(property(_automethods.__index__))
    __int__ = wrapdoc(Scalar.__int__)(property(_automethods.__int__))
    __invert__ = wrapdoc(Scalar.__invert__)(property(_automethods.__invert__))
    __neg__ = wrapdoc(Scalar.__neg__)(property(_automethods.__neg__))
    _name_html = wrapdoc(Scalar._name_html)(property(_automethods._name_html))
    _nvals = wrapdoc(Scalar._nvals)(property(_automethods._nvals))
    gb_obj = wrapdoc(Scalar.gb_obj)(property(_automethods.gb_obj))
    is_empty = wrapdoc(Scalar.is_empty)(property(_automethods.is_empty))
    isclose = wrapdoc(Scalar.isclose)(property(_automethods.isclose))
    isequal = wrapdoc(Scalar.isequal)(property(_automethods.isequal))
    name = wrapdoc(Scalar.name)(property(_automethods.name))
    name = name.setter(_automethods._set_name)
    nvals = wrapdoc(Scalar.nvals)(property(_automethods.nvals))
    to_pygraphblas = wrapdoc(Scalar.to_pygraphblas)(property(_automethods.to_pygraphblas))
    value = wrapdoc(Scalar.value)(property(_automethods.value))
    wait = wrapdoc(Scalar.wait)(property(_automethods.wait))
    # These raise exceptions
    __and__ = wrapdoc(Scalar.__and__)(Scalar.__and__)
    __matmul__ = wrapdoc(Scalar.__matmul__)(Scalar.__matmul__)
    __or__ = wrapdoc(Scalar.__or__)(Scalar.__or__)
    __rand__ = wrapdoc(Scalar.__rand__)(Scalar.__rand__)
    __rmatmul__ = wrapdoc(Scalar.__rmatmul__)(Scalar.__rmatmul__)
    __ror__ = wrapdoc(Scalar.__ror__)(Scalar.__ror__)
    # End auto-generation

A low-tech solution could simply read every file, search for "# Auto-generated from... and # End auto-generation, match "Scalar" to know which code to generate, then replace the code within the two comments with the automatically generated code.

Such a solution may be helpful for dask-grblas too.

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