Skip to content

Commit

Permalink
Add version info. Use same prerelease convention as Nvim itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Oct 30, 2016
1 parent 111bc07 commit ba1fcd4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
15 changes: 13 additions & 2 deletions neovim/__init__.py
Expand Up @@ -12,14 +12,18 @@
stdio_session, tcp_session)
from .plugin import (Host, autocmd, command, decode, encoding, function,
plugin, rpc_export, shutdown_hook)
from .util import Version


__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
'start_host', 'autocmd', 'command', 'encoding', 'decode',
'function', 'plugin', 'rpc_export', 'Host', 'Nvim',
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'VERSION',
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse')


VERSION = Version(major=0, minor=1, patch=11, prerelease="dev")


def start_host(session=None):
"""Promote the current process into python plugin host for Nvim.
Expand Down Expand Up @@ -64,7 +68,14 @@ def start_host(session=None):

if not session:
session = stdio_session()
host = Host(Nvim.from_session(session))
nvim = Nvim.from_session(session)

if nvim.version.api_level < 1:
sys.stderr.write("This version of the neovim python package "
"requires nvim 0.1.6 or later")
sys.exit(1)

host = Host(nvim)
host.start(plugins)


Expand Down
4 changes: 3 additions & 1 deletion neovim/api/nvim.py
Expand Up @@ -13,7 +13,7 @@
from .tabpage import Tabpage
from .window import Window
from ..compat import IS_PYTHON3
from ..util import format_exc_skip
from ..util import Version, format_exc_skip

__all__ = ('Nvim')

Expand Down Expand Up @@ -74,6 +74,8 @@ def __init__(self, session, channel_id, metadata, types,
self._session = session
self.channel_id = channel_id
self.metadata = metadata
version = metadata.get("version", {"api_level": 0})
self.version = Version(**version)
self.types = types
self.api = RemoteApi(self, 'nvim_')
self.vars = RemoteMap(self, 'nvim_get_var', 'nvim_set_var')
Expand Down
20 changes: 20 additions & 0 deletions neovim/util.py
Expand Up @@ -10,3 +10,23 @@ def format_exc_skip(skip, limit=None):
for i in range(skip):
tb = tb.tb_next
return ('\n'.join(format_exception(type, val, tb, limit))).rstrip()


# Taken from SimpleNamespace in python 3
class Version:

"""Helper class for version info."""

def __init__(self, **kwargs):
"""Create the Version object."""
self.__dict__.update(kwargs)

def __repr__(self):
"""Return str representation of the Version."""
keys = sorted(self.__dict__)
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
return "{}({})".format(type(self).__name__, ", ".join(items))

def __eq__(self, other):
"""Check if version is same as other."""
return self.__dict__ == other.__dict__
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -19,7 +19,7 @@
install_requires.append('greenlet')

setup(name='neovim',
version='0.1.10',
version='0.1.11dev',
description='Python client to neovim',
url='http://github.com/neovim/python-client',
download_url='https://github.com/neovim/python-client/archive/0.1.10.tar.gz',
Expand Down

0 comments on commit ba1fcd4

Please sign in to comment.