bavovanachte / sphinx-wavedrom

A sphinx extension that allows including wavedrom diagrams by using its text-based representation
MIT License
32 stars 18 forks source link

Python3.10 issue: ImportError: cannot import name 'Mapping' from 'collections' #38

Closed jannismain closed 1 year ago

jannismain commented 2 years ago

When trying to use sphinxcontrib-wavedrom with Python3.10 I get the following traceback:

Python 3.10.0 (default, Nov 10 2021, 13:56:10) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinxcontrib.wavedrom
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.10/site-packages/sphinxcontrib/wavedrom.py", line 15, in <module>
    from .wavedrom_render_image import render_wavedrom_image
  File ".../python3.10/site-packages/sphinxcontrib/wavedrom_render_image.py", line 7, in <module>
    from wavedrom import render
  File ".../python3.10/site-packages/wavedrom/__init__.py", line 29, in <module>
    from .waveform import WaveDrom
  File ".../python3.10/site-packages/wavedrom/waveform.py", line 33, in <module>
    from attrdict import AttrDict
  File ".../python3.10/site-packages/attrdict/__init__.py", line 5, in <module>
    from attrdict.mapping import AttrMap
  File ".../python3.10/site-packages/attrdict/mapping.py", line 4, in <module>
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (.../python3.10/collections/__init__.py)

This seems to be related to the attrdict requirement, which was archived by the owner and therefore unlikely to be updated for Python3.10.

jannismain commented 2 years ago

Seems to be already reported here: https://github.com/wallento/wavedrompy/issues/32

I first didn't see that wavedrom(py) is separate from this project.

MattEttus commented 2 years ago

Apparently Python 10 moved Mapping. The solution is here:

https://stackoverflow.com/questions/69381312/in-vs-code-importerror-cannot-import-name-mapping-from-collections

wallento commented 2 years ago

Thanks, looks easy to solve an will pick it up asap.

wallento commented 2 years ago

~Is not that easy to solve, but I am still at it, hope to land it this week.~

wallento commented 2 years ago

Just replaced it with the boilerplate implementation of the AttrDict feature we needed.

Can you please try locally:

pip install git+https://github.com/wallento/wavedrompy.git@05b1220f870ae513b7a4d4dc73ca4741c66a6c08

I will create a release once confirmed, @bavovanachte

bavovanachte commented 2 years ago

@wallento Haven't checked the output in detail, but at least the Extension error has disappeared. Thanks for the fix!

$ python --version
Python 3.10.3+

$ make -C example clean dirhtml WAVEDROM_HTML_NOJSINLINE=1
make: Entering directory 'sphinx-wavedrom/example'
rm -rf build/*
sphinx-build -b dirhtml -d build/doctrees  -W -D wavedrom_html_jsinline=0 source build/dirhtml
Running Sphinx v4.4.0

Extension error:
Could not import extension sphinxcontrib.wavedrom (exception: cannot import name 'Mapping' from 'collections' (/home/bvn/.pyenv/versions/3.10-dev/lib/python3.10/collections/__init__.py))
make: *** [Makefile:70: dirhtml] Error 2
make: Leaving directory 'sphinx-wavedrom/example'

$ pip install git+https://github.com/wallento/wavedrompy.git@05b1220f870ae513b7a4d4dc73ca4741c66a6c08
Looking in indexes: https://pypi.org/simple, https://dsl.colo.elex.be/artifactory/api/pypi/pypi-release/simple
Collecting git+https://github.com/wallento/wavedrompy.git@05b1220f870ae513b7a4d4dc73ca4741c66a6c08
  Cloning https://github.com/wallento/wavedrompy.git (to revision 05b1220f870ae513b7a4d4dc73ca4741c66a6c08) to /tmp/pip-req-build-i9_c6584
  Running command git clone --filter=blob:none --quiet https://github.com/wallento/wavedrompy.git /tmp/pip-req-build-i9_c6584
  Running command git rev-parse -q --verify 'sha^05b1220f870ae513b7a4d4dc73ca4741c66a6c08'
  Running command git fetch -q https://github.com/wallento/wavedrompy.git 05b1220f870ae513b7a4d4dc73ca4741c66a6c08
  Running command git checkout -q 05b1220f870ae513b7a4d4dc73ca4741c66a6c08
  Resolved https://github.com/wallento/wavedrompy.git to commit 05b1220f870ae513b7a4d4dc73ca4741c66a6c08
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for wavedrom, since package 'wheel' is not installed.
Installing collected packages: wavedrom
  Attempting uninstall: wavedrom
    Found existing installation: wavedrom 2.0.3.post2
    Uninstalling wavedrom-2.0.3.post2:
      Successfully uninstalled wavedrom-2.0.3.post2
  Running setup.py install for wavedrom ... done
Successfully installed wavedrom-2.0.3.post3.dev16+g05b1220

$ make -C example clean dirhtml WAVEDROM_HTML_NOJSINLINE=1
make: Entering directory 'sphinx-wavedrom/example'
rm -rf build/*
sphinx-build -b dirhtml -d build/doctrees  -W -D wavedrom_html_jsinline=0 source build/dirhtml
Running Sphinx v4.4.0
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [dirhtml]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                                                                                                                          
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                                                                                                           
generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.

The HTML pages are in build/dirhtml.

Build finished. The HTML pages are in build/dirhtml.
amykyta3 commented 2 years ago

@wallento - Confirmed your fix works and generated output looks correct.

jannismain commented 1 year ago

can confirm it is working on my end as well...