malthe / chameleon

Fast HTML/XML template engine for Python
https://chameleon.readthedocs.io
Other
176 stars 64 forks source link

4.3.0 release is breaking on Windows #395

Closed gr8jam closed 9 months ago

gr8jam commented 9 months ago

After upgrading Chameleon package to the latest release (4.3.0) I noticed that my project stopped working on Windows (on macOS everything seems fine). Here is the last part of the exception's traceback:

  ...
  File "C:\Users\myproject\venv\Lib\site-packages\chameleon\template.py", line 391, in read
    files = importlib_resources.files(self.spec.pname)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2032.0_x64__qbz5n2kfra8p0\Lib\importlib\resources\_common.py", line 22, in files
    return from_package(get_package(package))
                        ^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2032.0_x64__qbz5n2kfra8p0\Lib\importlib\resources\_common.py", line 53, in get_package
    resolved = resolve(package)
               ^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2032.0_x64__qbz5n2kfra8p0\Lib\importlib\resources\_common.py", line 44, in resolve
    return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2032.0_x64__qbz5n2kfra8p0\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C'

After looking at the Changes, my hunch is that it's something related to:

  • Replace pkg_resources with newer and faster importlib.resources and importlib.metadata. Just importing pkg_resources becomes slower and slower the more packages are installed.

but, I am not sure how to fix it.

malthe commented 9 months ago

This is a bug introduced in ad7a4985871946af9213745b24f093f0a369749d. Let me first add a Windows test run, then fix the issue.

gr8jam commented 9 months ago

Thanks for jumping on this so quickly!

mahmoud commented 9 months ago

I saw the changelog about 4.4.0 potentially fixing this, but alas, no such luck on my end: https://github.com/mahmoud/clastic/actions/runs/7241001024/job/19724620933?pr=37

malthe commented 9 months ago

@mahmoud strange I'll take a look.

malthe commented 9 months ago

@mahmoud something went wrong with the 4.4.0 release – I have released 4.4.1 to replace it.

mahmoud commented 8 months ago

Just circling back to confirm the new build worked. Thanks!