axiros / terminal_markdown_viewer

Styled Terminal Markdown Viewer
Other
1.8k stars 105 forks source link

Does not support Python 3.9 #86

Open fxcoudert opened 3 years ago

fxcoudert commented 3 years ago
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-req-build-8im_0e0r/setup.py", line 234, in <module>
        setup(
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/local/Cellar/mdv/1.7.4_1/libexec/lib/python3.9/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/install.py", line 546, in run
        self.run_command('build')
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/Cellar/python@3.9/3.9.0/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/private/tmp/pip-req-build-8im_0e0r/setup.py", line 184, in run
        out = template % self._get_context(src, outfile)
      File "/private/tmp/pip-req-build-8im_0e0r/setup.py", line 116, in _get_context
        c['body'] = self.md.convert(src)
      File "build/lib/markdown/__init__.py", line 375, in convert
        newRoot = treeprocessor.run(root)
      File "build/lib/markdown/treeprocessors.py", line 361, in run
        brs = root.getiterator('br')
    AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getiterator'
    Running setup.py install for Markdown: finished with status 'error'
ERROR: Command errored out with exit status 1: /usr/local/Cellar/mdv/1.7.4_1/libexec/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-req-build-8im_0e0r/setup.py'"'"'; __file__='"'"'/private/tmp/pip-req-build-8im_0e0r/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-q346dbmz/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/Cellar/mdv/1.7.4_1/libexec/include/site/python3.9/Markdown Check the logs for full command output.

From https://docs.python.org/3.9/whatsnew/3.9.html#removed :

Methods getchildren() and getiterator() in the ElementTree module have been removed. They were deprecated in Python 3.2. Use functions list() and iter() instead. The xml.etree.cElementTree module has been removed.

WillNye commented 3 years ago

Not sure if this is still an issue for you but I created a fork with 3.9 support https://github.com/WillNye/terminal_markdown_viewer that I'll be actively maintaining as it is used in several other frameworks I use. It's worth noting python2 support was dropped because it is no longer maintained.

To install pip3 install -U mdv3

davidrihtarsic commented 3 years ago

Hi, here is an easy patch for mdv working with python 3.9. Minor changes are needed. https://github.com/davidrihtarsic/davidrihtarsic.github.io/blob/master/Linux/src/patch_mdv_py_3.9.patch.

dhondta commented 3 years ago

For now, I get the following error while running my project's tests with Travis for Python 3.9 :

  File "/home/travis/virtualenv/python3.9.1/lib/python3.9/site-packages/mdv/markdownviewer.py", line 970, in formatter
      t = html_parser.unescape(t)
AttributeError: 'HTMLParser' object has no attribute 'unescape'

Does anybody get this error too ?

davidrihtarsic commented 3 years ago

Hi dhondta, I had exactly the same error and fixed it with the patch I've published. You can do it by using the patch or manually:

  1. edit .../.../.../markdownviewer.py
  2. and follow the content in the patch... change all red lines with green ones.
dhondta commented 3 years ago

Hi @davidrihtarsic Thank you very much for this quick response. However, applying your patch is perhaps not that convenient. Maybe @WillNye could apply a fix and publish the updated mdv3 package to PyPi ? This would be far better as this package can be used in the requirements of other packages and Travis CI builds...

davidrihtarsic commented 3 years ago

I totally agree with @dhondta. Applying a patch is not a solution.

WillNye commented 3 years ago

I don't mind incorporating any fixes @dhondta @davidrihtarsic. Could you give me an example that raises the exception when running mdv3?

dhondta commented 3 years ago

@WillNye OK, I figured out that a previous build failed because of mdv, not mdv3. Adapting my setup.cfg for installing mdv3 with Python 3.9 fixed the problem. So, no worry, your version is well fixed. Thank you so much. :tada:

TheLastGimbus commented 3 years ago

Hey how is this going? Neither mdv or mdv3 work for me :confused:

WillNye commented 3 years ago

@TheLastGimbus if you toss me an example that raises the exception as well as the traceback you're seeing I can look into it

TheLastGimbus commented 3 years ago
~$ mdv
... some stuff up here
    this is a Note

----
!!! question: You like this theme?
Styling Result
Traceback (most recent call last):
  File "/home/matiii/.local/bin/mdv", line 8, in <module>
    sys.exit(run())
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1657, in run
    print(main(**kw) if PY3 else str(main(**kw)))
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1375, in main
    the_html = MD.convert(md)
  File "/home/matiii/.local/lib/python3.9/site-packages/markdown/core.py", line 268, in convert
    newRoot = treeprocessor.run(root)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1150, in run
    formatter(doc, out)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1145, in formatter
    formatter(c, out, hir + 1, parent=el)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 970, in formatter
    t = html_parser.unescape(t)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
~/my-project$ mdv README.md 
Traceback (most recent call last):
  File "/home/matiii/.local/bin/mdv", line 8, in <module>
    sys.exit(run())
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1657, in run
    print(main(**kw) if PY3 else str(main(**kw)))
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1375, in main
    the_html = MD.convert(md)
  File "/home/matiii/.local/lib/python3.9/site-packages/markdown/core.py", line 268, in convert
    newRoot = treeprocessor.run(root)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1150, in run
    formatter(doc, out)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1145, in formatter
    formatter(c, out, hir + 1, parent=el)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 970, in formatter
    t = html_parser.unescape(t)
AttributeError: 'HTMLParser' object has no attribute 'unescape'

!!! question: You like this theme? Styling Result Traceback (most recent call last): File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 505, in style_ansi lexer = get_lexer_by_name(lexer_alias(lang)) File "/home/matiii/.local/lib/python3.9/site-packages/pygments/lexers/init.py", line 118, in get_lexer_by_name raise ClassNotFound('no lexer for alias %r found' % _alias) pygments.util.ClassNotFound: no lexer for alias 'language-python' found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/matiii/.local/bin/mdv", line 8, in sys.exit(run()) File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1616, in run print(main(**kw)) File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1365, in main raw = tags.code(raw.strip(), from_fenced_block=1, lang=lang) File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 690, in code s = style_ansi(raw_code, lang=lang) File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 507, in style_ansi print(col(R, 'Lexer for %s not found' % lang)) File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 555, in col if _strt in s: TypeError: argument of type 'int' is not iterable

```python
~/my-project$ mdv README.md
Traceback (most recent call last):
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 505, in style_ansi
    lexer = get_lexer_by_name(lexer_alias(lang))
  File "/home/matiii/.local/lib/python3.9/site-packages/pygments/lexers/__init__.py", line 118, in get_lexer_by_name
    raise ClassNotFound('no lexer for alias %r found' % _alias)
pygments.util.ClassNotFound: no lexer for alias 'language-bash' found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matiii/.local/bin/mdv", line 8, in <module>
    sys.exit(run())
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1616, in run
    print(main(**kw))
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1365, in main
    raw = tags.code(raw.strip(), from_fenced_block=1, lang=lang)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 690, in code
    s = style_ansi(raw_code, lang=lang)
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 507, in style_ansi
    print(col(R, 'Lexer for %s not found' % lang))
  File "/home/matiii/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 555, in col
    if _strt in s:
TypeError: argument of type 'int' is not iterable
WillNye commented 3 years ago

@TheLastGimbus Thanks for sending this over! I'm able to reproduce the problem and it looks like it stems from an existing issue where numbers in the markdown were being cast to an int. There was also an issue where an exception wasn't being handled properly. I'm busy with work today but I'll try to get to it today or tomorrow. In the meantime, I know it's a PITA an I'm sorry to ask but is there any way you could make an issue for this here? I don't actually maintain the legacy mdv or the repo this issue is filed under an I wanted to start keeping track of everything within my fork.

TheLastGimbus commented 3 years ago

Could do, but there is no issues tab:

image