Closed cyschneck closed 4 months ago
Hi @cyschneck, the extensions are installed fine - what is happening is that when you run pytest .
, an import of the local pywt/
tree is attempted rather than the installed package. Try this:
cd demo
pytest --pyargs pywt
Or alternatively:
cd demo # or any other clean dir
python -c "import pywt; pywt.test()"
This works for running the tests in the demo file, but I wanted to run the tests directory (PyWavelets/pywt/tests). But running pytest .
and pytest --pyargs pywt
outside the demo file throws the same module error
ImportError while loading conftest '/home/user/Github/pywt/pywt/conftest.py'.
../__init__.py:15: in <module>
from ._extensions._pywt import *
E ModuleNotFoundError: No module named 'pywt._extensions._pywt'
This works for running the tests in the demo file, but I wanted to run the tests directory (PyWavelets/pywt/tests).
They are the same tests. You cannot run the tests from within the git repo unless you're using an editable install, exactly because pytest
will then find the pywt
directory in the git repo and try to import it instead of the install pywt
.
So there's two ways of running the tests:
pytest --pyargs pywt
or python -c "import pywt; pywt.test()"
(away from the root of the repo)pip install -e . --no-build-isolation
and then run pytest
or pytest pywt
in the root of the repoThis is the standard problem with pytest, it needs to find the right package. A source layout in the repo of src/pkgname
avoids that issue, but we (and many/most python packages) don't use that.
This is the standard problem with pytest, it needs to find the right package. A source layout in the repo of src/pkgname avoids that issue, but we (and many/most python packages) don't use that.
Should this be a cue that we should move to an src/
layout? I looked at the directory structure for the Meson configuration, and it looks like it should be doable with changing
subdir('pywt')
in the root-level meson.build
file to point to src/pywt/
, and the rest of the directories should be the same (the inner meson.build
directories look like they don't use any absolute paths so that should make it easier).
It's not impossible, but I'm also not really keen to do that, since that will be a lot of code churn and result in merge conflicts for all open PRs and in-progress branches anyone may have. What we have here is a very standard layout for a repo with a Python package, so it's just one of those "you have to know this about how pytest works" things.
Thanks for the help! The pip install -e .
(combined with a conda install pytest
) was what I needed. I wanted to run the tests test folder under the pywt subfolder.
conda create -c conda-forge -n pywavelets python=3.10
conda activate pywavelets
pip install -e .
conda install pytest
cd pywt
pytest
Trying to build with pip install -e . --no-build-isolation
gave some issues with meson-python. But I was able to run the tests folder this way
Trying to build with
pip install -e . --no-build-isolation
gave some issues with meson-python. But I was able to run the tests folder this way
--no-build-isolation
disables auto-installing build dependencies; if you had added conda install meson-python
beforehand it would work.
Seems like things are working for you now though, so looks like we're all good here - hence I'll close this issue.
I am running a local instance of the repo on a Linux/Ubuntu environment with Python 3.10.13 and have not been able to run the testing suite
I followed the build instructions as follows:
Created a conda virtual env
Then, ran the install commands
But the issue arises when I attempt to run the testing suite
But since pytest wasn't originally installed as part of pip it throws
Which can be fixed with
conda install pytest
However, after install pytest, when I attempt I run
pytest .
it cannot find the pywt extensionsModuleNotFoundError: No module named 'pywt._extensions._pywt'
I've run this on my local fork and the main repo and have remade and cleaned the directory a few times, but have not had any luck. How can I install the extensions along with the repo?