Skip to content
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

Tests fail: ImportError: cannot import name '__version__' from 'scikit_build_core._version' #387

Closed
yurivict opened this issue Jun 21, 2023 · 9 comments · Fixed by #390
Closed

Comments

@yurivict
Copy link

cd /usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5 && /usr/bin/env XDG_DATA_HOME=/usr/ports/devel/py-scikit-build-core/work-py39  XDG_CONFIG_HOME=/usr/ports/devel/py-scikit-build-core/work-py39  XDG_CACHE_HOME=/usr/ports/devel/py-scikit-build-core/work-py39/.cache  HOME=/usr/ports/devel/py-scikit-build-core/work-py39 PATH=/usr/local/libexec/ccache:/usr/ports/devel/py-scikit-build-core/work-py39/.bin:/home/yuri/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin PKG_CONFIG_LIBDIR=/usr/ports/devel/py-scikit-build-core/work-py39/.pkgconfig:/usr/local/libdata/pkgconfig:/usr/local/share/pkgconfig:/usr/libdata/pkgconfig MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe  -fstack-protector-strong -fno-strict-aliasing "  CPP="cpp" CPPFLAGS=""  LDFLAGS=" -fstack-protector-strong " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing  "  MANPREFIX="/usr/local" CCACHE_DIR="/tmp/.ccache" BSD_INSTALL_PROGRAM="install  -s -m 555"  BSD_INSTALL_LIB="install  -s -m 0644"  BSD_INSTALL_SCRIPT="install  -m 555"  BSD_INSTALL_DATA="install  -m 0644"  BSD_INSTALL_MAN="install  -m 444" PYTHONPATH=/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages /usr/local/bin/python3.9 -m pytest -k '' -rs -v -o addopts= 
===================================================================================================== test session starts ======================================================================================================
platform freebsd13 -- Python 3.9.17, pytest-7.3.1, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/.hypothesis/examples')
Using --randomly-seed=3850044126
metadata: {'Python': '3.9.17', 'Platform': 'FreeBSD-13.2-STABLE-amd64-64bit-ELF', 'Packages': {'pytest': '7.3.1', 'pluggy': '1.0.0'}, 'Plugins': {'forked': '1.6.0', 'hypothesis': '6.75.9', 'flakes': '4.0.5', 'mypy-plugins': '1.11.1', 'cov': '2.9.0', 'randomly': '3.12.0', 'timeout': '2.1.0', 'rerunfailures': '11.1.2', 'flaky': '3.7.0', 'xdist': '2.5.0', 'env': '0.6.2', 'mock': '3.10.0', 'metadata': '3.0.0', 'html': '3.2.0', 'benchmark': '4.0.0'}}
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
installed packages of interest: build==0.10.0 packaging==23.1 pathspec==0.11.1 pip==23.1.2 pyproject_metadata==0.7.1 scikit_build_core==0.4.5 setuptools==63.1.0 virtualenv==20.23.0 wheel==0.40.0
sysconfig platform: freebsd-13.2-STABLE-amd64
rootdir: /usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5
configfile: pyproject.toml
testpaths: tests
plugins: forked-1.6.0, hypothesis-6.75.9, flakes-4.0.5, mypy-plugins-1.11.1, cov-2.9.0, randomly-3.12.0, timeout-2.1.0, rerunfailures-11.1.2, flaky-3.7.0, xdist-2.5.0, env-0.6.2, mock-3.10.0, metadata-3.0.0, html-3.2.0, benchmark-4.0.0
collected 83 items / 7 errors                                                                                                                                                                                                  

============================================================================================================ ERRORS ============================================================================================================
____________________________________________________________________________________________ ERROR collecting tests/test_builder.py ____________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_builder.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_builder.py:12: in <module>
    from scikit_build_core.builder.builder import Builder, archs_to_tags, get_archs
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/builder/builder.py:15: in <module>
    from ..cmake import CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
_________________________________________________________________________________________ ERROR collecting tests/test_cmake_config.py __________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_cmake_config.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_cmake_config.py:10: in <module>
    from scikit_build_core.cmake import CMake, CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
____________________________________________________________________________________________ ERROR collecting tests/test_fileapi.py ____________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_fileapi.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_fileapi.py:11: in <module>
    from scikit_build_core.cmake import CMake, CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
_______________________________________________________________________________________ ERROR collecting tests/test_generator_default.py _______________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_generator_default.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_generator_default.py:1: in <module>
    from scikit_build_core.builder.generator import parse_help_default
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/builder/generator.py:12: in <module>
    from ..cmake import CMake
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
_______________________________________________________________________________________ ERROR collecting tests/test_pyproject_pep517.py ________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_pyproject_pep517.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_pyproject_pep517.py:9: in <module>
    import build.util
/usr/local/lib/python3.9/site-packages/build/util.py:13: in <module>
    import build.env
/usr/local/lib/python3.9/site-packages/build/env.py:26: in <module>
    import virtualenv
/usr/local/lib/python3.9/site-packages/virtualenv/__init__.py:3: in <module>
    from .run import cli_run, session_via_cli
/usr/local/lib/python3.9/site-packages/virtualenv/run/__init__.py:14: in <module>
    from .plugin.creators import CreatorSelector
/usr/local/lib/python3.9/site-packages/virtualenv/run/plugin/creators.py:6: in <module>
    from virtualenv.create.via_global_ref.builtin.builtin_way import VirtualenvBuiltin
/usr/local/lib/python3.9/site-packages/virtualenv/create/via_global_ref/builtin/builtin_way.py:5: in <module>
    from virtualenv.create.creator import Creator
/usr/local/lib/python3.9/site-packages/virtualenv/create/creator.py:13: in <module>
    from virtualenv.discovery.cached_py_info import LogCmd
/usr/local/lib/python3.9/site-packages/virtualenv/discovery/cached_py_info.py:25: in <module>
    _CACHE[Path(sys.executable)] = PythonInfo()
/usr/local/lib/python3.9/site-packages/virtualenv/discovery/py_info.py:100: in __init__
    self.distutils_install = self._distutils_install().copy()
/usr/local/lib/python3.9/site-packages/virtualenv/discovery/py_info.py:183: in _distutils_install
    d = dist.Distribution({"script_args": "--no-user-cfg"})  # conf files not parsed so they do not hijack paths
/usr/local/lib/python3.9/site-packages/setuptools/dist.py:476: in __init__
    _Distribution.__init__(
/usr/local/lib/python3.9/site-packages/setuptools/_distutils/dist.py:275: in __init__
    self.finalize_options()
/usr/local/lib/python3.9/site-packages/setuptools/dist.py:899: in finalize_options
    for ep in sorted(loaded, key=by_order):
/usr/local/lib/python3.9/site-packages/setuptools/dist.py:898: in <lambda>
    loaded = map(lambda e: e.load(), filtered)
/usr/local/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py:194: in load
    module = import_module(match.group('module'))
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/setuptools/build_cmake.py:14: in <module>
    from ..builder.builder import Builder, get_archs
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/builder/builder.py:15: in <module>
    from ..cmake import CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
__________________________________________________________________________________________ ERROR collecting tests/test_simple_pure.py __________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_simple_pure.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_simple_pure.py:13: in <module>
    from scikit_build_core.cmake import CMake, CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:21: in <module>
    from ._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
________________________________________________________________________________________ ERROR collecting tests/test_wheelfile_utils.py ________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_wheelfile_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_wheelfile_utils.py:7: in <module>
    import scikit_build_core.build._wheelfile
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/build/_wheelfile.py:25: in <module>
    from .._version import __version__
E   ImportError: cannot import name '__version__' from 'scikit_build_core._version' (/usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 7 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================================== 7 errors in 2.60s =======================================================================================================
*** Error code 2

Version: 0.4.5
Python-3.9
FreeBSD 13.2

@LecrisUT
Copy link
Collaborator

How did you install scikit-build-core? The os distribution appears to be 0.3.1 but you are reporting about 0.4.5. Also can you print out the file _version.py?:

$ cat /usr/ports/devel/py-scikit-build-core/work-py39/stage/usr/local/lib/python3.9/site-packages/scikit_build_core/_version.py

My suspicion is that a version of setuptools_scm or a combination with the python version generates unexpected form of _version.py

@henryiii
Copy link
Collaborator

Ahh, that's an old version of setuptools_scm. I've hit that before. :/ Modern setuptools_scm create a __version__ alias. Older ones did not.

@henryiii
Copy link
Collaborator

PS, you really need to get a newer version of setuptools_scm eventually in FreeBSD. ;)

henryiii added a commit that referenced this issue Jun 21, 2023
Fix #387. We were importing this correctly in `__init__.py`, but missed
this in a couple of other places. Removed from `.pyi` file to have mypy
find this in the future.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@yurivict
Copy link
Author

@henryiii

I've submitted the request to update the setuptools_scm port.
But the above patch doesn't fix the problem for an older setuptools_scm - test errors are still there.

@henryiii
Copy link
Collaborator

What are the errors that remain?

@yurivict
Copy link
Author

Now many tests fail with:

____________________________________________________________________________________________ ERROR collecting tests/test_builder.py ____________________________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-scikit-build-core/work-py39/scikit_build_core-0.4.5/tests/test_builder.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_builder.py:12: in <module>
    from scikit_build_core.builder.builder import Builder, archs_to_tags, get_archs
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/builder/builder.py:15: in <module>
    from ..cmake import CMaker
../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:18: in <module>
    from .. import __version__
E   ImportError: attempted relative import beyond top-level package

@henryiii
Copy link
Collaborator

henryiii commented Jun 21, 2023

../stage/usr/local/lib/python3.9/site-packages/scikit_build_core/cmake.py:18: in <module>
    from .. import __version__

Are you sure the patch was applied correctly? For line 18, I see:

from . import __version__

(One dot instead of two)

@yurivict
Copy link
Author

Sorry, the previous errors were from incorrectly applied patch.

Now I am using the latest revision, and it fails this way:

===>  Building for py39-scikit-build-core-0.4.5.13
* Getting build dependencies for wheel...
* Building wheel...
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
  File "/usr/local/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/usr/local/lib/python3.9/site-packages/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
    return _build_backend().build_wheel(wheel_directory, config_settings,
  File "/usr/local/lib/python3.9/site-packages/hatchling/build.py", line 56, in build_wheel
    return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
  File "/usr/local/lib/python3.9/site-packages/hatchling/builders/plugin/interface.py", line 93, in build
    self.metadata.validate_fields()
  File "/usr/local/lib/python3.9/site-packages/hatchling/metadata/core.py", line 243, in validate_fields
    _ = self.version
  File "/usr/local/lib/python3.9/site-packages/hatchling/metadata/core.py", line 128, in version
    self._version = self._get_version()
  File "/usr/local/lib/python3.9/site-packages/hatchling/metadata/core.py", line 226, in _get_version
    version = self.hatch.version.cached
  File "/usr/local/lib/python3.9/site-packages/hatchling/metadata/core.py", line 1415, in cached
    raise type(e)(message) from None
LookupError: Error getting the version from source `vcs`: setuptools-scm was unable to detect version for /usr/ports/devel/py-scikit-build-core/work-py39/scikit-build-core-0.4.5-13-g164ffe0.

Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj

ERROR Backend subprocess exited when trying to invoke build_wheel
*** Error code 1

@henryiii
Copy link
Collaborator

Okay, that's better. I assume that's because you aren't on a version or using a patch; you can set SETUPTOOLS_PRETEND_VERSION to something to make it just use that version. It should also be able to pick up the version from the official git tarballs (modern git using git archive) (ignore the "such as GitHub's tarballs" comment in the error message, that should be wrong).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants