`sabctools` does not work with `python-build-standalone`
I initially made an issue over at https://github.com/astral-sh/python-build-standalone/issues/548. See https://github.com/astral-sh/python-build-standalone/issues/548#issuecomment-2692485114 for more information.
The python-build-standalone project produces standalone, highly-redistributable builds of Python. These builds are being used by practically every python workflow manager such as uv, poetry, hatch, pdm, etc.
sabctools, however, does not work with these builds. Quick reproduction:
❯ docker run --rm -it ghcr.io/astral-sh/uv:0.6.3-python3.13-bookworm /bin/sh
# uv venv -p 3.13
Using CPython 3.13.2 interpreter at: /usr/local/bin/python3.13
Creating virtual environment at: .venv
# uv pip install sabctools
Resolved 1 package in 81ms
Prepared 1 package in 59ms
Installed 1 package in 4ms
+ sabctools==8.2.5
# uv run python
Python 3.13.2 (main, Feb 6 2025, 22:37:13) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sabctools
>>> sabctools.__version__
'8.2.5'
>>> exit
# rm -rf .venv
# uv venv -p 3.13 --python-preference only-managed # Force use of PBS instead of system python
Using CPython 3.13.2
Creating virtual environment at: .venv
# uv pip install sabctools
Resolved 1 package in 9ms
Installed 1 package in 13ms
+ sabctools==8.2.5
# uv run python
Python 3.13.2 (main, Feb 12 2025, 14:51:17) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sabctools
AttributeError: module '_ssl' has no attribute '__file__'. Did you mean: '__name__'?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import sabctools
File "/.venv/lib/python3.13/site-packages/sabctools/__init__.py", line 2, in <module>
from sabctools.sabctools import *
SystemError: initialization of sabctools raised unreported exception
>>>
I don't know if we can ever support this.. The whole point of sabctools is to integrate with Python's own function calls and not be stand-alone. We call internal functions of the _ssl compiled binary of Python to achieve the optimizations we need.
Maybe somebody wants to look into this, but given the current distribution methods we have I don't currently see this as something we need to support soon.
We should probably look at allowing the module to initialise when ssl._ssl.file is unavailable, with a PyObject_HasAttrString check or maybe just clear the exception state with PyErr_Clear. I think it's not clear from the documentation but even though PyObject_GetAttrString returns null it is setting an exception.
I don't think there will be anyway to make the hooks into OpenSSL work because we rely on loading the shared openssl library but on a static build I don't think that'll be possible.
Run into the same issue, the python-build-standalone has _ssl as built-in. How about making the ssl-related behavior optional?