-
Notifications
You must be signed in to change notification settings - Fork 66
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
ENH: implement editable wheels without having to run meson install #279
Conversation
9d1d646
to
b0059c7
Compare
Working on this one question arises: what should we do with the Python bytecode cache files? Should we allow them and store them next to the source files, either in the source or build directory, or should we disallow them? Having them in the build directory does not bother me, but I'm not sure we should have them stored in the source directory. Implementing a loader that diverts the bytecode cache in a place disjoint from the source file is also an option, but seems a lot of work. |
93a9a12
to
8e410df
Compare
Is there a reason we're avoiding |
I would prefer excluding them. They have caused trouble in the past in causing a bad magic number |
I kind of have the same question, but from a slightly different perspective. The two things that are known to be problematic right now are running tests and setting breakpoints directly in an IDE. For both, my impression was that installing symlinks and pointing the IDE at the install dir is the one thing that will help. This rewrite is orthogonal to that, right? I don't have a good feel for these custom loaders, but they can't fix the IDE issue was my impression. |
We avoid I don't know how IDEs set breakpoints in source code, but assuming they work similarly as how plain However, with this approach, when you step through the code in a debugger, you step through the real code and not a copy of it that is going to be obliterated at the next reload. |
It would be very useful to have some input from IDE developers about what's their idea about supporting setting breakpoints in the source code of editable wheels. |
That's not relevant here - the idea was to install symlinks directly; the wheel only contains the loader.
Indeed, that's the one thing that will work - edit the installed directory in the IDE (which then also edits the original sources, because symlink). Still not great, but should work.
I'm not sure how to get that. IDE developers probably won't care. This is only a problem for editable wheels + out-of-place builds, which is rare. |
Can you elaborate more on this? |
Well, the biggest problem I see is that it breaks the fundamental promise of editable wheels, namely that the code that is execute is the code that you are editing inside your project. With editable installations based on an installed tree, the code being executed is a copy of the code you are editing. One major consequence is that if you step through the execution in a debugger in your IDE the source code you see is not the source code in your project. If you quit the debugger and modify the code that you are staring at it in the IDE, your edits will be lost the next time you execute your code. Another class of problems is keeping the installed tree and the source tree synchronized. Either you wipe the installed tree at every rebuild as you propose in #282 or you need some more complex form of file tracking. For small projects this is maybe not an issue, but for things like SciPy is a major slowdown: a Python code only change takes a few hundred of milliseconds to be rebuild (just the time for ninja to recognize that there is nothing to do) but installing takes several seconds. Finally, the current code that uses the installed tree for the editable install is much more complex than the code that does not use it and does not suffer form the two class of problems above. If you can live with the two class of problems above, you maybe don't even need editable wheels: simply integrate building a regular wheel and installing it into your test runner. Quickly clobbered together and untested make solution: PYTHON ?= python
test:
$(PYTHON) -m build --no-isolation --wheel -Cbuilddir=build
$(PYTHON) -m pip install dist/*.whl
$(PYTHON) -m pytest tests/ |
fcdf3f7
to
aa61dad
Compare
91a452f
to
b61cc9e
Compare
I don't think releasing 0.13 with one implementation of the editable wheel support and switch to another implementation for 0.14 makes much sense, also considering that editable wheels support is the highlight of 0.13. Everyone agrees that this approach is the one that should be taken. Still I would like someone else to have a look at the implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll try to finish my review this week, sorry for the delay. |
@lithomas1 did you have a chance to try this is combination with setting break-points in an IDE? |
Yeah, looks like it works perfectly there. |
Running with Python 3.9 allows mypy to check our importlib.resource interfaces. mypy 0.991 does a better job in understanding typing in the editable support code.
78fb86e
to
23e275c
Compare
This implementation uses a .pth file to install a custom module finder. The module finder uses the Meson installation plan introspection data to build a virtual view of how files would be laid out in a wheel and looks up the modules from there. Not having to copy files from the source or build directory to the installation directory, rebuilds are faster. Executing directly from the build and source directory is more true to the spirit of editable wheels. There is no risk for the user to accidentally edit the code in the installation directory and have their edits to be overwritten at the next reload. I haven't verified this, but this approach has also the potential to allow to set debugger breakpoints from the code in the source directory and have them work at execution time (this should work if the code is imported before being executed).
We support typing only with Python >= 3.9.
This avoids cluttering the source directory with bytecode cache. It should also avoid surprising behavior when the source is removed from version control but the bytecode cache is still present in the working directory.
@dnicolodi please do not merge pull requests after a review before at least giving the reviewers a chance to reply to feedback and/or re-review the parts that changed. |
Sorry. The last time you said that one round of review was enough. I felt like all your comments have been addressed. I must have misunderstood. |
Exploring the idea of using a custom loader to avoid having to run
meson install
. This works for Python modules. Supporting data files is possible but requires some more work.