help.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import pkgutil
  2. import sys
  3. import fontTools
  4. import importlib
  5. import os
  6. from pathlib import Path
  7. def main():
  8. """Show this help"""
  9. path = fontTools.__path__
  10. descriptions = {}
  11. for pkg in sorted(
  12. mod.name
  13. for mod in pkgutil.walk_packages([fontTools.__path__[0]], prefix="fontTools.")
  14. ):
  15. try:
  16. imports = __import__(pkg, globals(), locals(), ["main"])
  17. except ImportError as e:
  18. continue
  19. try:
  20. description = imports.main.__doc__
  21. # Cython modules seem to return "main()" as the docstring
  22. if description and description != "main()":
  23. pkg = pkg.replace("fontTools.", "").replace(".__main__", "")
  24. # show the docstring's first line only
  25. descriptions[pkg] = description.splitlines()[0]
  26. except AttributeError as e:
  27. pass
  28. for pkg, description in descriptions.items():
  29. print("fonttools %-25s %s" % (pkg, description), file=sys.stderr)
  30. if __name__ == "__main__":
  31. print("fonttools v%s\n" % fontTools.__version__, file=sys.stderr)
  32. main()