Skip to content

Commit

Permalink
Merge pull request #11 from patrick-csliu/refactor/src
Browse files Browse the repository at this point in the history
refactor src
  • Loading branch information
patrick-csliu authored Sep 16, 2023
2 parents 13a5268 + db1e17d commit 2da261c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
ext_modules=[
Extension(
name="testpackage.mydemo", # as it would be imported
name="testpackage._mydemo", # as it would be imported
# may include packages/namespaces separated by `.`

sources=["./src/testpackage/c/mydemo.c"], # all sources are compiled into a single binary file
Expand Down
6 changes: 3 additions & 3 deletions src/testpackage/c/mydemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ static PyMethodDef mydemoMethods[] = {

static struct PyModuleDef spammodule = {
PyModuleDef_HEAD_INIT,
"mydemo", /* name of module */
"this is some mydemo's doc", /* module documentation, may be NULL */
"_mydemo", /* name of module */
"this is a mydemo's doc", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
mydemoMethods
};

PyMODINIT_FUNC
PyInit_mydemo(void)
PyInit__mydemo(void) /* module name is _mydemo */
{
PyObject *m;

Expand Down
16 changes: 16 additions & 0 deletions src/testpackage/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""module run.py docstring"""

from . import _mydemo

def hello():
"""test message"""
print('Hello world, this is "run.py"')

def mydemo():
print("_mydemo.print_hello()")
output = _mydemo.print_hello()
print("output:", output)
print(f"__doc__ = {_mydemo.__doc__}")
print(f"__file__ = {_mydemo.__file__}")
print(f"__name__ = {_mydemo.__name__}")
print(f"__package__ = {_mydemo.__package__}")
15 changes: 0 additions & 15 deletions src/testpackage/run.py

This file was deleted.

10 changes: 3 additions & 7 deletions src/testpackage/test/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"""test package"""

from testpackage import run
from testpackage import mydemo
from testpackage import main

print(run.cos10())
run.hello()

value = mydemo.print_hello()
print(f"output from mydemo.print_hello(): {value}")
main.hello()
main.mydemo()

0 comments on commit 2da261c

Please sign in to comment.