Codebase list python-pynvim / 5f1d37b
Import upstream version 0.4.3 Debian Janitor 2 years ago
11 changed file(s) with 63 addition(s) and 112 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 2.1
11 Name: pynvim
2 Version: 0.4.2
2 Version: 0.4.3
33 Summary: Python client to neovim
44 Home-page: http://github.com/neovim/pynvim
55 Author: Thiago de Arruda
66 Author-email: tpadilha84@gmail.com
77 License: Apache
8 Download-URL: https://github.com/neovim/pynvim/archive/0.4.2.tar.gz
8 Download-URL: https://github.com/neovim/pynvim/archive/0.4.3.tar.gz
99 Description: UNKNOWN
1010 Platform: UNKNOWN
1111 Provides-Extra: pyuv
7979 self._handlers.get(msg[0], self._on_invalid_message)(msg)
8080 except Exception:
8181 err_str = format_exc(5)
82 pass # replaces next logging statement
83 #warn(err_str)
82 warn(err_str)
8483 self._msgpack_stream.send([1, 0, err_str, None])
8584
8685 def _on_request(self, msg):
8887 # - msg[1]: id
8988 # - msg[2]: method name
9089 # - msg[3]: arguments
91 pass # replaces next logging statement
92 #debug('received request: %s, %s', msg[2], msg[3])
90 debug('received request: %s, %s', msg[2], msg[3])
9391 self._request_cb(msg[2], msg[3], Response(self._msgpack_stream,
9492 msg[1]))
9593
9896 # - msg[1]: the id
9997 # - msg[2]: error(if any)
10098 # - msg[3]: result(if not errored)
101 pass # replaces next logging statement
102 #debug('received response: %s, %s', msg[2], msg[3])
99 debug('received response: %s, %s', msg[2], msg[3])
103100 self._pending_requests.pop(msg[1])(msg[2], msg[3])
104101
105102 def _on_notification(self, msg):
106103 # notification/event
107104 # - msg[1]: event name
108105 # - msg[2]: arguments
109 pass # replaces next logging statement
110 #debug('received notification: %s, %s', msg[1], msg[2])
106 debug('received notification: %s, %s', msg[1], msg[2])
111107 self._notification_cb(msg[1], msg[2])
112108
113109 def _on_invalid_message(self, msg):
114110 error = 'Received invalid message %s' % msg
115 pass # replaces next logging statement
116 #warn(error)
111 warn(error)
117112 self._msgpack_stream.send([1, 0, error, None])
118113
119114
139134 resp = [1, self._request_id, value, None]
140135 else:
141136 resp = [1, self._request_id, None, value]
142 pass # replaces next logging statement
143 #debug('sending response to request %d: %s', self._request_id, resp)
137 debug('sending response to request %d: %s', self._request_id, resp)
144138 self._msgpack_stream.send(resp)
101101 pipe = sys.stdin
102102 coroutine = self._loop.connect_read_pipe(self._fact, pipe)
103103 self._loop.run_until_complete(coroutine)
104 pass # replaces next logging statement
105 #debug("native stdin connection successful")
104 debug("native stdin connection successful")
106105
107106 # Make sure subprocesses don't clobber stdout,
108107 # send the output to stderr instead.
115114 pipe = os.fdopen(rename_stdout, 'wb')
116115 coroutine = self._loop.connect_write_pipe(self._fact, pipe)
117116 self._loop.run_until_complete(coroutine)
118 pass # replaces next logging statement
119 #debug("native stdout connection successful")
117 debug("native stdout connection successful")
120118
121119 def _connect_child(self, argv):
122120 if os.name != 'nt':
9494
9595 def connect_tcp(self, address, port):
9696 """Connect to tcp/ip `address`:`port`. Delegated to `_connect_tcp`."""
97 pass # replaces next logging statement
98 #info('Connecting to TCP address: %s:%d', address, port)
97 info('Connecting to TCP address: %s:%d', address, port)
9998 self._connect_tcp(address, port)
10099
101100 def connect_socket(self, path):
102101 """Connect to socket at `path`. Delegated to `_connect_socket`."""
103 pass # replaces next logging statement
104 #info('Connecting to %s', path)
102 info('Connecting to %s', path)
105103 self._connect_socket(path)
106104
107105 def connect_stdio(self):
108106 """Connect using stdin/stdout. Delegated to `_connect_stdio`."""
109 pass # replaces next logging statement
110 #info('Preparing stdin/stdout for streaming data')
107 info('Preparing stdin/stdout for streaming data')
111108 self._connect_stdio()
112109
113110 def connect_child(self, argv):
114111 """Connect a new Nvim instance. Delegated to `_connect_child`."""
115 pass # replaces next logging statement
116 #info('Spawning a new nvim instance')
112 info('Spawning a new nvim instance')
117113 self._connect_child(argv)
118114
119115 def send(self, data):
120116 """Queue `data` for sending to Nvim."""
121 pass # replaces next logging statement
122 #debug("Sending '%s'", data)
117 debug("Sending '%s'", data)
123118 self._send(data)
124119
125120 def threadsafe_call(self, fn):
144139 self._on_data = data_cb
145140 if threading.current_thread() == main_thread:
146141 self._setup_signals([signal.SIGINT, signal.SIGTERM])
147 pass # replaces next logging statement
148 #debug('Entering event loop')
142 debug('Entering event loop')
149143 self._run()
150 pass # replaces next logging statement
151 #debug('Exited event loop')
144 debug('Exited event loop')
152145 if threading.current_thread() == main_thread:
153146 self._teardown_signals()
154147 signal.signal(signal.SIGINT, default_int_handler)
157150 def stop(self):
158151 """Stop the event loop."""
159152 self._stop()
160 pass # replaces next logging statement
161 #debug('Stopped event loop')
153 debug('Stopped event loop')
162154
163155 def close(self):
164156 """Stop the event loop."""
165157 self._close()
166 pass # replaces next logging statement
167 #debug('Closed event loop')
158 debug('Closed event loop')
168159
169160 def _on_signal(self, signum):
170161 msg = 'Received {}'.format(self._signames[signum])
171 pass # replaces next logging statement
172 #debug(msg)
162 debug(msg)
173163 if signum == signal.SIGINT and self._transport_type == 'stdio':
174164 # When the transport is stdio, we are probably running as a Nvim
175165 # child process. In that case, we don't want to be killed by
182172 self.stop()
183173
184174 def _on_error(self, error):
185 pass # replaces next logging statement
186 #debug(error)
175 debug(error)
187176 self._error = OSError(error)
188177 self.stop()
189178
2929
3030 def send(self, msg):
3131 """Queue `msg` for sending to Nvim."""
32 pass # replaces next logging statement
33 #debug('sent %s', msg)
32 debug('sent %s', msg)
3433 self.loop.send(self._packer.pack(msg))
3534
3635 def run(self, message_cb):
5554 self._unpacker.feed(data)
5655 while True:
5756 try:
58 pass # replaces next logging statement
59 #debug('waiting for message...')
57 debug('waiting for message...')
6058 msg = next(self._unpacker)
61 pass # replaces next logging statement
62 #debug('received message: %s', msg)
59 debug('received message: %s', msg)
6360 self._message_cb(msg)
6461 except StopIteration:
65 pass # replaces next logging statement
66 #debug('unpacker needs more data...')
62 debug('unpacker needs more data...')
6763 break
3737 try:
3838 fn(*args, **kwargs)
3939 except Exception:
40 pass # replaces next logging statement
41 #warn("error caught while excecuting async callback\n%s\n",
42 #format_exc())
40 warn("error caught while excecuting async callback\n%s\n",
41 format_exc())
4342
4443 def greenlet_wrapper():
4544 gr = greenlet.greenlet(handler)
9897 raise OSError('EOF')
9998 err, rv = v
10099 if err:
101 pass # replaces next logging statement
102 #info("'Received error: %s", err)
100 info("'Received error: %s", err)
103101 raise self.error_wrapper(err)
104102 return rv
105103
128126 gr.switch()
129127
130128 if self._setup_exception:
131 pass # replaces next logging statement
132 #error('Setup error: {}'.format(self._setup_exception))
129 error('Setup error: {}'.format(self._setup_exception))
133130 raise self._setup_exception
134131
135132 # Process all pending requests and notifications
158155 parent = gr.parent
159156
160157 def response_cb(err, rv):
161 pass # replaces next logging statement
162 #debug('response is available for greenlet %s, switching back', gr)
158 debug('response is available for greenlet %s, switching back', gr)
163159 gr.switch(err, rv)
164160
165161 self._async_session.request(method, args, response_cb)
166 pass # replaces next logging statement
167 #debug('yielding from greenlet %s to wait for response', gr)
162 debug('yielding from greenlet %s to wait for response', gr)
168163 return parent.switch()
169164
170165 def _blocking_request(self, method, args):
197192 def handler():
198193 try:
199194 rv = self._request_cb(name, args)
200 pass # replaces next logging statement
201 #debug('greenlet %s finished executing, '
202 #+ 'sending %s as response', gr, rv)
195 debug('greenlet %s finished executing, '
196 + 'sending %s as response', gr, rv)
203197 response.send(rv)
204198 except ErrorResponse as err:
205 pass # replaces next logging statement
206 #warn("error response from request '%s %s': %s", name,
207 #args, format_exc())
199 warn("error response from request '%s %s': %s", name,
200 args, format_exc())
208201 response.send(err.args[0], error=True)
209202 except Exception as err:
210 pass # replaces next logging statement
211 #warn("error caught while processing request '%s %s': %s", name,
212 #args, format_exc())
203 warn("error caught while processing request '%s %s': %s", name,
204 args, format_exc())
213205 response.send(repr(err) + "\n" + format_exc(5), error=True)
214 pass # replaces next logging statement
215 #debug('greenlet %s is now dying...', gr)
206 debug('greenlet %s is now dying...', gr)
216207
217208 # Create a new greenlet to handle the request
218209 gr = greenlet.greenlet(handler)
219 pass # replaces next logging statement
220 #debug('received rpc request, greenlet %s will handle it', gr)
210 debug('received rpc request, greenlet %s will handle it', gr)
221211 gr.switch()
222212
223213 def _on_notification(self, name, args):
224214 def handler():
225215 try:
226216 self._notification_cb(name, args)
227 pass # replaces next logging statement
228 #debug('greenlet %s finished executing', gr)
217 debug('greenlet %s finished executing', gr)
229218 except Exception:
230 pass # replaces next logging statement
231 #warn("error caught while processing notification '%s %s': %s",
232 #name, args, format_exc())
233
234 pass # replaces next logging statement
235 #debug('greenlet %s is now dying...', gr)
219 warn("error caught while processing notification '%s %s': %s",
220 name, args, format_exc())
221
222 debug('greenlet %s is now dying...', gr)
236223
237224 gr = greenlet.greenlet(handler)
238 pass # replaces next logging statement
239 #debug('received rpc notification, greenlet %s will handle it', gr)
225 debug('received rpc notification, greenlet %s will handle it', gr)
240226 gr.switch()
241227
242228
116116 handler = self._request_handlers.get(name, None)
117117 if not handler:
118118 msg = self._missing_handler_error(name, 'request')
119 pass # replaces next logging statement
120 #error(msg)
119 error(msg)
121120 raise ErrorResponse(msg)
122121
123 pass # replaces next logging statement
124 #debug('calling request handler for "%s", args: "%s"', name, args)
122 debug('calling request handler for "%s", args: "%s"', name, args)
125123 rv = handler(*args)
126 pass # replaces next logging statement
127 #debug("request handler for '%s %s' returns: %s", name, args, rv)
124 debug("request handler for '%s %s' returns: %s", name, args, rv)
128125 return rv
129126
130127 def _on_notification(self, name, args):
134131 handler = self._notification_handlers.get(name, None)
135132 if not handler:
136133 msg = self._missing_handler_error(name, 'notification')
137 pass # replaces next logging statement
138 #error(msg)
134 error(msg)
139135 self._on_async_err(msg + "\n")
140136 return
141137
142 pass # replaces next logging statement
143 #debug('calling notification handler for "%s", args: "%s"', name, args)
138 debug('calling notification handler for "%s", args: "%s"', name, args)
144139 handler(*args)
145140
146141 def _missing_handler_error(self, name, kind):
157152 for path in plugins:
158153 err = None
159154 if path in self._loaded:
160 pass # replaces next logging statement
161 #error('{} is already loaded'.format(path))
155 error('{} is already loaded'.format(path))
162156 continue
163157 try:
164158 if path == "script_host.py":
172166 self._discover_classes(module, handlers, path)
173167 self._discover_functions(module, handlers, path, False)
174168 if not handlers:
175 pass # replaces next logging statement
176 #error('{} exports no handlers'.format(path))
169 error('{} exports no handlers'.format(path))
177170 continue
178171 self._loaded[path] = {'handlers': handlers, 'module': module}
179172 except Exception as e:
180173 err = ('Encountered {} loading plugin at {}: {}\n{}'
181174 .format(type(e).__name__, path, e, format_exc(5)))
182 pass # replaces next logging statement
183 #error(err)
175 error(err)
184176 self._load_errors[path] = err
185177
186178 kind = ("script-host" if len(plugins) == 1 and has_script
6565 forwarded to Nvim.
6666 """
6767 self.nvim = nvim
68 pass # replaces next logging statement
69 #info('install import hook/path')
68 info('install import hook/path')
7069 self.hook = path_hook(nvim)
7170 sys.path_hooks.append(self.hook)
7271 nvim.VIM_SPECIAL_PATH = '_vim_path_'
7372 sys.path.append(nvim.VIM_SPECIAL_PATH)
74 pass # replaces next logging statement
75 #info('redirect sys.stdout and sys.stderr')
73 info('redirect sys.stdout and sys.stderr')
7674 self.saved_stdout = sys.stdout
7775 self.saved_stderr = sys.stderr
7876 sys.stdout = RedirectStream(lambda data: nvim.out_write(data))
8179 def teardown(self):
8280 """Restore state modified from the `setup` call."""
8381 nvim = self.nvim
84 pass # replaces next logging statement
85 #info('uninstall import hook/path')
82 info('uninstall import hook/path')
8683 sys.path.remove(nvim.VIM_SPECIAL_PATH)
8784 sys.path_hooks.remove(self.hook)
88 pass # replaces next logging statement
89 #info('restore sys.stdout and sys.stderr')
85 info('restore sys.stdout and sys.stderr')
9086 sys.stdout = self.saved_stdout
9187 sys.stderr = self.saved_stderr
9288
10399 def python_execute_file(self, file_path, range_start, range_stop):
104100 """Handle the `pyfile` ex command."""
105101 self._set_current_range(range_start, range_stop)
106 with open(file_path) as f:
102 with open(file_path, 'rb') as f:
107103 script = compile(f.read(), file_path, 'exec')
108104 try:
109105 exec(script, self.module.__dict__)
3838 return (name, VERSION.__dict__, type_, method_spec, attributes)
3939
4040
41 VERSION = Version(major=0, minor=4, patch=2, prerelease='')
41 VERSION = Version(major=0, minor=4, patch=3, prerelease='')
00 Metadata-Version: 2.1
11 Name: pynvim
2 Version: 0.4.2
2 Version: 0.4.3
33 Summary: Python client to neovim
44 Home-page: http://github.com/neovim/pynvim
55 Author: Thiago de Arruda
66 Author-email: tpadilha84@gmail.com
77 License: Apache
8 Download-URL: https://github.com/neovim/pynvim/archive/0.4.2.tar.gz
8 Download-URL: https://github.com/neovim/pynvim/archive/0.4.3.tar.gz
99 Description: UNKNOWN
1010 Platform: UNKNOWN
1111 Provides-Extra: pyuv
3434 install_requires.append('greenlet')
3535
3636 setup(name='pynvim',
37 version='0.4.2',
37 version='0.4.3',
3838 description='Python client to neovim',
3939 url='http://github.com/neovim/pynvim',
40 download_url='https://github.com/neovim/pynvim/archive/0.4.2.tar.gz',
40 download_url='https://github.com/neovim/pynvim/archive/0.4.3.tar.gz',
4141 author='Thiago de Arruda',
4242 author_email='tpadilha84@gmail.com',
4343 license='Apache',