Skip to content

Commit 71d2d65

Browse files
authored
packaging: pynvim.__version__ attribute (0.5.0.dev0) #540
pynvim previously did not have the `pynvim.__version__` attribute, which is a popular convention for python modules. We add the `pynvim.__version__` string in addition to `pynvim.VERSION`, and let `pynvim._version` be the only file that contains the version metadata for the pynvim package. `setup.py` can also get the version string from this file. pynvim version is bumped up to a devel version: 0.5.0.dev0 (from 0.4.3).
1 parent abc7547 commit 71d2d65

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ connecting to and scripting Nvim processes through its msgpack-rpc API.
1010
Install
1111
-------
1212

13-
Supports python 3.10 or later.
13+
Supports python 3.7 or later.
1414

1515
pip3 install pynvim
1616

@@ -115,14 +115,15 @@ Release
115115

116116
1. Create a release commit with title `Pynvim x.y.z`
117117
- list significant changes in the commit message
118-
- bump the version in `pynvim/util.py` and `setup.py` (3 places in total)
118+
- bump the version in `pynvim/_version.py`
119119
2. Make a release on GitHub with the same commit/version tag and copy the message.
120120
3. Run `scripts/disable_log_statements.sh`
121121
4. Run `python -m build`
122122
- diff the release tarball `dist/pynvim-x.y.z.tar.gz` against the previous one.
123123
5. Run `twine upload -r pypi dist/*`
124124
- Assumes you have a pypi account with permissions.
125125
6. Run `scripts/enable_log_statements.sh` or `git reset --hard` to restore the working dir.
126+
7. Bump up to the next development version in `pynvim/_version.py`, with `prerelease` suffix `dev0`.
126127

127128
License
128129
-------

pynvim/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from types import SimpleNamespace as Version
99
from typing import List, Optional, cast, overload
1010

11+
from pynvim._version import VERSION, __version__
1112
from pynvim.api import Nvim, NvimError
12-
from pynvim.msgpack_rpc import (ErrorResponse, Session, TTransportType, child_session,
13-
socket_session, stdio_session, tcp_session)
13+
from pynvim.msgpack_rpc import (ErrorResponse, Session, TTransportType,
14+
child_session, socket_session, stdio_session,
15+
tcp_session)
1416
from pynvim.plugin import (Host, autocmd, command, decode, encoding, function,
1517
plugin, rpc_export, shutdown_hook)
16-
from pynvim.util import VERSION
1718

1819
if sys.version_info < (3, 8):
1920
from typing_extensions import Literal
@@ -24,8 +25,9 @@
2425
__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
2526
'start_host', 'autocmd', 'command', 'encoding', 'decode',
2627
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'NvimError',
27-
'Version', 'VERSION', 'shutdown_hook', 'attach', 'setup_logging',
28-
'ErrorResponse')
28+
'Version', 'VERSION', '__version__',
29+
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse',
30+
)
2931

3032

3133
def start_host(session: Optional[Session] = None) -> None:

pynvim/_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Specifies pynvim version."""
2+
# pylint: disable=consider-using-f-string
3+
4+
from types import SimpleNamespace
5+
6+
# see also setup.py
7+
VERSION = SimpleNamespace(major=0, minor=5, patch=0, prerelease="dev0")
8+
9+
# e.g. "0.5.0", "0.5.0.dev0" (PEP-440)
10+
__version__ = '{major}.{minor}.{patch}'.format(**vars(VERSION))
11+
12+
if VERSION.prerelease:
13+
__version__ += '.' + VERSION.prerelease

pynvim/util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import sys
44
from traceback import format_exception
5-
from types import SimpleNamespace
65
from typing import Any, Dict, Optional, Tuple, TypeVar
76

7+
from pynvim._version import VERSION
8+
89

910
def format_exc_skip(skip: int, limit: Optional[int] = None) -> str:
1011
"""Like traceback.format_exc but allow skipping the first frames."""
@@ -26,6 +27,3 @@ def get_client_info(
2627
name = "python{}-{}".format(sys.version_info[0], kind)
2728
attributes = {"license": "Apache v2", "website": "github.com/neovim/pynvim"}
2829
return (name, VERSION.__dict__, type_, method_spec, attributes)
29-
30-
31-
VERSION = SimpleNamespace(major=0, minor=4, patch=3, prerelease="")

setup.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
"""setup.py for pynvim."""
2+
3+
import os.path
14
import platform
25
import sys
36

7+
__PATH__ = os.path.abspath(os.path.dirname(__file__))
8+
49
from setuptools import setup
510

611
install_requires = [
@@ -11,7 +16,7 @@
1116
pytest_runner = ['pytest-runner'] if needs_pytest else []
1217

1318
setup_requires = [
14-
] + pytest_runner,
19+
] + pytest_runner
1520

1621
tests_require = [
1722
'pytest',
@@ -29,13 +34,21 @@
2934
if sys.version_info < (3, 8):
3035
install_requires.append('typing-extensions')
3136

37+
38+
# __version__: see pynvim/_version.py
39+
with open(os.path.join(__PATH__, "pynvim/_version.py"),
40+
"r", encoding="utf-8") as fp:
41+
_version_env = {}
42+
exec(fp.read(), _version_env) # pylint: disable=exec-used
43+
version = _version_env['__version__']
44+
45+
3246
setup(name='pynvim',
33-
version='0.4.3',
47+
version=version,
3448
description='Python client for Neovim',
3549
url='http://github.com/neovim/pynvim',
36-
download_url='https://github.com/neovim/pynvim/archive/0.4.3.tar.gz',
37-
author='Thiago de Arruda',
38-
author_email='[email protected]',
50+
download_url=f'https://github.com/neovim/pynvim/archive/{version}.tar.gz',
51+
author='Neovim Authors',
3952
license='Apache',
4053
packages=['pynvim', 'pynvim.api', 'pynvim.msgpack_rpc',
4154
'pynvim.msgpack_rpc.event_loop', 'pynvim.plugin',

test/test_version.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pynvim
2+
3+
4+
def test_version() -> None:
5+
assert pynvim.__version__
6+
assert isinstance(pynvim.__version__, str)
7+
print(f"pynvim.__version__ = '{pynvim.__version__}'")

0 commit comments

Comments
 (0)