-
Notifications
You must be signed in to change notification settings - Fork 68
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: add support for editable wheels #87
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
4a2b9df
to
034d9d1
Compare
This new implementation uses import hooks, which is what I wanted to do initially. Since the complexity required to make the old approach work turned out to be a bit big, it makes more sense to do it like this from the start. The idea is that we built on top of the Traversable protocol ( |
034d9d1
to
cee00c5
Compare
This is an interesting approach. Although I wonder how ergonomic it is. The main use of editable installations is during development. During development with compiled languages (which I think is the main target of meson-python) it is not unusual to do a recompilation just to check that the written code at least compiles. How would this work with approach? Also, does this still uses ephemeral build directories as the regular builds or does it default to a build directory inside the project folder? An example usage scenario would be great to have. Thank you! |
I'd say it is "Python projects containing compiled languages" - typically the majority of contributors (at least for large projects like NumPy, SciPy, Pandas) touch docs, tests, and pure Python code only, or at least way more often than native code. I agree that when you're touching C/C++/Cython/Fortran, editable builds are less relevant. But I've had regular requests from collaborators for editable installs, in particular from those who work with IDEs. |
The way we've set it up for SciPy now to work with Meson is that running the test suite always first rebuilds (necessary to ensure the out-of-place install is not out of date). This takes a fraction of a second, so avoiding rebuilds on imports isn't essential I'd say. (not sure it matters regarding code complexity here). |
The Python stdlib docs are extremely sparse as usual. I have to admit I don't immediately grasp how this all works, a sketch of what actually happens with this implementation when one runs |
I don't think that's the case. I do a lot of cross-project development where I need to test the changes in one project within another one. In this case editable installations are useful. |
Wow, this is pretty cool. Thanks for putting up the PR @FFY00. For this to work, would every project would need to inject this hook(MesonpyFinder) into sys.meta_path in their init.py? |
mesonpy/_editable.py
Outdated
|
||
def install(path: str) -> None: | ||
editable = Editable(os.path.abspath(path)) | ||
sys.meta_path.append(MesonpyFinder(editable)) |
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.
Would a prepend be more appropriate here?
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.
Doesn't matter much, but my reasoning for simply appending was to not slow down any of the other imports. But this is now outdated given our new approach.
After discussing with @rgommers, we thought it would be better to simplify the initial approach. Instead of creating our own loader and reader, we will just intercept the import call with a custom finder, which won't change any of the import machinery and will simply trigger a rebuild + install to a dummy directory with we will make sure we add to |
Nop! Our editable wheel will install a Also, the custom finder will need to be in |
cee00c5
to
64625c2
Compare
64625c2
to
400c62e
Compare
@@ -192,11 +188,15 @@ def _has_extension_modules(self) -> bool: | |||
# Assume that all code installed in {platlib} is Python ABI dependent. | |||
return bool(self._wheel_files['platlib']) | |||
|
|||
@property | |||
def normalized_name(self) -> str: | |||
return self._project.name.replace('-', '_') |
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.
Not related to editable installs: shouldn't this also map "."
to "_"
?
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.
Good catch! But not really here, though I should definitely be doing that in the module name.
400c62e
to
5ee52b1
Compare
Alright, I haven't tested it yet, but it's getting pretty late, so I should go. The code should now be complete, but I expect stuff to be broken -- as I said, I didn't do any testing. |
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.
Just a few superficial comments.
mesonpy/__init__.py
Outdated
|
||
project_path = self._source_dir / '.mesonpy-editable' | ||
top_level_modules = self._project.top_level_modules | ||
rebuild_commands = [list(cmd) for cmd in self._project.build_commands(project_path)] |
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.
Why the list comprehension?
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.
To convert to the correct type.
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.
Correct type for what? This makes tuples into lists, but it does not seem like lists are required. Are they? If they are, can't we just return the correct type?
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.
I left some comments, addressing typos I saw when I pulled this. Hopefully, this helps you out a little.
Other then the suggestions, you'll need to add mesonpy/_editable
to the meson.build
file.
53512e0
to
bd85f57
Compare
Alright, this should now be finally working 🎉 The only thing is that it currently does not detect top-level native modules. @lithomas1 want to give it a try? |
Nice this is pretty awesome 🚀 (It is especially cool that you can just edit .pyx files and have the changes sync up too). The only issue I have is slow rebuilds. It's not a deal-breaker for me, but its probably something to think about in the future. |
How does that compare to just running Perhaps we should have a way to disable swallowing the Meson output, so that developers can see the log when Python starts up? |
Signed-off-by: Filipe Laíns <[email protected]>
This was leftover from when we ran auditwheel. Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
pytest has its own tmpdir management and cleanup, making is easier to inspect the environments when the tests fail. Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Dirty workaround for cases where Meson does not install to the expected paths, like in macOS. Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
376ed35
to
89af86c
Compare
docs/index.rst
Outdated
|
||
.. code-block:: | ||
|
||
python -m pip install -e . --config-settings editable-verbose= |
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.
Do we error when this is passed but we are not doing an editable install?
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.
Yep.
meson-python/mesonpy/__init__.py
Lines 1119 to 1128 in 89af86c
for key in config_settings: | |
known_keys = ('builddir', 'editable-verbose', *meson_args_cli_keys) | |
if key not in known_keys: | |
import difflib | |
matches = difflib.get_close_matches(key, known_keys, n=3) | |
if len(matches): | |
alternatives = ' or '.join(f'"{match}"' for match in matches) | |
raise ConfigError(f'Unknown configuration entry "{key}". Did you mean {alternatives}?') | |
else: | |
raise ConfigError(f'Unknown configuration entry "{key}"') |
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.
The docs look quite good to me now, just a few minor suggestions to clarify things.
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.
LGTM
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
89af86c
to
d0011ec
Compare
I somehow missed the notification for Ralf's review, so I only noticed yesterday 🤣 |
This is just an initial approach, that is known to not work on alluse-cases. It simply uses .pth files to inject search locations for the
default import finder, for this reason generated files that should be
installed inside modules will not be available.
Signed-off-by: Filipe Laíns [email protected]