__main__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import sys
  2. from os.path import join, dirname, abspath, isdir
  3. def _start_linter():
  4. """
  5. This is a pre-alpha API. You're not supposed to use it at all, except for
  6. testing. It will very likely change.
  7. """
  8. import jedi
  9. if '--debug' in sys.argv:
  10. jedi.set_debug_function()
  11. for path in sys.argv[2:]:
  12. if path.startswith('--'):
  13. continue
  14. if isdir(path):
  15. import fnmatch
  16. import os
  17. paths = []
  18. for root, dirnames, filenames in os.walk(path):
  19. for filename in fnmatch.filter(filenames, '*.py'):
  20. paths.append(os.path.join(root, filename))
  21. else:
  22. paths = [path]
  23. try:
  24. for p in paths:
  25. for error in jedi.Script(path=p)._analysis():
  26. print(error)
  27. except Exception:
  28. if '--pdb' in sys.argv:
  29. import traceback
  30. traceback.print_exc()
  31. import pdb
  32. pdb.post_mortem()
  33. else:
  34. raise
  35. def _complete():
  36. import jedi
  37. import pdb
  38. if '-d' in sys.argv:
  39. sys.argv.remove('-d')
  40. jedi.set_debug_function()
  41. try:
  42. completions = jedi.Script(sys.argv[2]).complete()
  43. for c in completions:
  44. c.docstring()
  45. c.type
  46. except Exception as e:
  47. print(repr(e))
  48. pdb.post_mortem()
  49. else:
  50. print(completions)
  51. if len(sys.argv) == 2 and sys.argv[1] == 'repl':
  52. # don't want to use __main__ only for repl yet, maybe we want to use it for
  53. # something else. So just use the keyword ``repl`` for now.
  54. print(join(dirname(abspath(__file__)), 'api', 'replstartup.py'))
  55. elif len(sys.argv) > 1 and sys.argv[1] == '_linter':
  56. _start_linter()
  57. elif len(sys.argv) > 1 and sys.argv[1] == '_complete':
  58. _complete()
  59. else:
  60. print('Command not implemented: %s' % sys.argv[1])