find_modules.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """
  2. modulegraph.find_modules - High-level module dependency finding interface
  3. =========================================================================
  4. History
  5. ........
  6. Originally (loosely) based on code in py2exe's build_exe.py by Thomas Heller.
  7. """
  8. import os
  9. import pkgutil
  10. from .modulegraph import Alias
  11. def get_implies():
  12. def _xml_etree_modules():
  13. import xml.etree
  14. return [
  15. f"xml.etree.{module_name}"
  16. for _, module_name, is_package in pkgutil.iter_modules(xml.etree.__path__)
  17. if not is_package
  18. ]
  19. result = {
  20. # imports done from C code in built-in and/or extension modules
  21. # (untrackable by modulegraph).
  22. "_curses": ["curses"],
  23. "posix": ["resource"],
  24. "gc": ["time"],
  25. "time": ["_strptime"],
  26. "datetime": ["time"],
  27. "parser": ["copyreg"],
  28. "codecs": ["encodings"],
  29. "_sre": ["copy", "re"],
  30. "zipimport": ["zlib"],
  31. # _frozen_importlib is part of the interpreter itself
  32. "_frozen_importlib": None,
  33. # os.path is an alias for a platform specific module,
  34. # ensure that the graph shows this.
  35. "os.path": Alias(os.path.__name__),
  36. # Python >= 3.2:
  37. "_datetime": ["time", "_strptime"],
  38. "_json": ["json.decoder"],
  39. "_pickle": ["codecs", "copyreg", "_compat_pickle"],
  40. "_posixsubprocess": ["gc"],
  41. "_ssl": ["socket"],
  42. # Python >= 3.3:
  43. "_elementtree": ["pyexpat"] + _xml_etree_modules(),
  44. # This is not C extension, but it uses __import__
  45. "anydbm": ["dbhash", "gdbm", "dbm", "dumbdbm", "whichdb"],
  46. # Known package aliases
  47. "wxPython.wx": Alias('wx'),
  48. }
  49. return result