From ae2ac4489158a91f24083056230286bf81ec41d6 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Wed, 8 Sep 2021 12:28:41 +0300 Subject: [PATCH] Moved the metadata into `setup.cfg` Added `pyproject.toml` Replaced fetching version from a file with fetching a version from version control system tags. Also fixed a bug with incorrect content of `__all__` in `__main__.py` --- .gitignore | 3 +++ pylsp_jsonrpc/__init__.py | 19 +++++++++++++++- pylsp_jsonrpc/_version.py | 5 ----- pyproject.toml | 7 ++++++ setup.cfg | 29 ++++++++++++++++++++++++ setup.py | 47 --------------------------------------- 6 files changed, 57 insertions(+), 53 deletions(-) delete mode 100644 pylsp_jsonrpc/_version.py create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/.gitignore b/.gitignore index 3fc908a..95df41c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# autogenerated version file +/pylsp_jsonrpc/_version.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/pylsp_jsonrpc/__init__.py b/pylsp_jsonrpc/__init__.py index 8f327dd..03314c6 100644 --- a/pylsp_jsonrpc/__init__.py +++ b/pylsp_jsonrpc/__init__.py @@ -1,6 +1,23 @@ # Copyright 2017-2020 Palantir Technologies, Inc. # Copyright 2021- Python Language Server Contributors. +from . import _version from ._version import __version__ -__all__ = [__version__] + +def convert_version_info(version: str) -> (int, ..., str): + version_info = version.split(".") + for i in range(len(version_info)): # pylint:disable=consider-using-enumerate + try: + version_info[i] = int(version_info[i]) + except ValueError: + version_info[i] = version_info[i].split("+")[0] + version_info = version_info[: i + 1] + break + + return tuple(version_info) + + +_version.VERSION_INFO = convert_version_info(__version__) + +__all__ = ("__version__",) diff --git a/pylsp_jsonrpc/_version.py b/pylsp_jsonrpc/_version.py deleted file mode 100644 index 48e51ac..0000000 --- a/pylsp_jsonrpc/_version.py +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -VERSION_INFO = (1, 1, 0, 'dev0') -__version__ = '.'.join(map(str, VERSION_INFO)) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..28b0e6a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "pylsp_jsonrpc/_version.py" +write_to_template = "__version__ = \"{version}\"\n" # VERSION_INFO is populated in __main__ diff --git a/setup.cfg b/setup.cfg index 3c9d096..e6850a0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,32 @@ +[metadata] +name = python-lsp-jsonrpc +author = Python Language Server Contributors +description = JSON RPC 2.0 server library +url = https://github.com/python-lsp/python-lsp-jsonrpc +long_description = file: README.md +long_description_content_type = text/markdown + + +[options] +packages = find: +setup_requires = setuptools>=44; wheel; setuptools_scm[toml]>=3.4.3 +install_requires = ujson>=3.0.0 + +[options.packages.find] +exclude = + contrib + docs + test + test.* + +[options.extras_require] +test = + pylint + pycodestyle + pyflakes + pytest + pytest-cov + coverage [pycodestyle] ignore = E226, E722, W504 diff --git a/setup.py b/setup.py deleted file mode 100755 index 25cdf2b..0000000 --- a/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -import ast -import os -from setuptools import find_packages, setup - -HERE = os.path.abspath(os.path.dirname(__file__)) - - -def get_version(module='pylsp_jsonrpc'): - """Get version.""" - with open(os.path.join(HERE, module, '_version.py'), 'r') as f: - data = f.read() - lines = data.split('\n') - for line in lines: - if line.startswith('VERSION_INFO'): - version_tuple = ast.literal_eval(line.split('=')[-1].strip()) - version = '.'.join(map(str, version_tuple)) - break - return version - - -README = open('README.md', 'r').read() - - -setup( - name='python-lsp-jsonrpc', - version=get_version(), - description='JSON RPC 2.0 server library', - license="MIT", - license_file="LICENSE", - long_description=README, - long_description_content_type='text/markdown', - url='https://github.com/python-lsp/python-lsp-jsonrpc', - author='Python Language Server Contributors', - packages=find_packages(exclude=['contrib', 'docs', 'test']), - install_requires=[ - 'ujson>=3.0.0', - ], - extras_require={ - 'test': ['pylint', 'pycodestyle', 'pyflakes', 'pytest', - 'pytest-cov', 'coverage'], - }, -)