Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single module package? #63

Open
finnBsch opened this issue Dec 11, 2022 · 3 comments
Open

Single module package? #63

finnBsch opened this issue Dec 11, 2022 · 3 comments

Comments

@finnBsch
Copy link

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
Copy link
Collaborator

henryiii commented Dec 11, 2022

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
Copy link
Author

finnBsch commented Dec 15, 2022

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:

  • Create a Package from my C++ library, so that on installation I get a folder with it
  • Omit the Packagename (or the module name) for all signatures in the documentation

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
Copy link
Collaborator

henryiii commented Mar 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants