splunk / splunk-sdk-python

Splunk Software Development Kit for Python
http://dev.splunk.com
Apache License 2.0
687 stars 369 forks source link

ImportWarning: _SixMetaPathImporter.find_spec() not found starting from python3.10 #535

Closed VmirGerts closed 6 months ago

VmirGerts commented 1 year ago

Describe the bug Starting from python version "3.10", running pytest -W error with a test file which imports splunklib produces following ImportWarning (interpreted as an error due to the "-W error" flag):

E ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module() (see full log below)

To Reproduce Note: the steps 1 and 3 are only necessary because Ubuntu20.04 does not provide python3.10 out of the box.

  1. If python3.10 is not installed:
    add-apt-repository ppa:deadsnakes/ppa
    apt install -y python3.10 python3.10-dev python3.10-venv python3.10-distutils
  2. Create and activate python3.10 environment:
    virtualenv venv -p /usr/bin/python3.10
    . venv/bin/activate
  3. Upgrade pip
    curl -sS https://bootstrap.pypa.io/get-pip.py | python
  4. Install required packages
    pip install pytest splunk-sdk
  5. Create following test file 'test_splunk_sdk.py'
    
    import splunklib

def test_splunklib(): pass

6. Run pytest with "-W error"
```shell
pytest test_splunk_sdk.py -W error

Expected behavior No ImportWarning

Logs or Screenshots Complete log:

$ pytest -W error test_splunk_sdk.py 
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.10.12, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/username/test_splunk_sdk
collected 0 items / 1 error                                                                                                                                                            

======================================================================================== ERRORS ========================================================================================
_________________________________________________________________________ ERROR collecting test_splunk_sdk.py __________________________________________________________________________
<frozen importlib._bootstrap>:939: in _find_spec
    ???
E   AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:
venv/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
venv/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
venv/lib/python3.10/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
venv/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
venv/lib/python3.10/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
venv/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
venv/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
venv/lib/python3.10/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
test_splunk_sdk.py:2: in <module>
    import splunklib
venv/lib/python3.10/site-packages/splunklib/__init__.py:18: in <module>
    from splunklib.six.moves import map
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1002: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:941: in _find_spec
    ???
<frozen importlib._bootstrap>:914: in _find_spec_legacy
    ???
E   ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module()
=============================================================================== short test summary info ================================================================================
ERROR test_splunk_sdk.py - ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================================== 1 error in 0.12s ===================================================================================

SDK (please complete the following information):

Fix suggestion

Update the six.py with the newer version from the official repo: https://github.com/benjaminp/six/blob/master/six.py The newer version provides the find_spec() function.

ashah-splunk commented 11 months ago

Hi @VmirGerts, this quarter we are planning on a new beta release for the Python SDK with updated support for Python 3.9 and hope to resolve this issue as we are removing six.py dependency. Please watch for updates here.

ashah-splunk commented 6 months ago

Hi @VmirGerts Sorry for the delay, we have published a new version of Python SDK v2.0.0 with Python v3.7+ support. Request you to use the latest SDK and let us know if the issue is resolved. Thanks

VmirGerts commented 6 months ago

Hi @ashah-splunk , thank you for the update! I can confirm that the issue is fixed now.

Btw, just for the purpose of completeness: I realized that one could just run python -Werror -c "import splunklib" to reproduce the error. So creating a test file was not necessary.