freeze_support.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Provides a function to report all internal modules for using freezing tools
  3. pytest
  4. """
  5. from __future__ import absolute_import, division, print_function
  6. def freeze_includes():
  7. """
  8. Returns a list of module names used by pytest that should be
  9. included by cx_freeze.
  10. """
  11. import py
  12. import _pytest
  13. result = list(_iter_all_modules(py))
  14. result += list(_iter_all_modules(_pytest))
  15. return result
  16. def _iter_all_modules(package, prefix=""):
  17. """
  18. Iterates over the names of all modules that can be found in the given
  19. package, recursively.
  20. Example:
  21. _iter_all_modules(_pytest) ->
  22. ['_pytest.assertion.newinterpret',
  23. '_pytest.capture',
  24. '_pytest.core',
  25. ...
  26. ]
  27. """
  28. import os
  29. import pkgutil
  30. if type(package) is not str:
  31. path, prefix = package.__path__[0], package.__name__ + "."
  32. else:
  33. path = package
  34. for _, name, is_package in pkgutil.iter_modules([path]):
  35. if is_package:
  36. for m in _iter_all_modules(os.path.join(path, name), prefix=name + "."):
  37. yield prefix + m
  38. else:
  39. yield prefix + name