pybind / scikit_build_example

An example combining scikit-build and pybind11
Other
110 stars 29 forks source link

Single module package? #63

Open finnBsch opened 1 year ago

finnBsch commented 1 year ago

Hi, how would I go about creating a single module package? Say I have one module with a few classes. The automatically generated signatures of the class functions contain then something like packagename.modulename.classname However, as this package only contains one module, the packagename and modulename are redundant information. Is there away to create just the module, and not a package? Or to omit these names in the signatures?

henryiii commented 1 year ago

Sure you can! I waffled a bit on showing such an example here, but most of the time a realistic package probably grows to have at least a little bit in Python, so that's why the example here is with a module.

You can see at least one example in scikit-build-core's tests, but the idea is simple: install directly to "." rather than a folder name, and don't have a folder with the package name in the repo. Make sure you name the extension nicely, since it's going in site-packages as-is.

You can also have a Python __init__.py that imports everything from the SO. (well, instead, not also)

finnBsch commented 1 year ago

Hi Henry, Thank you for the help. I managed to install my C++ library just as a module. This leads to the function signatures being modulename.classname, because the module is not part of a package anymore. It makes the documentation more convenient. Now, I am running into a different problem: I want to add external files (images, fonts,..) to be used by the library as described here: https://python-packaging.readthedocs.io/en/latest/non-code-files.html. For that, it would make sense to install the Python Module into a Folder. This however to my understanding would make it a package, rather than just the module and hence I run into the function signature problem. So, now, what I would like to have:

Is there a way?

You can also have a Python init.py that imports everything from the SO. (well, instead, not also)

Is this how to achieve that?

And maybe related to that: Why do we use scikit-build-core instead of scikit-build here? I am a bit confused

henryiii commented 1 year ago

Sorry, missed this. You want this:

You can also have a Python __init__.py that imports everything from the SO. (well, instead, not also)

You'd just have src/packagename/__init__.py that does from ._core import * (or, better yet, list things explicitly). Then your module would be packagename._core.

Scikit-build-core is the modern builder for scikit-build. Eventually, scikit-build will just use scikit-build-core anyway.