__init__.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (c) Microsoft Corporation.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # DeepSpeed Team
  4. import sys
  5. import os
  6. def _build_file_index(directory, suffix='.tr'):
  7. """Build an index of source files and their basenames in a given directory.
  8. Args:
  9. directory (string): the directory to index
  10. suffix (string): index files with this suffix
  11. Returns:
  12. list: A list of tuples of the form [(basename, absolute path), ...]
  13. """
  14. index = []
  15. for fname in os.listdir(directory):
  16. if fname.endswith(suffix):
  17. basename = fname[:fname.rfind(suffix)] # strip the suffix
  18. path = os.path.join(directory, fname)
  19. index.append((basename, path))
  20. return index
  21. # Go over all local source files and parse them as strings
  22. _module = sys.modules[_build_file_index.__module__]
  23. _directory = os.path.dirname(os.path.realpath(__file__))
  24. for name, fname in _build_file_index(_directory):
  25. with open(fname, 'r') as fin:
  26. setattr(_module, name, fin.read())