Tufin / pytos

A Python SDK for Tufin Orchestration Suite
https://www.tufin.com
Apache License 2.0
55 stars 21 forks source link

[Bug] Python 3.10.x not working #49

Open Cellebyte opened 2 years ago

Cellebyte commented 2 years ago

As of the new python release 3.10.x some modules which are used as a dependency are not working for pytos. It would be great if the dependencies can be updated to work also with python 3.10.

https://bugs.python.org/issue25988

$ python -m tufin.pytos.module
Traceback (most recent call last):
    from pytos.secureapp.helpers import Secure_App_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/secureapp/helpers.py", line 16, in <module>
    from pytos.securechange.helpers import Secure_Change_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/securechange/helpers.py", line 19, in <module>
    from pytos.common.helpers import Secure_API_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/common/helpers.py", line 7, in <module>
    from pytos.common import rest_requests
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/common/rest_requests.py", line 16, in <module>
    import requests_toolbelt
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
    from .adapters import SSLAdapter, SourceAddressAdapter
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
    from .ssl import SSLAdapter
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
    from .._compat import poolmanager
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/_compat.py", line 11, in <module>
    from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
marioland commented 2 years ago

Workaround in pytos\common\rest_requests.py insert from collections import abc as collections instead of the top line

Cellebyte commented 2 years ago

@marioland the workaround only works when you manually patch the library. Would be better to fix it upstream.

Cellebyte commented 1 year ago

for the people waiting for #52 I have a working hotfix.

# <project_name>/_hotfix.py
from collections.abc import MutableMapping, Mapping
from collections import (
    ChainMap,
    namedtuple,
    OrderedDict,
    deque,
    defaultdict,
    Counter,
    UserDict,
    UserList,
    UserString,
)
from collections import abc

__all__ = [
    "ChainMap",
    "MutableMapping",
    "Mapping",
    "namedtuple",
    "OrderedDict",
    "abc",
    "deque",
    "defaultdict",
    "Counter",
    "UserDict",
    "UserList",
    "UserString",
]
# <project_name>.__init__.py
import sys
import <project_name>._hotfix as collections

sys.modules["collections"] = collections