- Notifications
You must be signed in to change notification settings - Fork82
Testing application built with meson-python#659
-
I am working on an application that is Python-based (so it has a bunch of Python files). However, the application also implements a Python extension and some shared libraries. The Python files import the Python extension as a module, which, in-turn, opens the shared libraries with I am not clear on how to test my application. When building the extension and libraries, they all get built into I also tried to run the application with How do I test my application? Thank you. |
BetaWas this translation helpful?Give feedback.
All reactions
I am not sure what this means. I am using editable builds but do you mean that after the build I would have to copy all of the pure-Python files into the build directory
build/cp311?
Editable installs will create a hook loader that ensures that any time you import the project, regardless of current directory and regardless of $PYTHONPATH, you get the version you installed via the editable install. It also has some nice tricks such as automatically reloading any time you modify a source file -- because it will then run ninja to rebuild the C extensions before proceeding with the import, so you can edit source files and rerun your code / tests / interactive interpreter without manually re…
Replies: 1 comment 7 replies
-
In order for a python project to be importable when it consists of both .py files and compiled extensions, you have to do one of:
meson-python supports editable installation, so you can install it that way and then iterate on that for your tests. For a more in-depth approach, you can take a look at:
|
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
They are separate importable modules. However, the pure-Python module cannot find the C extension. This is the source tree after the mason-python build:
I am not sure what this means. I am using editable builds but do you mean that after the build I would have to copy all of the pure-Python files into the build directory |
BetaWas this translation helpful?Give feedback.
All reactions
-
Editable installs will create a hook loader that ensures that any time you import the project, regardless of current directory and regardless of $PYTHONPATH, you get the version you installed via the editable install. It also has some nice tricks such as automatically reloading any time you modify a source file -- because it will then run ninja to rebuild the C extensions before proceeding with the import, so you can edit source files and rerun your code / tests / interactive interpreter without manually rebuilding. |
BetaWas this translation helpful?Give feedback.
All reactions
-
If PYTHONPATH contains both:
Then in principle I can't see what the problem would be when running directly from the source tree. Have you tried adding e.g. a debug print to main.py to have it show what it sees as sys.path when the failure occurs? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think in this example it would work, but if you modify it slightly to:
then the issue is that you wind up with two conflicting locations for the same module:
You can add both to your frommymodule.extimportfoo will fail because python sees If I drop the src location from |
BetaWas this translation helpful?Give feedback.
All reactions
-
@eli-schwartz Does it means that we cannot run test on a wheel (because i don't think it is possible to install a wheel in editable)? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Not completely sure what you mean by that. "Editable installs" per the specification is just a wheel that doesn't contain your code, but instead contains a small import hook that locates your code from your build tree. It's possible to test a non-editable wheel too. But your tests have to be separately importable from outside the wheel. For example, you can have Or you can have But what you cannot do is: (which is a bad idea anyway), because the tests cannot be imported in the same python process as the project itself. |
BetaWas this translation helpful?Give feedback.