packaging_modules.rst 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .. _tutorial-packaging-modules:
  2. ===================================
  3. Packaging External Modules for Salt
  4. ===================================
  5. External Modules Setuptools Entry-Points Support
  6. ================================================
  7. The salt loader was enhanced to look for external modules by looking at the
  8. `salt.loader` entry-point:
  9. https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
  10. `pkg_resources` should be installed, which is normally included in setuptools.
  11. https://setuptools.readthedocs.io/en/latest/pkg_resources.html
  12. The package which has custom engines, minion modules, outputters, etc, should
  13. require setuptools and should define the following entry points in its setup
  14. function:
  15. .. code-block:: python
  16. from setuptools import setup, find_packages
  17. setup(name=<NAME>,
  18. version=<VERSION>,
  19. description=<DESC>,
  20. author=<AUTHOR>,
  21. author_email=<AUTHOR-EMAIL>,
  22. url=' ... ',
  23. packages=find_packages(),
  24. entry_points='''
  25. [salt.loader]
  26. engines_dirs = <package>.<loader-module>:engines_dirs
  27. fileserver_dirs = <package>.<loader-module>:fileserver_dirs
  28. pillar_dirs = <package>.<loader-module>:pillar_dirs
  29. returner_dirs = <package>.<loader-module>:returner_dirs
  30. roster_dirs = <package>.<loader-module>:roster_dirs
  31. ''')
  32. The above setup script example mentions a loader module. here's an example of
  33. how `<package>/<loader-module>.py` it should look:
  34. .. code-block:: python
  35. # -*- coding: utf-8 -*-
  36. # Import python libs
  37. import os
  38. PKG_DIR = os.path.abspath(os.path.dirname(__file__))
  39. def engines_dirs():
  40. '''
  41. yield one path per parent directory of where engines can be found
  42. '''
  43. yield os.path.join(PKG_DIR, 'engines_1')
  44. yield os.path.join(PKG_DIR, 'engines_2')
  45. def fileserver_dirs():
  46. '''
  47. yield one path per parent directory of where fileserver modules can be found
  48. '''
  49. yield os.path.join(PKG_DIR, 'fileserver')
  50. def pillar_dirs():
  51. '''
  52. yield one path per parent directory of where external pillar modules can be found
  53. '''
  54. yield os.path.join(PKG_DIR, 'pillar')
  55. def returner_dirs():
  56. '''
  57. yield one path per parent directory of where returner modules can be found
  58. '''
  59. yield os.path.join(PKG_DIR, 'returners')
  60. def roster_dirs():
  61. '''
  62. yield one path per parent directory of where roster modules can be found
  63. '''
  64. yield os.path.join(PKG_DIR, 'roster')