freeze_support.py 1.2 KB

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