Skip to content

Commit edc4435

Browse files
authored
Migrate code to a namespace package 'xyz' (#19)
1 parent 5c158ce commit edc4435

File tree

6 files changed

+69
-86
lines changed

6 files changed

+69
-86
lines changed

Sandbox.ipynb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"outputs": [],
1111
"source": [
12-
"import py_cppmodel"
12+
"import xyz.cppmodel"
1313
]
1414
},
1515
{
@@ -57,7 +57,7 @@
5757
"\"\"\"\n",
5858
"\n",
5959
"tu = clang.cindex.TranslationUnit.from_source(\"tmp.cc\", COMPILER_ARGS, unsaved_files=[(\"tmp.cc\", source)])\n",
60-
"model = py_cppmodel.Model(tu)\n",
60+
"model = xyz.cppmodel.Model(tu)\n",
6161
"model"
6262
]
6363
},
@@ -72,19 +72,11 @@
7272
"source": [
7373
"model.unmodelled_nodes"
7474
]
75-
},
76-
{
77-
"cell_type": "code",
78-
"execution_count": null,
79-
"id": "5",
80-
"metadata": {},
81-
"outputs": [],
82-
"source": []
8375
}
8476
],
8577
"metadata": {
8678
"kernelspec": {
87-
"display_name": "Python 3 (ipykernel)",
79+
"display_name": "py-cppmodel",
8880
"language": "python",
8981
"name": "python3"
9082
},
@@ -98,7 +90,7 @@
9890
"name": "python",
9991
"nbconvert_exporter": "python",
10092
"pygments_lexer": "ipython3",
101-
"version": "3.10.14"
93+
"version": "3.10.9"
10294
}
10395
},
10496
"nbformat": 4,

pyproject.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "py-cppmodel"
2+
name = "xyz-cppmodel"
33
version = "0.0.1"
44
description = "A Python wrapper around clang's python bindings to generate a simple Python model of a C++ translation unit."
55
readme = "README.md"
@@ -31,15 +31,8 @@ addopts = "-n auto -v"
3131
requires = ["hatchling"]
3232
build-backend = "hatchling.build"
3333

34-
[tool.hatch.build.targets.sdist]
35-
include = [
36-
"py_cppmodel.py",
37-
"LICENSE",
38-
"README.md",
39-
]
40-
4134
[tool.hatch.build.targets.wheel]
42-
include = ["py_cppmodel.py"]
35+
packages = ["src/xyz"]
4336

4437
[tool.ruff]
4538
line-length = 120

py_cppmodel.py renamed to src/xyz/cppmodel.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, cursor: Cursor):
2828
self.name: str = cursor.displayname
2929

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

3333

3434
class Type:
@@ -44,7 +44,7 @@ def __init__(self, cindex_type):
4444
self.pointee = None
4545

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

4949

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

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

5858

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

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

6969

7070
class _Function:
@@ -101,7 +101,7 @@ def __init__(self, cursor, namespaces=[]):
101101

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

106106
def __eq__(self, f) -> bool:
107107
if self.name != f.name:
@@ -132,7 +132,7 @@ def __repr__(self) -> str:
132132
s = "virtual {} = 0".format(s)
133133
elif self.is_virtual:
134134
s = "virtual {}".format(s)
135-
return "<py_cppmodel.Method {}>".format(s)
135+
return "<xyz.cppmodel.Method {}>".format(s)
136136

137137

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

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

168168

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

195195
def __repr__(self) -> str:
196-
return "<py_cppmodel.Model filename={}, classes={}, functions={}>".format(
196+
return "<xyz.cppmodel.Model filename={}, classes={}, functions={}>".format(
197197
self.filename,
198198
[c.name for c in self.classes],
199199
[f.name for f in self.functions],
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from clang.cindex import TranslationUnit
33

4-
import py_cppmodel
4+
import xyz.cppmodel
55

66
COMPILER_ARGS = [
77
"-x",
@@ -41,7 +41,7 @@ def model():
4141
COMPILER_ARGS,
4242
unsaved_files=[("sample.cc", SOURCE)],
4343
)
44-
return py_cppmodel.Model(tu)
44+
return xyz.cppmodel.Model(tu)
4545

4646

4747
def test_filename(model):
@@ -50,26 +50,26 @@ def test_filename(model):
5050

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

5656

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

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

6464

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

7171
assert len(model.classes[0].methods) == 1
72-
assert str(model.classes[0].methods[0]) == "<py_cppmodel.Method int foo(int)>"
72+
assert str(model.classes[0].methods[0]) == "<xyz.cppmodel.Method int foo(int)>"
7373
assert len(model.classes[0].methods[0].annotations) == 1
7474
assert model.classes[0].methods[0].annotations[0] == "foo"
7575

@@ -78,9 +78,9 @@ def test_unmodelled_nodes(model):
7878
assert len(model.unmodelled_nodes) == 2
7979
assert (
8080
str(model.unmodelled_nodes[0])
81-
== "<py_cppmodel.Unmodelled z <SourceLocation file 'sample.cc', line 1, column 5>>"
81+
== "<xyz.cppmodel.Unmodelled z <SourceLocation file 'sample.cc', line 1, column 5>>"
8282
)
8383
assert (
8484
str(model.unmodelled_nodes[1])
85-
== "<py_cppmodel.Unmodelled B<T> <SourceLocation file 'sample.cc', line 12, column 7>>"
85+
== "<xyz.cppmodel.Unmodelled B<T> <SourceLocation file 'sample.cc', line 12, column 7>>"
8686
)

test_parse_standard_library_includes.py renamed to tests/test_parse_standard_library_includes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from clang.cindex import TranslationUnit
33

4-
import py_cppmodel
4+
import xyz.cppmodel
55

66
COMPILER_ARGS = [
77
"-x",
@@ -49,4 +49,4 @@ def test_include(include):
4949
)
5050

5151
# This should not raise an exception.
52-
py_cppmodel.Model(tu)
52+
xyz.cppmodel.Model(tu)

uv.lock

Lines changed: 41 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)