diff --git a/setup.py b/setup.py index 4b9569b..2832ca1 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/src/testpackage/c/mydemo.c b/src/testpackage/c/mydemo.c index 284ec82..8193900 100644 --- a/src/testpackage/c/mydemo.c +++ b/src/testpackage/c/mydemo.c @@ -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; diff --git a/src/testpackage/main.py b/src/testpackage/main.py new file mode 100644 index 0000000..be1ef74 --- /dev/null +++ b/src/testpackage/main.py @@ -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__}") diff --git a/src/testpackage/run.py b/src/testpackage/run.py deleted file mode 100644 index 6abd760..0000000 --- a/src/testpackage/run.py +++ /dev/null @@ -1,15 +0,0 @@ -"""module run.py docstring""" - -import math -from . import mydemo - -def cos10(): - """cos(10)""" - return math.cos(10) - -def hello(): - """test message""" - print('Hello world, this is "run.py"') - -output = mydemo.print_hello() -print(output) diff --git a/src/testpackage/test/test.py b/src/testpackage/test/test.py index 00f8df5..963350c 100644 --- a/src/testpackage/test/test.py +++ b/src/testpackage/test/test.py @@ -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()