getlogbook / logbook

A cool logging replacement for Python.
http://logbook.readthedocs.org
Other
1.48k stars 165 forks source link

Fix version attr module path with setuptools static attr parser #363

Closed jameshilliard closed 1 year ago

jameshilliard commented 1 year ago

Setuptools attr parser does not support following imports which results in setuptools falling back to dynamically executing the module during a build which can break when runtime dependencies are not yet present.

See: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#attr

Fixes:

Traceback (most recent call last):
  File "/home/buildroot/buildroot/output/per-package/python-logbook/host/lib/python3.11/site-packages/setuptools/config/expand.py", line 193, in read_attr
    return getattr(StaticModule(module_name, spec), attr_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildroot/buildroot/output/per-package/python-logbook/host/lib/python3.11/site-packages/setuptools/config/expand.py", line 87, in __getattr__
    raise AttributeError(f"{self.name} has no attribute {attr}") from e
AttributeError: logbook has no attribute __version__
RazerM commented 1 year ago

In which scenario does this actually fail? I can do pip install --no-binary logbook logbook in a clean venv no bother.

I agree the StaticModule branch is better and I'll accept the PR, but I don't see any deprecation notice about the fallback method.

jameshilliard commented 1 year ago

In which scenario does this actually fail?

When cross compiling for example with a host python interpreter that say doesn't have say ssl support.

I can do pip install --no-binary logbook logbook in a clean venv no bother.

Might be that the venv has ssl support while the cross host python interpreter does not in my case.

I don't see any deprecation notice about the fallback method.

Yeah, it's not deprecated AFAIU, it just happens to not function correctly when cross compiling if there are any target dependencies needed to execute the fallback method. Cross compiling python is a bit weird as you have both a host and target interpreter with separate site-packages.

RazerM commented 1 year ago

v1.7.0.post0 has been released with the fix