_has_cy.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # util/_has_cy.py
  2. # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: https://www.opensource.org/licenses/mit-license.php
  7. # mypy: ignore-errors
  8. import os
  9. import typing
  10. def _import_cy_extensions():
  11. # all cython extension extension modules are treated as optional by the
  12. # setup, so to ensure that all are compiled, all should be imported here
  13. from ..cyextension import collections
  14. from ..cyextension import immutabledict
  15. from ..cyextension import processors
  16. from ..cyextension import resultproxy
  17. from ..cyextension import util
  18. return (collections, immutabledict, processors, resultproxy, util)
  19. _CYEXTENSION_MSG: str
  20. if not typing.TYPE_CHECKING:
  21. if os.environ.get("DISABLE_SQLALCHEMY_CEXT_RUNTIME"):
  22. HAS_CYEXTENSION = False
  23. _CYEXTENSION_MSG = "DISABLE_SQLALCHEMY_CEXT_RUNTIME is set"
  24. else:
  25. try:
  26. _import_cy_extensions()
  27. except ImportError as err:
  28. HAS_CYEXTENSION = False
  29. _CYEXTENSION_MSG = str(err)
  30. else:
  31. _CYEXTENSION_MSG = "Loaded"
  32. HAS_CYEXTENSION = True
  33. else:
  34. HAS_CYEXTENSION = False