Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions examples/shapes/src/py/pyshapes/_syntax.py
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions examples/shapes/src/py/pyshapes/geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/shapes/src/py/pyshapes/mesh/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/shapes/src/py/pyshapes/primitives/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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/
)
"""

Expand Down