hook-pylint.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2020 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. #
  13. # *************************************************
  14. # hook-pylint.py - PyInstaller hook file for pylint
  15. # *************************************************
  16. # The pylint package, in __pkginfo__.py, is version 1.4.3. Looking at its
  17. # source:
  18. #
  19. # From checkers/__init__.py, starting at line 122::
  20. #
  21. # def initialize(linter):
  22. # """initialize linter with checkers in this package """
  23. # register_plugins(linter, __path__[0])
  24. #
  25. # From reporters/__init__.py, starting at line 131::
  26. #
  27. # def initialize(linter):
  28. # """initialize linter with reporters in this package """
  29. # utils.register_plugins(linter, __path__[0])
  30. #
  31. # From utils.py, starting at line 881::
  32. #
  33. # def register_plugins(linter, directory):
  34. # """load all module and package in the given directory, looking for a
  35. # 'register' function in each one, used to register pylint checkers
  36. # """
  37. # imported = {}
  38. # for filename in os.listdir(directory):
  39. # base, extension = splitext(filename)
  40. # if base in imported or base == '__pycache__':
  41. # continue
  42. # if extension in PY_EXTS and base != '__init__' or (
  43. # not extension and isdir(join(directory, base))):
  44. # try:
  45. # module = load_module_from_file(join(directory, filename))
  46. #
  47. #
  48. # So, we need all the Python source in the ``checkers/`` and ``reporters/``
  49. # subdirectories, since these are run-time discovered and loaded. Therefore,
  50. # these files are all data files. In addition, since this is a module, the
  51. # pylint/__init__.py file must be included, since submodules must be children of
  52. # a module.
  53. from PyInstaller.utils.hooks import (
  54. collect_data_files, collect_submodules, is_module_or_submodule, get_module_file_attribute
  55. )
  56. datas = (
  57. [(get_module_file_attribute('pylint.__init__'), 'pylint')] +
  58. collect_data_files('pylint.checkers', True) +
  59. collect_data_files('pylint.reporters', True)
  60. )
  61. # Add imports from dynamically loaded modules, excluding pylint.test
  62. # subpackage (pylint <= 2.3) and pylint.testutils submodule (pylint < 2.7)
  63. # or subpackage (pylint >= 2.7)
  64. def _filter_func(name):
  65. return (
  66. not is_module_or_submodule(name, 'pylint.test') and
  67. not is_module_or_submodule(name, 'pylint.testutils')
  68. )
  69. hiddenimports = collect_submodules('pylint', _filter_func)