packaging_modules.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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(
  18. name=THE_NAME,
  19. version=THE_VERSION,
  20. description=THE_DESCRIPTION,
  21. author=THE_AUTHOR_NAME,
  22. author_email=THE_AUTHOR_EMAIL,
  23. url=" ... ",
  24. packages=find_packages(),
  25. entry_points="""
  26. [salt.loader]
  27. engines_dirs = <package>.<loader-module>:engines_dirs
  28. fileserver_dirs = <package>.<loader-module>:fileserver_dirs
  29. pillar_dirs = <package>.<loader-module>:pillar_dirs
  30. returner_dirs = <package>.<loader-module>:returner_dirs
  31. roster_dirs = <package>.<loader-module>:roster_dirs
  32. """,
  33. )
  34. The above setup script example mentions a loader module. here's an example of
  35. how `<package>/<loader-module>.py` it should look:
  36. .. code-block:: python
  37. # -*- coding: utf-8 -*-
  38. # Import python libs
  39. import os
  40. PKG_DIR = os.path.abspath(os.path.dirname(__file__))
  41. def engines_dirs():
  42. """
  43. yield one path per parent directory of where engines can be found
  44. """
  45. yield os.path.join(PKG_DIR, "engines_1")
  46. yield os.path.join(PKG_DIR, "engines_2")
  47. def fileserver_dirs():
  48. """
  49. yield one path per parent directory of where fileserver modules can be found
  50. """
  51. yield os.path.join(PKG_DIR, "fileserver")
  52. def pillar_dirs():
  53. """
  54. yield one path per parent directory of where external pillar modules can be found
  55. """
  56. yield os.path.join(PKG_DIR, "pillar")
  57. def returner_dirs():
  58. """
  59. yield one path per parent directory of where returner modules can be found
  60. """
  61. yield os.path.join(PKG_DIR, "returners")
  62. def roster_dirs():
  63. """
  64. yield one path per parent directory of where roster modules can be found
  65. """
  66. yield os.path.join(PKG_DIR, "roster")