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