Skip to content

Commit d1c9c31

Browse files
committed
On python3.4+, only support asyncio and expose it to rplugins
Dissallow python3.3 python2.7 is unchanged (pyuv is still preferred; loop not exposed)
1 parent 320cb7d commit d1c9c31

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ python:
1616
# If the build matrix gets bigger, also update the number of runs
1717
# at the bottom of .scrutinizer.yml.
1818
- 2.7
19-
- 3.3
2019
- 3.4
2120
- 3.5
2221
- 3.6

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ connecting to and scripting Nvim processes through its msgpack-rpc API.
99

1010
#### Installation
1111

12-
Supports python 2.7, and 3.3 or later.
12+
Supports python 2.7, and 3.4 or later.
1313

1414
```sh
1515
pip2 install neovim

neovim/api/nvim.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class Nvim(object):
3636
`SubClass.from_nvim(nvim)` where `SubClass` is a subclass of `Nvim`, which
3737
is useful for having multiple `Nvim` objects that behave differently
3838
without one affecting the other.
39+
40+
When this library is used on python3.4+, asyncio event loop is guaranteed
41+
to be used. It is available as the "loop" attribute of this closs. Note
42+
that asyncio callbacks cannot make blocking requests, which which includes
43+
accessing state-dependent attributes. They should instead schedule another
44+
callback using nvim.async_call, which will not have this restriction.
3945
"""
4046

4147
@classmethod
@@ -90,6 +96,10 @@ def __init__(self, session, channel_id, metadata, types,
9096
self._decode = decode
9197
self._err_cb = err_cb
9298

99+
# only on python3.4+ we expose asyncio
100+
if IS_PYTHON3:
101+
self.loop = self._session.loop._loop
102+
93103
def _from_nvim(self, obj, decode=None):
94104
if decode is None:
95105
decode = self._decode

neovim/msgpack_rpc/async_session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, msgpack_stream):
2727
1: self._on_response,
2828
2: self._on_notification
2929
}
30+
self.loop = msgpack_stream.loop
3031

3132
def threadsafe_call(self, fn):
3233
"""Wrapper around `MsgpackStream.threadsafe_call`."""

neovim/msgpack_rpc/event_loop/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
33
Tries to use pyuv as a backend, falling back to the asyncio implementation.
44
"""
5-
try:
6-
# libuv is fully implemented in C, use it when available
7-
from .uv import UvEventLoop
8-
EventLoop = UvEventLoop
9-
except ImportError:
10-
# asyncio(trollius on python 2) is pure python and should be more portable
11-
# across python implementations
5+
6+
from ...compat import IS_PYTHON3
7+
8+
# on python3 we only support asyncio, as we want to expose it to plugins
9+
if IS_PYTHON3:
1210
from .asyncio import AsyncioEventLoop
1311
EventLoop = AsyncioEventLoop
12+
else:
13+
try:
14+
# libuv is fully implemented in C, use it when available
15+
from .uv import UvEventLoop
16+
EventLoop = UvEventLoop
17+
except ImportError:
18+
# asyncio(trollius on python 2) is pure python and should be more portable
19+
# across python implementations
20+
from .asyncio import AsyncioEventLoop
21+
EventLoop = AsyncioEventLoop
1422

1523

1624
__all__ = ('EventLoop')

neovim/msgpack_rpc/msgpack_stream.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ class MsgpackStream(object):
1919

2020
def __init__(self, event_loop):
2121
"""Wrap `event_loop` on a msgpack-aware interface."""
22-
self._event_loop = event_loop
22+
self.loop = event_loop
2323
self._packer = Packer(encoding='utf-8',
2424
unicode_errors=unicode_errors_default)
2525
self._unpacker = Unpacker()
2626
self._message_cb = None
2727

2828
def threadsafe_call(self, fn):
2929
"""Wrapper around `BaseEventLoop.threadsafe_call`."""
30-
self._event_loop.threadsafe_call(fn)
30+
self.loop .threadsafe_call(fn)
3131

3232
def send(self, msg):
3333
"""Queue `msg` for sending to Nvim."""
3434
debug('sent %s', msg)
35-
self._event_loop.send(self._packer.pack(msg))
35+
self.loop .send(self._packer.pack(msg))
3636

3737
def run(self, message_cb):
3838
"""Run the event loop to receive messages from Nvim.
@@ -41,12 +41,12 @@ def run(self, message_cb):
4141
a message has been successfully parsed from the input stream.
4242
"""
4343
self._message_cb = message_cb
44-
self._event_loop.run(self._on_data)
44+
self.loop .run(self._on_data)
4545
self._message_cb = None
4646

4747
def stop(self):
4848
"""Stop the event loop."""
49-
self._event_loop.stop()
49+
self.loop .stop()
5050

5151
def _on_data(self, data):
5252
self._unpacker.feed(data)

neovim/msgpack_rpc/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, async_session):
2626
self._pending_messages = deque()
2727
self._is_running = False
2828
self._setup_exception = None
29+
self.loop = async_session.loop
2930

3031
def threadsafe_call(self, fn, *args, **kwargs):
3132
"""Wrapper around `AsyncSession.threadsafe_call`."""

setup.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
install_requires = [
88
'msgpack>=0.5.0',
99
]
10-
extras_require = {
11-
'pyuv': ['pyuv>=1.0.0'],
12-
}
1310

14-
if os.name == 'nt':
15-
install_requires.append('pyuv>=1.0.0')
16-
elif sys.version_info < (3, 4):
17-
# trollius is just a backport of 3.4 asyncio module
18-
install_requires.append('trollius')
11+
if sys.version_info < (3, 4):
12+
if os.name == 'nt':
13+
install_requires.append('pyuv>=1.0.0')
14+
else:
15+
# trollius is just a backport of 3.4 asyncio module
16+
install_requires.append('trollius')
1917

2018
if platform.python_implementation() != 'PyPy':
2119
# pypy already includes an implementation of the greenlet module
@@ -32,5 +30,4 @@
3230
packages=['neovim', 'neovim.api', 'neovim.msgpack_rpc',
3331
'neovim.msgpack_rpc.event_loop', 'neovim.plugin'],
3432
install_requires=install_requires,
35-
extras_require=extras_require,
3633
zip_safe=False)

0 commit comments

Comments
 (0)