hook-sphinx.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. from PyInstaller.utils.hooks import collect_data_files, collect_submodules, eval_statement
  12. # Sphinx consists of several extensions that are lazily loaded. So collect all submodules to ensure we do not miss
  13. # any of them.
  14. hiddenimports = collect_submodules('sphinx')
  15. # For each extension in sphinx.application.builtin_extensions that does not come from the sphinx package, do a
  16. # collect_submodules(). We need to do this explicitly because collect_submodules() does not seem to work with
  17. # namespace packages, which precludes us from simply doing hiddenimports += collect_submodules('sphinxcontrib')
  18. builtin_extensions = list(
  19. eval_statement(
  20. """
  21. from sphinx.application import builtin_extensions
  22. print(builtin_extensions)
  23. """
  24. )
  25. )
  26. for extension in builtin_extensions:
  27. if extension.startswith('sphinx.'):
  28. continue # Already collected
  29. hiddenimports += collect_submodules(extension)
  30. # This is inherited from an earlier version of the hook, and seems to have been required in Sphinx v.1.3.1 era due to
  31. # https://github.com/sphinx-doc/sphinx/blob/b87ce32e7dc09773f9e71305e66e8d6aead53dd1/sphinx/cmdline.py#L173.
  32. # It does not hurt to keep it around, just in case.
  33. hiddenimports += ['locale']
  34. # Collect all data files: *.html and *.conf files in ``sphinx.themes``, translation files in ``sphinx.locale``, etc.
  35. # Also collect all data files for the alabaster theme.
  36. datas = collect_data_files('sphinx') + collect_data_files('alabaster')