If you use autodoc-typehints as an sphinx extension (as described in https://pypi.org/project/sphinx-autodoc-typehints/) you get an error like this (taken from py-khard) Extension error: Could not import extension sphinx_autodoc_typehints (exception: cannot import name '__version__' from 'sphinx_autodoc_typehints.version' (/usr/local/lib/python3.9/site-packages/sphinx_autodoc_typehints/version.py)) It boils down to the following line in (/usr/local/lib/python3.9/site-packages/sphinx_autodoc_typehints/__init__.py:26 from .version import __version__ where __version__ is not existing in version.py Currently it is unclear for me if it has something to do with the switch to pep 517 (see https://github.com/tox-dev/sphinx-autodoc-typehints/blame/main/src/sphinx_autodoc_typehints/__init__.py why I think that).
I further debugged the problem: The default build command (for pep517 based builds) is python3 -m build -n -w which builds in *non isolation*. Doing this, I get a version.py (for this port) looking like # coding: utf-8 # file generated by setuptools_scm # don't change, don't track in version control version = '1.22' version_tuple = (1, 22) which leads to the error above. If I build this python project in an isolated environment (I assume that fetches all python deps explicitly in venv) with python3 -m build -w I get a file like # file generated by setuptools_scm # don't change, don't track in version control __version__ = version = '1.22' __version_tuple__ = version_tuple = (1, 22) which is what sphinx-autodoc-typehints expects. So building in isolation screws up the port system, doing it without isolation results in a broken version.py. I don't know what are the exact differences in deps between isolation/no isolation. I assume some version differences in a dep (like setuptools_scm?). I currently see no way of fixing that problem. I tried to post-patch the generated version.py but the pep517 build commands generates version.py and bundle it in a wheel in one step.
Related issue: https://github.com/tox-dev/sphinx-autodoc-typehints/issues/327
Created attachment 240566 [details] Fix build issue when building in not isolated mode (In reply to Jon Bringhurst from comment #2) Since upsteam does not see any problem with the current behaviour we can only patch this issue on our side. Thank you Jon for propose a fix. I attached the patch for our port. I also removed some redundant build dependencies.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=c1f83d71134e6cf4a5142c3cb917f25c265bbad3 commit c1f83d71134e6cf4a5142c3cb917f25c265bbad3 Author: Andreas Bilke <andreas@bilke.org> AuthorDate: 2023-03-09 00:07:21 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2023-03-11 08:38:57 +0000 textproc/py-sphinx-autodoc-typehints: fix building in non isolated mode Since upsteam does not see any problem with the current behaviour we can only patch this issue on our side. Also remove some redundant build dependencies. PR: 269686 textproc/py-sphinx-autodoc-typehints/Makefile | 5 +---- ...rc_sphinx__autodoc__typehints_____init____.py (new) | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-)
Thank you for your contribution.