Skip to content

Commit 6ce2473

Browse files
committed
Add C++ interface and Python bindings for the pycmtemplate module
1 parent 46003c8 commit 6ce2473

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

pycmtemplate/ctopy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pycmtemplate_c
2+
3+
functionFromCPP = pycmtemplate_c.functionFromCPP
4+
functionFromCPP2 = pycmtemplate_c.functionFromCPP2
5+
6+
variableFromCPP = pycmtemplate_c.variableFromCPP
7+
variableFromCPP2 = pycmtemplate_c.variableFromCPP2

pycmtemplate/ctopy.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Interface file for the C++ module. (pycmtemplate/ctopy.pyi)
3+
This file is used to define the interface of the C++ module.
4+
The interface file is used by the Python type checker to check the types of the C++ module.
5+
"""
6+
7+
# Function definitions
8+
def functionFromCPP() -> int: ...
9+
def functionFromCPP2(a: int, b: int) -> int: ...
10+
11+
# Variable definitions
12+
variableFromCPP: int
13+
variableFromCPP2: str

pycmtemplate/py.typed

Whitespace-only changes.

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from setuptools import setup, Extension
1+
from setuptools import setup, Extension, find_packages
22

33
# C/C++ extension module configuration
44
module = Extension(
@@ -15,6 +15,12 @@
1515
long_description="Python C/C++ template project",
1616
author="Etkin Dogan",
1717
author_email="[email protected]",
18+
packages=find_packages(),
19+
install_requires=[],
1820
python_requires=">=3.8",
1921
ext_modules=[module],
22+
package_data={
23+
# Required for .pyi files to be included in the package
24+
"pycmtemplate": ["py.typed"],
25+
},
2026
)

tests/test2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pycmtemplate
2+
3+
print("Function calls")
4+
r1 = pycmtemplate.functionFromCPP()
5+
r2 = pycmtemplate.functionFromCPP2(3, 5)
6+
7+
print("Print results")
8+
print(r1)
9+
print(r2)
10+
11+
print("Print variables")
12+
print(pycmtemplate.variableFromCPP)
13+
print(pycmtemplate.variableFromCPP2)

0 commit comments

Comments
 (0)