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
16 changes: 4 additions & 12 deletions Sandbox.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"outputs": [],
"source": [
"import py_cppmodel"
"import xyz.cppmodel"
]
},
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"\"\"\"\n",
"\n",
"tu = clang.cindex.TranslationUnit.from_source(\"tmp.cc\", COMPILER_ARGS, unsaved_files=[(\"tmp.cc\", source)])\n",
"model = py_cppmodel.Model(tu)\n",
"model = xyz.cppmodel.Model(tu)\n",
"model"
]
},
Expand All @@ -72,19 +72,11 @@
"source": [
"model.unmodelled_nodes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "py-cppmodel",
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kernel display name is set to "py-cppmodel" which references the old package name. For consistency with the namespace migration, consider updating this to "xyz-cppmodel" or a more generic name like "Python 3".

Suggested change
"display_name": "py-cppmodel",
"display_name": "xyz-cppmodel",

Copilot uses AI. Check for mistakes.
"language": "python",
"name": "python3"
},
Expand All @@ -98,7 +90,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "py-cppmodel"
name = "xyz-cppmodel"
version = "0.0.1"
description = "A Python wrapper around clang's python bindings to generate a simple Python model of a C++ translation unit."
readme = "README.md"
Expand Down Expand Up @@ -31,15 +31,8 @@ addopts = "-n auto -v"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.sdist]
include = [
"py_cppmodel.py",
"LICENSE",
"README.md",
]

[tool.hatch.build.targets.wheel]
include = ["py_cppmodel.py"]
packages = ["src/xyz"]

[tool.ruff]
line-length = 120
Expand Down
18 changes: 9 additions & 9 deletions py_cppmodel.py → src/xyz/cppmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, cursor: Cursor):
self.name: str = cursor.displayname

def __repr__(self) -> str:
return "<py_cppmodel.Unmodelled {} {}>".format(self.name, self.location)
return "<xyz.cppmodel.Unmodelled {} {}>".format(self.name, self.location)


class Type:
Expand All @@ -44,7 +44,7 @@ def __init__(self, cindex_type):
self.pointee = None

def __repr__(self) -> str:
return "<py_cppmodel.Type {}>".format(self.name)
return "<xyz.cppmodel.Type {}>".format(self.name)


class Member:
Expand All @@ -53,7 +53,7 @@ def __init__(self, cursor: Cursor):
self.name: str = cursor.spelling

def __repr__(self) -> str:
return "<py_cppmodel.Member {} {}>".format(self.type, self.name)
return "<xyz.cppmodel.Member {} {}>".format(self.type, self.name)


class FunctionArgument:
Expand All @@ -63,8 +63,8 @@ def __init__(self, type: Type, name: Optional[str] = None):

def __repr__(self) -> str:
if self.name is None:
return "<py_cppmodel.FunctionArgument self.type.name>"
return "<py_cppmodel.FunctionArgument {} {}>".format(self.type, self.name)
return "<xyz.cppmodel.FunctionArgument self.type.name>"
return "<xyz.cppmodel.FunctionArgument {} {}>".format(self.type, self.name)


class _Function:
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, cursor, namespaces=[]):

def __repr__(self) -> str:
s = _Function.__repr__(self)
return "<py_cppmodel.Function {}>".format(s)
return "<xyz.cppmodel.Function {}>".format(s)

def __eq__(self, f) -> bool:
if self.name != f.name:
Expand Down Expand Up @@ -132,7 +132,7 @@ def __repr__(self) -> str:
s = "virtual {} = 0".format(s)
elif self.is_virtual:
s = "virtual {}".format(s)
return "<py_cppmodel.Method {}>".format(s)
return "<xyz.cppmodel.Method {}>".format(s)


class Class:
Expand Down Expand Up @@ -163,7 +163,7 @@ def __init__(self, cursor: Cursor, namespaces: List[str]):
self.base_classes.append(c.type.spelling)

def __repr__(self) -> str:
return "<py_cppmodel.Class {}>".format(self.name)
return "<xyz.cppmodel.Class {}>".format(self.name)


class Model:
Expand Down Expand Up @@ -193,7 +193,7 @@ def is_error_in_current_file(diagnostic: Diagnostic) -> bool:
self._add_child_nodes(translation_unit.cursor, [])

def __repr__(self) -> str:
return "<py_cppmodel.Model filename={}, classes={}, functions={}>".format(
return "<xyz.cppmodel.Model filename={}, classes={}, functions={}>".format(
self.filename,
[c.name for c in self.classes],
[f.name for f in self.functions],
Expand Down
22 changes: 11 additions & 11 deletions test_py_cppmodel.py → tests/test_cppmodel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from clang.cindex import TranslationUnit

import py_cppmodel
import xyz.cppmodel

COMPILER_ARGS = [
"-x",
Expand Down Expand Up @@ -41,7 +41,7 @@ def model():
COMPILER_ARGS,
unsaved_files=[("sample.cc", SOURCE)],
)
return py_cppmodel.Model(tu)
return xyz.cppmodel.Model(tu)


def test_filename(model):
Expand All @@ -50,26 +50,26 @@ def test_filename(model):

def test_functions(model):
assert len(model.functions) == 2
assert str(model.functions[0]) == "<py_cppmodel.Function double bar(double)>"
assert str(model.functions[1]) == "<py_cppmodel.Function int main()>"
assert str(model.functions[0]) == "<xyz.cppmodel.Function double bar(double)>"
assert str(model.functions[1]) == "<xyz.cppmodel.Function int main()>"


def test_classes(model):
assert len(model.classes) == 1
assert str(model.classes[0]) == "<py_cppmodel.Class A>"
assert str(model.classes[0]) == "<xyz.cppmodel.Class A>"

assert len(model.classes[0].annotations) == 1
assert model.classes[0].annotations[0] == "A"


def test_class_members(model):
assert len(model.classes[0].members) == 3
assert str(model.classes[0].members[0]) == "<py_cppmodel.Member <py_cppmodel.Type int> a>"
assert str(model.classes[0].members[1]) == "<py_cppmodel.Member <py_cppmodel.Type double> b>"
assert str(model.classes[0].members[2]) == "<py_cppmodel.Member <py_cppmodel.Type char[8]> c>"
assert str(model.classes[0].members[0]) == "<xyz.cppmodel.Member <xyz.cppmodel.Type int> a>"
assert str(model.classes[0].members[1]) == "<xyz.cppmodel.Member <xyz.cppmodel.Type double> b>"
assert str(model.classes[0].members[2]) == "<xyz.cppmodel.Member <xyz.cppmodel.Type char[8]> c>"

assert len(model.classes[0].methods) == 1
assert str(model.classes[0].methods[0]) == "<py_cppmodel.Method int foo(int)>"
assert str(model.classes[0].methods[0]) == "<xyz.cppmodel.Method int foo(int)>"
assert len(model.classes[0].methods[0].annotations) == 1
assert model.classes[0].methods[0].annotations[0] == "foo"

Expand All @@ -78,9 +78,9 @@ def test_unmodelled_nodes(model):
assert len(model.unmodelled_nodes) == 2
assert (
str(model.unmodelled_nodes[0])
== "<py_cppmodel.Unmodelled z <SourceLocation file 'sample.cc', line 1, column 5>>"
== "<xyz.cppmodel.Unmodelled z <SourceLocation file 'sample.cc', line 1, column 5>>"
)
assert (
str(model.unmodelled_nodes[1])
== "<py_cppmodel.Unmodelled B<T> <SourceLocation file 'sample.cc', line 12, column 7>>"
== "<xyz.cppmodel.Unmodelled B<T> <SourceLocation file 'sample.cc', line 12, column 7>>"
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from clang.cindex import TranslationUnit

import py_cppmodel
import xyz.cppmodel

COMPILER_ARGS = [
"-x",
Expand Down Expand Up @@ -49,4 +49,4 @@ def test_include(include):
)

# This should not raise an exception.
py_cppmodel.Model(tu)
xyz.cppmodel.Model(tu)
84 changes: 41 additions & 43 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading