-
Notifications
You must be signed in to change notification settings - Fork 625
[LIVY-527] added autocompletion api and implementation for ipython #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,22 @@ | |
|
|
||
| TOP_FRAME_REGEX = re.compile(r'\s*File "<stdin>".*in <module>') | ||
|
|
||
| def get_completer(): | ||
| try: | ||
| __IPYTHON__ | ||
| from IPython.core.completer import IPCompleter | ||
| ip = get_ipython() | ||
| ip_completer = IPCompleter(ip,global_namespace=global_dict) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| global_dict['ip_completer'] = ip_completer | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the completer need to be visible to user statements? Otherwise it seems you can just use a regular global variable (like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completer will be different when python interpreter is different. The number of completer global variable will be two,I don't know if that's appropriate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean ( I think it would be better to keep a single variable for the completer, and a boolean that says whether to use the IPython API. But my main question was: do they need to be stored in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,I see what you mean. |
||
| except NameError: | ||
| try: | ||
| from rlcompleter import Completer | ||
| p_completer = Completer(namespace=global_dict) | ||
| global_dict['p_completer'] = p_completer | ||
| except: | ||
| pass | ||
|
|
||
|
|
||
| def execute_reply(status, content): | ||
| return { | ||
| 'msg_type': 'execute_reply', | ||
|
|
@@ -195,6 +211,28 @@ def processBypassJob(self, serialized_job): | |
| def addFile(self, uri_path): | ||
| job_context.sc.addFile(uri_path) | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a lot of blank lines. Surprising the style checker didn't complain. Should be one line between methods. |
||
|
|
||
|
|
||
| def complete(self,code,cursor_pos=None): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| results = [] | ||
| ip_completer =global_dict.get('ip_completer') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| p_completer = global_dict.get("p_completer") | ||
| if ip_completer is not None: | ||
| results = ip_completer.complete(code,cursor_pos=cursor_pos)[1] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| elif p_completer is not None: | ||
| p_completer = global_dict.get("p_completer") | ||
| state = 0 | ||
| result = None | ||
| while state == 0 or result is not None: | ||
| result = p_completer.complete(code,state) | ||
| if result is not None: | ||
| results.append(result) | ||
| state += 1 | ||
| return ",".join(results) | ||
|
|
||
|
|
||
|
|
||
| def addPyFile(self, uri_path): | ||
| job_context.sc.addPyFile(uri_path) | ||
|
|
||
|
|
@@ -555,6 +593,7 @@ def main(): | |
| sys.stderr = UnicodeDecodingStringIO() | ||
|
|
||
| spark_major_version = os.getenv("LIVY_SPARK_MAJOR_VERSION") | ||
| get_completer() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| try: | ||
| listening_port = 0 | ||
| if os.environ.get("LIVY_TEST") != "true": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangqiaoshi Since fake_shell runs within a standard python process and not within an ipython shell, how will IPCompleter be initialized?