__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) 2017 Linaro Limited.
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. import importlib
  5. import logging
  6. from runners.core import ZephyrBinaryRunner, MissingProgram
  7. _logger = logging.getLogger('runners')
  8. def _import_runner_module(runner_name):
  9. try:
  10. importlib.import_module(f'runners.{runner_name}')
  11. except ImportError as ie:
  12. # Runners are supposed to gracefully handle failures when they
  13. # import anything outside of stdlib, but they sometimes do
  14. # not. Catch ImportError to handle this.
  15. _logger.warning(f'The module for runner "{runner_name}" '
  16. f'could not be imported ({ie}). This most likely '
  17. 'means it is not handling its dependencies properly. '
  18. 'Please report this to the zephyr developers.')
  19. # We import these here to ensure the ZephyrBinaryRunner subclasses are
  20. # defined; otherwise, ZephyrBinaryRunner.get_runners() won't work.
  21. _names = [
  22. 'blackmagicprobe',
  23. 'bossac',
  24. 'canopen_program',
  25. 'dediprog',
  26. 'dfu',
  27. 'esp32',
  28. 'hifive1',
  29. 'intel_s1000',
  30. 'jlink',
  31. 'mdb',
  32. 'misc',
  33. 'nios2',
  34. 'nrfjprog',
  35. 'nsim',
  36. 'openocd',
  37. 'pyocd',
  38. 'qemu',
  39. 'stm32cubeprogrammer',
  40. 'stm32flash',
  41. 'xtensa',
  42. # Keep this list sorted by runner name; don't add to the end.
  43. ]
  44. for _name in _names:
  45. _import_runner_module(_name)
  46. def get_runner_cls(runner):
  47. '''Get a runner's class object, given its name.'''
  48. for cls in ZephyrBinaryRunner.get_runners():
  49. if cls.name() == runner:
  50. return cls
  51. raise ValueError('unknown runner "{}"'.format(runner))
  52. __all__ = ['ZephyrBinaryRunner', 'get_runner_cls']