ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
71 stars 39 forks source link

xml2rfc should not break on weasyprint if that isn't actually needed #962

Open cabo opened 1 year ago

cabo commented 1 year ago

Describe the issue

After something randomly changed in my Python environment:

Traceback (most recent call last):
  File "/Users/cabo/bin/xml2rfc", line 5, in <module>
    from xml2rfc.run import main
  File "/Users/cabo/lib/python3.10/site-packages/xml2rfc/__init__.py", line 38, in <module>
    from weasyprint.text.ffi import pango
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 945, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1439, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1405, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1255, in __iter__
  File "<frozen importlib._bootstrap_external>", line 1242, in _recalculate
  File "<frozen importlib._bootstrap_external>", line 1238, in _get_parent_path
KeyError: 'weasyprint'

I did not try to actually generate PDF, so xml2rfc should not depend on that loading properly.

Code of Conduct

kesara commented 1 year ago

If you still have this environment, can you provide the Python version, xml2rfc version and the WeasyPrint version? Because I could not recreate this error with different WeasyPrint / xml2rfc combinations.

xml2rfc already checks for ImportError, OSError and AttributeError. Maybe we can add KeyError to the list or swallow all Exceptions.

cabo commented 1 year ago

The error occurred when there was no working WeasyPrint installed (there may have been remnants of one). I have since fixed the problem that prevented installing WeasyPrint on that machine, so I don't have an easy way to reproduce.

cabo commented 1 year ago

Python version must have been python3.10 (see messages above).

kesara commented 1 year ago

Thank you. This looks like an error occurred due to a Python environment configuration issue. There's already logic guarding against not having WeasyPrint or an older version of WeasyPrint. So xml2rfc will not break if WeasyPrint is not installed.