Skip to content

Commit ba1fcd4

Browse files
committed
Add version info. Use same prerelease convention as Nvim itself.
1 parent 111bc07 commit ba1fcd4

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

neovim/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
stdio_session, tcp_session)
1313
from .plugin import (Host, autocmd, command, decode, encoding, function,
1414
plugin, rpc_export, shutdown_hook)
15+
from .util import Version
1516

1617

1718
__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
1819
'start_host', 'autocmd', 'command', 'encoding', 'decode',
19-
'function', 'plugin', 'rpc_export', 'Host', 'Nvim',
20+
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'VERSION',
2021
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse')
2122

2223

24+
VERSION = Version(major=0, minor=1, patch=11, prerelease="dev")
25+
26+
2327
def start_host(session=None):
2428
"""Promote the current process into python plugin host for Nvim.
2529
@@ -64,7 +68,14 @@ def start_host(session=None):
6468

6569
if not session:
6670
session = stdio_session()
67-
host = Host(Nvim.from_session(session))
71+
nvim = Nvim.from_session(session)
72+
73+
if nvim.version.api_level < 1:
74+
sys.stderr.write("This version of the neovim python package "
75+
"requires nvim 0.1.6 or later")
76+
sys.exit(1)
77+
78+
host = Host(nvim)
6879
host.start(plugins)
6980

7081

neovim/api/nvim.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .tabpage import Tabpage
1414
from .window import Window
1515
from ..compat import IS_PYTHON3
16-
from ..util import format_exc_skip
16+
from ..util import Version, format_exc_skip
1717

1818
__all__ = ('Nvim')
1919

@@ -74,6 +74,8 @@ def __init__(self, session, channel_id, metadata, types,
7474
self._session = session
7575
self.channel_id = channel_id
7676
self.metadata = metadata
77+
version = metadata.get("version", {"api_level": 0})
78+
self.version = Version(**version)
7779
self.types = types
7880
self.api = RemoteApi(self, 'nvim_')
7981
self.vars = RemoteMap(self, 'nvim_get_var', 'nvim_set_var')

neovim/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,23 @@ def format_exc_skip(skip, limit=None):
1010
for i in range(skip):
1111
tb = tb.tb_next
1212
return ('\n'.join(format_exception(type, val, tb, limit))).rstrip()
13+
14+
15+
# Taken from SimpleNamespace in python 3
16+
class Version:
17+
18+
"""Helper class for version info."""
19+
20+
def __init__(self, **kwargs):
21+
"""Create the Version object."""
22+
self.__dict__.update(kwargs)
23+
24+
def __repr__(self):
25+
"""Return str representation of the Version."""
26+
keys = sorted(self.__dict__)
27+
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
28+
return "{}({})".format(type(self).__name__, ", ".join(items))
29+
30+
def __eq__(self, other):
31+
"""Check if version is same as other."""
32+
return self.__dict__ == other.__dict__

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
install_requires.append('greenlet')
2020

2121
setup(name='neovim',
22-
version='0.1.10',
22+
version='0.1.11dev',
2323
description='Python client to neovim',
2424
url='http://github.com/neovim/python-client',
2525
download_url='https://github.com/neovim/python-client/archive/0.1.10.tar.gz',

0 commit comments

Comments
 (0)