bskinn / sphobjinv

Toolkit for manipulation and inspection of Sphinx objects.inv files
https://sphobjinv.readthedocs.io
MIT License
78 stars 7 forks source link

Implement deferred SSL import #275

Open bskinn opened 1 year ago

bskinn commented 1 year ago

This will be necessary in order for https://github.com/bskinn/soi-app/issues/10 to work, at all. PyScript doesn't ship with a working ssl package, and sphobjinv imports ssl at import time.

sphobjinv doesn't use SSL except for Inventory(url=...) instantiation. Any ImportError that occurs during an attempt to import ssl will need to be deferred until such time that Inventory(url=...) is attempted.

This means that the creation of Inventory._sslcontext will also have to be deferred, since ssl is used to create that context. Thus, #113 will be needed for functional reasons.

bskinn commented 1 year ago

A simple descriptor might be enough. Inside Inventory:

class Inventory(...):

    ...

    _sslcontext_obj = None

    @property
    def _sslcontext(self):
        # This is clunky and not best practice. Could also work with top-level import
        # and and just defer the exception to this use of ssl....have to decide.
        import ssl
        if not self._sslcontext_obj:
            self._sslcontext_obj = ssl. ...

        return self._sslcontext_obj
bskinn commented 3 months ago

Note to self: There is request capability in Pyodide and PyScript, it just is accessed differently. So, we would want to to some import-time testing to see what's available, and then use the first option that works out of a priority-sequenced cascade of options.