From eb9f674d2df0425925eaad98b64e4dbd01405d69 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 8 Oct 2024 18:22:36 +0000 Subject: [PATCH 1/2] #13 Update example template syntax --- examples/shapes/src/py/pyshapes/_syntax.py | 17 ++++++++++++----- .../shapes/src/py/pyshapes/geometry/__init__.py | 4 ++-- .../shapes/src/py/pyshapes/mesh/__init__.py | 6 +++--- .../src/py/pyshapes/primitives/__init__.py | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/shapes/src/py/pyshapes/_syntax.py b/examples/shapes/src/py/pyshapes/_syntax.py index ef6da94..2afd7e6 100644 --- a/examples/shapes/src/py/pyshapes/_syntax.py +++ b/examples/shapes/src/py/pyshapes/_syntax.py @@ -1,18 +1,25 @@ +import inspect from collections.abc import Iterable -class ClassDict: +class TemplateClassDict: def __init__(self, template_dict): self._dict = {} - for arg_tuple, clas in template_dict.items(): + for arg_tuple, cls in template_dict.items(): + if not inspect.isclass(cls): + raise TypeError("Expected class, got {}".format(type(cls))) if not isinstance(arg_tuple, Iterable): arg_tuple = (arg_tuple,) - key = tuple(str(arg) for arg in arg_tuple) - self._dict[key] = clas + key = tuple( + arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple + ) + self._dict[key] = cls def __getitem__(self, arg_tuple): if not isinstance(arg_tuple, Iterable): arg_tuple = (arg_tuple,) - key = tuple(str(arg) for arg in arg_tuple) + key = tuple( + arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple + ) return self._dict[key] diff --git a/examples/shapes/src/py/pyshapes/geometry/__init__.py b/examples/shapes/src/py/pyshapes/geometry/__init__.py index f2e6185..a09b8a9 100644 --- a/examples/shapes/src/py/pyshapes/geometry/__init__.py +++ b/examples/shapes/src/py/pyshapes/geometry/__init__.py @@ -1,8 +1,8 @@ # Bring in everything from the shared module -from pyshapes._syntax import ClassDict +from pyshapes._syntax import TemplateClassDict from pyshapes.geometry._pyshapes_geometry import * -Point = ClassDict( +Point = TemplateClassDict( { 2: Point_2, 3: Point_3, diff --git a/examples/shapes/src/py/pyshapes/mesh/__init__.py b/examples/shapes/src/py/pyshapes/mesh/__init__.py index 1a0fa99..a976af6 100644 --- a/examples/shapes/src/py/pyshapes/mesh/__init__.py +++ b/examples/shapes/src/py/pyshapes/mesh/__init__.py @@ -1,15 +1,15 @@ # Bring in everything from the shared module -from pyshapes._syntax import ClassDict +from pyshapes._syntax import TemplateClassDict from pyshapes.mesh._pyshapes_mesh import * -AbstractMesh = ClassDict( +AbstractMesh = TemplateClassDict( { (2, 2): AbstractMesh_2_2, (3, 3): AbstractMesh_3_3, } ) -ConcreteMesh = ClassDict( +ConcreteMesh = TemplateClassDict( { 2: ConcreteMesh_2, 3: ConcreteMesh_3, diff --git a/examples/shapes/src/py/pyshapes/primitives/__init__.py b/examples/shapes/src/py/pyshapes/primitives/__init__.py index a4c3311..7097cad 100644 --- a/examples/shapes/src/py/pyshapes/primitives/__init__.py +++ b/examples/shapes/src/py/pyshapes/primitives/__init__.py @@ -1,8 +1,8 @@ # Bring in everything from the shared module -from pyshapes._syntax import ClassDict +from pyshapes._syntax import TemplateClassDict from pyshapes.primitives._pyshapes_primitives import * -Shape = ClassDict( +Shape = TemplateClassDict( { 2: Shape_2, 3: Shape_3, From cdb004ec063c09bf228da669b0139b7ed358ef54 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Tue, 8 Oct 2024 18:23:15 +0000 Subject: [PATCH 2/2] #13 Increment to version 0.3.1 --- pyproject.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f8e2429..fcdd3ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ authors = [ license = { file = "LICENSE" } keywords = ["C++", "Python", "Pybind11"] readme = "README.md" -version = "0.2.1" +version = "0.3.1" classifiers = [ "Development Status :: 4 - Beta", @@ -48,8 +48,7 @@ Repository = "https://github.com/Chaste/cppwg/" target-version = ["py38", "py39", "py310", "py311", "py312"] extend-exclude = """ ( - ^/examples/shapes/wrapper/pybind11/ - | ^/cppwg/templates/ + ^/cppwg/templates/ ) """