astropy / extension-helpers

Helpers to assist with building Python packages with compiled C/Cython extensions
https://extension-helpers.readthedocs.io
BSD 3-Clause "New" or "Revised" License
16 stars 12 forks source link

1.0.0: pytest is failing #41

Closed kloczek closed 1 year ago

kloczek commented 2 years ago

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-extension-helpers-1.0.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-extension-helpers-1.0.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --import-mode=importlib
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/extension-helpers-1.0.0, configfile: setup.cfg
plugins: hypothesis-6.40.0
collected 10 items / 3 errors

================================================================================== ERRORS ==================================================================================
________________________________________________ ERROR collecting build/lib/extension_helpers/tests/test_openmp_helpers.py _________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/extension-helpers-1.0.0/build/lib/extension_helpers/tests/test_openmp_helpers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
build/lib/extension_helpers/tests/test_openmp_helpers.py:11: in <module>
    from .._openmp_helpers import add_openmp_flags_if_available, generate_openmp_enabled_py
E   ModuleNotFoundError: No module named 'build.lib.extension_helpers._openmp_helpers'; 'build.lib.extension_helpers' is not a package
_________________________________________________ ERROR collecting build/lib/extension_helpers/tests/test_setup_helpers.py _________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/extension-helpers-1.0.0/build/lib/extension_helpers/tests/test_setup_helpers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
build/lib/extension_helpers/tests/test_setup_helpers.py:10: in <module>
    from .._setup_helpers import get_compiler, get_extensions
E   ModuleNotFoundError: No module named 'build.lib.extension_helpers._setup_helpers'; 'build.lib.extension_helpers' is not a package
_____________________________________________________ ERROR collecting build/lib/extension_helpers/tests/test_utils.py _____________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/extension-helpers-1.0.0/build/lib/extension_helpers/tests/test_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
build/lib/extension_helpers/tests/test_utils.py:4: in <module>
    from .._utils import import_file, write_if_different
E   ModuleNotFoundError: No module named 'build.lib.extension_helpers._utils'; 'build.lib.extension_helpers' is not a package
========================================================================= short test summary info ==========================================================================
ERROR build/lib/extension_helpers/tests/test_openmp_helpers.py
ERROR build/lib/extension_helpers/tests/test_setup_helpers.py
ERROR build/lib/extension_helpers/tests/test_utils.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================ 3 errors in 0.36s =============================================================================
kloczek commented 2 years ago

Why test suite has hardcodeed build path? 🤔 I seee domething like that first time ever .. (and I've already packaged +800 python modules)

kloczek commented 2 years ago

Also it looks like tst suite expect sprobably extension_helpers._utils which probably is expected that will be DSO module and during the build I dont see used cython to produce DSO.

+ /usr/bin/python3 -sBm build -w --no-isolation
* Getting dependencies for wheel...
running egg_info
creating extension_helpers.egg-info
writing extension_helpers.egg-info/PKG-INFO
writing dependency_links to extension_helpers.egg-info/dependency_links.txt
writing entry points to extension_helpers.egg-info/entry_points.txt
writing requirements to extension_helpers.egg-info/requires.txt
writing top-level names to extension_helpers.egg-info/top_level.txt
writing manifest file 'extension_helpers.egg-info/SOURCES.txt'
listing git files failed - pretending there aren't any
reading manifest file 'extension_helpers.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'ah_bootstrap.py'
warning: no previously-included files found matching '*.pyc'
warning: no previously-included files found matching '*.o'
no previously-included directories found matching 'build'
adding license file 'LICENSE.rst'
writing manifest file 'extension_helpers.egg-info/SOURCES.txt'
* Building wheel...
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/extension_helpers
copying extension_helpers/__init__.py -> build/lib/extension_helpers
copying extension_helpers/_openmp_helpers.py -> build/lib/extension_helpers
copying extension_helpers/_setup_helpers.py -> build/lib/extension_helpers
copying extension_helpers/_utils.py -> build/lib/extension_helpers
copying extension_helpers/conftest.py -> build/lib/extension_helpers
copying extension_helpers/version.py -> build/lib/extension_helpers
creating build/lib/extension_helpers/tests
copying extension_helpers/tests/__init__.py -> build/lib/extension_helpers/tests
copying extension_helpers/tests/test_openmp_helpers.py -> build/lib/extension_helpers/tests
copying extension_helpers/tests/test_setup_helpers.py -> build/lib/extension_helpers/tests
copying extension_helpers/tests/test_utils.py -> build/lib/extension_helpers/tests
creating build/lib/extension_helpers/src
copying extension_helpers/src/compiler.c -> build/lib/extension_helpers/src
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/__init__.py -> build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/_openmp_helpers.py -> build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/_setup_helpers.py -> build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/_utils.py -> build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/conftest.py -> build/bdist.linux-x86_64/wheel/extension_helpers
copying build/lib/extension_helpers/version.py -> build/bdist.linux-x86_64/wheel/extension_helpers
creating build/bdist.linux-x86_64/wheel/extension_helpers/tests
copying build/lib/extension_helpers/tests/__init__.py -> build/bdist.linux-x86_64/wheel/extension_helpers/tests
copying build/lib/extension_helpers/tests/test_openmp_helpers.py -> build/bdist.linux-x86_64/wheel/extension_helpers/tests
copying build/lib/extension_helpers/tests/test_setup_helpers.py -> build/bdist.linux-x86_64/wheel/extension_helpers/tests
copying build/lib/extension_helpers/tests/test_utils.py -> build/bdist.linux-x86_64/wheel/extension_helpers/tests
creating build/bdist.linux-x86_64/wheel/extension_helpers/src
copying build/lib/extension_helpers/src/compiler.c -> build/bdist.linux-x86_64/wheel/extension_helpers/src
running install_egg_info
running egg_info
writing extension_helpers.egg-info/PKG-INFO
writing dependency_links to extension_helpers.egg-info/dependency_links.txt
writing entry points to extension_helpers.egg-info/entry_points.txt
writing requirements to extension_helpers.egg-info/requires.txt
writing top-level names to extension_helpers.egg-info/top_level.txt
listing git files failed - pretending there aren't any
reading manifest file 'extension_helpers.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'ah_bootstrap.py'
warning: no previously-included files found matching '*.pyc'
warning: no previously-included files found matching '*.o'
no previously-included directories found matching 'build'
adding license file 'LICENSE.rst'
writing manifest file 'extension_helpers.egg-info/SOURCES.txt'
Copying extension_helpers.egg-info to build/bdist.linux-x86_64/wheel/extension_helpers-1.0.0-py3.8.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/extension_helpers-1.0.0.dist-info/WHEEL
creating '/home/tkloczko/rpmbuild/BUILD/extension-helpers-1.0.0/dist/tmpna9ic7ne/extension_helpers-1.0.0-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'extension_helpers/__init__.py'
adding 'extension_helpers/_openmp_helpers.py'
adding 'extension_helpers/_setup_helpers.py'
adding 'extension_helpers/_utils.py'
adding 'extension_helpers/conftest.py'
adding 'extension_helpers/version.py'
adding 'extension_helpers/src/compiler.c'
adding 'extension_helpers/tests/__init__.py'
adding 'extension_helpers/tests/test_openmp_helpers.py'
adding 'extension_helpers/tests/test_setup_helpers.py'
adding 'extension_helpers/tests/test_utils.py'
adding 'extension_helpers-1.0.0.dist-info/LICENSE.rst'
adding 'extension_helpers-1.0.0.dist-info/METADATA'
adding 'extension_helpers-1.0.0.dist-info/WHEEL'
adding 'extension_helpers-1.0.0.dist-info/entry_points.txt'
adding 'extension_helpers-1.0.0.dist-info/top_level.txt'
adding 'extension_helpers-1.0.0.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel
Successfully built extension_helpers-1.0.0-py3-none-any.whl
kloczek commented 2 years ago

gentle ping 😋

astrofrog commented 2 years ago

Why test suite has hardcodeed build path? 🤔

Could you clarify what you mean here?

I'm not managing to reproduce this issue - could you perhaps recommend a docker image I could reproduce this in, and the exact commands you are using? (in particular it wasn't clear how exactly you installed the built wheel). Thanks!

astrofrog commented 2 years ago

Note that also if you run:

/usr/bin/pytest -ra --import-mode=importlib

in the root of the source folder, it will likely try and pick up the tests inside the build folder and inside the extension_helpers directory, and in both cases the tests will probably be importing extension_helpers from their parent folders rather than the installed version?

astrofrog commented 2 years ago

If you want to test the installed version, it would be better to switch to an empty directory and run pytest --pyargs extension_helpers

kloczek commented 2 years ago

If you want to test the installed version, it would be better to switch to an empty directory and run pytest --pyargs extension_helpers

That works. Thx However that param would be goof to add to pytest.ini or to test args in setup.cfg to be able use pytest without args.

Cadair commented 2 years ago

I guess we could add testpaths to the pytest config in setup.cfg (https://github.com/sunpy/sunpy/blob/main/setup.cfg#L114) to make it only pick up the source tree when running without any args.

If you do want to test an installed version of a package though, you are better using --pyargs if that package has also installed it's tests.

astrofrog commented 1 year ago

This should be fixed by #54