driver.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. .. _mach_driver:
  2. =======
  3. Drivers
  4. =======
  5. Entry Points
  6. ============
  7. It is possible to use setuptools' entry points to load commands
  8. directly from python packages. A mach entry point is a function which
  9. returns a list of files or directories containing mach command
  10. providers. e.g.:
  11. .. code-block:: python
  12. def list_providers():
  13. providers = []
  14. here = os.path.abspath(os.path.dirname(__file__))
  15. for p in os.listdir(here):
  16. if p.endswith('.py'):
  17. providers.append(os.path.join(here, p))
  18. return providers
  19. See http://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins
  20. for more information on creating an entry point. To search for entry
  21. point plugins, you can call
  22. :py:meth:`mach.main.Mach.load_commands_from_entry_point`. e.g.:
  23. .. code-block:: python
  24. mach.load_commands_from_entry_point("mach.external.providers")
  25. Adding Global Arguments
  26. =======================
  27. Arguments to mach commands are usually command-specific. However,
  28. mach ships with a handful of global arguments that apply to all
  29. commands.
  30. It is possible to extend the list of global arguments. In your
  31. *mach driver*, simply call
  32. :py:meth:`mach.main.Mach.add_global_argument`. e.g.:
  33. .. code-block:: python
  34. mach = mach.main.Mach(os.getcwd())
  35. # Will allow --example to be specified on every mach command.
  36. mach.add_global_argument('--example', action='store_true',
  37. help='Demonstrate an example global argument.')