Delgan / loguru

Python logging made (stupidly) simple
MIT License
18.69k stars 682 forks source link

Loguru fails to import in pypy/osx #1004

Closed direvius closed 5 months ago

direvius commented 8 months ago

I have a pypy installed with homebrew on OSX 12.5.1

➜  ~ pypy3.10 --version
Python 3.10.12 (af44d0b8114cb82c40a07bb9ee9c1ca8a1b3688c, Jun 25 2023, 12:34:25)
[PyPy 7.3.12 with GCC Apple LLVM 14.0.0 (clang-1400.0.29.202)]

I'm getting the following error while trying to import loguru:

>>>> import loguru
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/site-packages/loguru/__init__.py", line 31, in <module>
    logger.add(_sys.stderr)
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/site-packages/loguru/_logger.py", line 979, in add
    exception_formatter = ExceptionFormatter(
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/site-packages/loguru/_better_exceptions.py", line 157, in __init__
    self._lib_dirs = self._get_lib_dirs()
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/site-packages/loguru/_better_exceptions.py", line 166, in _get_lib_dirs
    paths = {sysconfig.get_path(name, scheme) for scheme in schemes for name in names}
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/site-packages/loguru/_better_exceptions.py", line 166, in <setcomp>
    paths = {sysconfig.get_path(name, scheme) for scheme in schemes for name in names}
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/sysconfig.py", line 596, in get_path
    return get_paths(scheme, vars, expand)[name]
KeyError: 'platstdlib'

I have been able to localize it to concrete key osx_framework_user:

>>>> sysconfig.get_path("platstdlib", "osx_framework_user")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/pypy3.10/7.3.12/libexec/lib/pypy3.10/sysconfig.py", line 596, in get_path
    return get_paths(scheme, vars, expand)[name]
KeyError: 'platstdlib'

This is because platstdlib corresponding key has leading spaces for some reason:

>>>> sysconfig.get_paths("osx_framework_user")
{'stdlib': '/Users/direvius/.local/lib/pypy', '    platstdlib': '/Users/direvius/.local/lib/pypy', 'purelib': '/Users/direvius/.local/lib/pypy/site-packages', 'platlib': '/Users/direvius/.local/lib/pypy/site-packages', 'include': '/Users/direvius/.local/include/pypy3.10', 'scripts': '/Users/direvius/.local/bin', 'data': '/Users/direvius/.local'}
Delgan commented 8 months ago

Thanks for the report.

This is actully a bug in PyPy, see https://foss.heptapod.net/pypy/pypy/-/issues/3954

direvius commented 8 months ago

thank you for a quick reply!

Delgan commented 5 months ago

Closing as it seems fixed upstream.