-
Notifications
You must be signed in to change notification settings - Fork 54
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
Idea for new entry point: cmake.package
#831
Comments
Great idea! To flesh out this a bit more, how should the project define the There is also On Fedora packaging side, we also have to figure out how to point the entry_point there to the system installed one. On python side, it would have to look slightly different because afaik, the entry_point must point to a python loadable path, but I don't see a reason why that path can't be made to be a valid python path with |
After doing some research on entry points, I understand them a little better, and have a better idea of how we would go about this. The entry point would look more like: [cmake.package]
ExamplePackage = "example:cmake_package_dir" And then in import importlib.resources as rs
def cmake_package_dir(_package_name): # _package_name is ignored here, but could theoretically be used
return rs.files(__package__) / "lib64/cmake/example"
Yes, that's basically what I'm advocating here. |
I believe |
I believe we had this idea at the beginning, got stuck on if it should set _DIR or _ROOT, and then somehow didn't end up adding either... IIRC _ROOT is the better one? |
No. |
We've been supporting directly specifying the directory and not requiring an entry point function. It just needs to be a valid Python module, which is pretty much just a directory. |
Ahh, but a module path could resolve to several physical paths. But I think we could just then pick the one with the config file in it? |
How? How does the consuming project find the directly-specified directory? |
Shouldn't be a problem. The idea is that I.e. not using |
I guess you can always define cache variables manually, but not sure if it refers to that. And also this seems to be the reverse, i.e. the installed package defines what and where |
Right. I'm proposing adding functionality for this:
so that consuming packages don't have to know things about the dependency's wheel layout. We were almost there with |
Hmm, also occurs to me, how would one disable the preference of the entry_points? For The longterm proper solution would probably be to write a DependencyProvider interface like |
Kyle and I were discussing this earlier and I am supportive of the idea.
I think Henry was referring to the fact that with the
Could you actually stick to the above and simply specify the relative path to the directory? Directories are (namespace) packages, therefore importable modules, so I think you could just take the resulting module's
Are you imagining a situation where there are multiple providers of a config file with the same name? I don't know if there is a good way to avoid them clobbering each other in this case. |
Yes, also Anyway, we should not be discussing changing the current system in this issue - the new entry point should be just like the existing pair (minus the extra detail that the name matters).1
I think this was about how to disable an installed Python module forcing its CMake files to be found. If you had "thing" installed with When we were first discussing this (can't find records, probably was around community meeting 5 or so), I think we had the idea that users could supply ignore patterns on the entry point names. By the way, going back to the beginning:
We can't add an entry point automatically unless a user sets this in their Also:
I don't think that's required, though. Setting your Footnotes
|
The issue I see is that it wouldn't be able to support pointing to system packages like
Indeed, basically going by the general CMake guidelines to not define (top-level) user configurations inside a CMakeLists.txt. In a similar manner we should keep those empty such that the end-user can define them inside |
|
Interesting, can you expand on that with an example or upstream documentation? From my reading it means that if you are in |
https://cmake.org/cmake/help/latest/command/find_package.html
|
Definitely should use either |
If you wanted to point at Not sure if we should also specify some way to scope the access, since a package is not guaranteed to be on disk, but the file we want needs to be accessible via a disk-based path for at least the duration of the CMake call. We could make the object a context manager, for example. |
I think we need to first start with how would the user use |
Scikit-build-core already supports the
cmake.prefix
entry point, which appends the value toCMAKE_PREFIX_PATH
. In theory, this will allow projects that installlib/cmake/<package>/<package>-config.cmake
to automatically be found by consuming projects. However, this does not work in cases where:lib64/cmake/<package>/<package>-config.cmake
, and the consuming package is built on a Debian-based system, because in this case,FIND_LIBRARY_USE_LIB64_PATHS
is set toFALSE
In theory, the exporting project could set
cmake.prefix
to<wheel-name>/lib64/cmake/<package>
, because thefind_package()
search procedure does look directly in the values ofCMAKE_PREFIX_PATH
in addition to the various subdirectories listed. However, that is only conventional on Windows, and I don't consider it good practice to setCMAKE_PREFIX_PATH
to<wheel-name>/lib64/cmake/<package>
, when prefixes are really meant to havelib64/cmake/<package>
within them.I propose an alternative: a new entry point called
cmake.package
, that is used like so inentry_points.txt
:In this case, scikit-build-core would pass
-DExamplePackage_DIR=/home/user/.local/lib/python3.12/site-packages/example/lib64/cmake/example
to CMake. The*_DIR
variable tells CMake exactly where to find a package file, rather than giving it a list of prefixes to search through their subdirectories. There's no ambiguity, and it works with any package layout, as long as the config file is named<Package>Config.cmake
or<package>-config.cmake
.But it gets even better! With the CMake File API, we can even automatically figure out if the project is exporting any package config files. By searching through the
installer
keys, it can search forfile
installers that install<package>-config.cmake
or<Package>Config.cmake
, andexport
installers that install<package>-targets.cmake
or<Package>Targets.cmake
. If it finds the two together, it's a pretty safe bet that that's a CMake package config file, and scikit-build-core can automatically create an entry point for it. (Note that this would be more ambiguous if the<package>-config.cmake
convention is used, since that loses casing information. In that case, we could defer to the export name, or just not support the<package>-config.cmake
convention.)Note that if the heuristics used by the automatic entry point creation are incorrect for any reason, the package creator can still manually specify a
cmake.package
entry point to override the automatic creation procedure.The text was updated successfully, but these errors were encountered: