-
Notifications
You must be signed in to change notification settings - Fork 66
Support editable installs of Cython pxd files #516
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
Conversation
Ignore the above, see my next comment. I resolved the issue I was originally running into. The predefined pytest fixtures aren't really designed for multiple packages being installed in a single test, so I had to import some stuff manually from conftest to produce a reasonable test. Happy to look into cleaner solutions later, but for now I don't think it's critical for an initial demo of the problem. To make it easier to see the differences between my PR and @LecrisUT's original that this is based off of (#399) I've opened a corresponding PR from my branch onto his at LecrisUT#1. That PR can be used to view just the relevant diff, while this PR will run CI for us. |
OK weird, I found the issue although I don't quite understand the underlying cause. It seems like there's a bug where it works with |
Quick note about $ tree
.
├── pkg1
│ ├── CMakeLists.txt
│ ├── src
│ │ └── pkg1
│ │ └── one.pyx
│ ├── python
│ │ └── pkg1
│ │ ├── __init__.py # This file is empty
│ │ └── one.pxd
│ └── pyproject.toml
└── pkg2
├── CMakeLists.txt
├── src
│ └── pkg2
│ └── two.pyx
├── python
│ └── pkg2
│ └── __init__.py # This file is empty
└── pyproject.toml #CMakeLists.txt
add_custom_command(
OUTPUT pkg1/one.c
DEPENDS pkg1/one.pyx
VERBATIM
COMMAND "${CYTHON}" "${CMAKE_CURRENT_SOURCE_DIR}/src/pkg1/one.pyx" --output-file
"${CMAKE_CURRENT_BINARY_DIR}/pkg1/one.c")
python_add_library(one MODULE "${CMAKE_CURRENT_BINARY_DIR}/pkg1/one.c"
WITH_SOABI)
install(TARGETS one DESTINATION pkg1/) #pyproject.toml
[tool.scikit-build]
wheel.packages = ["python/pkg1"] The key part her is that Although now that I am looking at the error more carefully it is odd, it should still be able to pick it up |
#399 is in, but it doesn't work if there's an |
This one does not use I think the issue is that there is some priority to how the the modules are loaded against |
A bit swamped this week but will try to get back into this in the next week or two. |
31c27cc
to
480d720
Compare
Depending on your level of familiarity with Cython, we may need to get some help from a Cython developer here. From a quick inspection, it seems like since Cython is essentially a preprocessing transpiler of the pyx files, I'm not sure whether Furthermore, pxd files would change the 1-1 mapping from module to source file into a many-to-one mapping. I've done that by manually modifying the installed On the issue you also commented
I agree that the pyx files don't need to be added at all. I didn't do anything special to add them, but we could try and clean up whatever in scikit-build-core is doing that. FWIW one hacky solution I tried was to replace the pyx file with the pxd file in the known source files provided to the |
Seems you've identified the issue and it might be a way to approach it. I'm not familiar with cython, so I could use a breakdown of how you've edited, maybe a tree view of the files and the dictionary passed to the editable file that makes it work. From what I read, we should filter the modules that have |
Sorry, my wording was confusing. When I said "and it works in this specific case", I was referring to the fact that in general it would not be well-defined for the
Essentially Cython can be thought of as a compiled superset of Python. In analogy to C, Cython supports To debug, I've created a local environment with scikit-build-core, then done an editable install of pkg1 into it (which works fine). I then do an editable install of pkg2, which fails as expected. The following approaches all work to remedy this issue:
However, if I add a
None of the prints of "find_spec..." mention pkg1 during Cython compilation. All of the mentions that I do see are of Python builds or Cython internals, suggesting that since Cython is itself implemented in Python we're seeing the bits that imports in order to do the transpiling, but the transpiling itself does not respect modifications of Does that make sense? |
751eac1
to
3ce543b
Compare
All right, after some discussion at the last dev meeting we came up with an alternative solution that involves just adding the extra paths directly to the pth file. My diagnosis in #516 (comment) is correct, and the new solution leverages the fact that Cython does support pth files for paths even though it does not support meta path finders. I will follow up with Cython to try and get that support added in the future, but this solution seems workable in scikit-build-core for now. @henryiii I've added a test, but I'm not sure how to get it to pass. How should I get installation of scikit-build-core in the virtual environment to install the current local package instead of pulling from PyPI? We could invoke |
…red for a true test
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
903f951
to
3b6f925
Compare
Thanks for the fix! I guess the isolated fixture and the associated pep518 wheelhouse are designed exactly for the use case of pulling the current version of the code, makes sense. Let me know if you need anything else from me on this PR. |
Yes, they are. :) |
Editable installs of packages containing Cython currently do not properly support downstream Cython packages finding the pxd files from the editable install. The issue is that editable installs are managed using a meta path finder, and Cython does not appear to support that for pxd files. However, Cython does support pth files adding include paths directly, so this PR solves the pxd search issue by adding the necessary paths directly to the pth file that currently adds the meta path finder.
Resolves #442