diff --git a/.gitignore b/.gitignore index c878736e..3c4093d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# autogenerated version file +/pylsp/_version.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/pylsp/__init__.py b/pylsp/__init__.py index 923ad919..151dddc0 100644 --- a/pylsp/__init__.py +++ b/pylsp/__init__.py @@ -3,12 +3,29 @@ import os import pluggy +from . import _version from ._version import __version__ + +def convert_version_info(version: str) -> (int, ..., str): + version_info = version.split(".") + for i, v in enumerate(version_info): + try: + version_info[i] = int(v) + except ValueError: + version_info[i] = v.split("+")[0] + version_info = version_info[: i + 1] + break + + return tuple(version_info) + + +_version.VERSION_INFO = convert_version_info(__version__) + PYLSP = 'pylsp' IS_WIN = os.name == 'nt' hookspec = pluggy.HookspecMarker(PYLSP) hookimpl = pluggy.HookimplMarker(PYLSP) -__all__ = [__version__] +__all__ = ("__version__",) diff --git a/pylsp/_version.py b/pylsp/_version.py deleted file mode 100644 index 1075f467..00000000 --- a/pylsp/_version.py +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -"""PyLSP versioning information.""" - -VERSION_INFO = (1, 4, 0, 'dev0') -__version__ = '.'.join(map(str, VERSION_INFO)) diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 3707222f..9617e372 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -81,7 +81,7 @@ def run_flake8(flake8_executable, args, document): try: cmd = [flake8_executable] cmd.extend(args) - p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) + p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with except IOError: log.debug("Can't execute %s. Trying with '%s -m flake8'", flake8_executable, sys.executable) cmd = [sys.executable, '-m', 'flake8'] diff --git a/pylsp/plugins/pylint_lint.py b/pylsp/plugins/pylint_lint.py index d974a2f8..cbbf01da 100644 --- a/pylsp/plugins/pylint_lint.py +++ b/pylsp/plugins/pylint_lint.py @@ -246,7 +246,7 @@ def _run_pylint_stdio(pylint_executable, document, flags): cmd = [pylint_executable] cmd.extend(flags) cmd.extend(['--from-stdin', document.path]) - p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) + p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with except IOError: log.debug("Can't execute %s. Trying with 'python -m pylint'", pylint_executable) cmd = ['python', '-m', 'pylint'] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..cbad00d4 --- /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/_version.py" +write_to_template = "__version__ = \"{version}\"\n" # VERSION_INFO is populated in __main__ diff --git a/setup.cfg b/setup.cfg index 5a1f6077..93379eed 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,89 @@ +[metadata] +name = python-lsp-server +author = Python Language Server Contributors +description = Python Language Server for the Language Server Protocol +url = https://github.com/python-lsp/python-lsp-server +long_description = file: README.md +long_description_content_type = text/markdown + +[options] +packages = find: +python_requires = >=3.7 +install_requires = + jedi>=0.17.2,<0.19.0 + python-lsp-jsonrpc>=1.0.0 + pluggy + ujson>=3.0.0 + setuptools>=39.0.0 +setup_requires = setuptools>=44; wheel; setuptools_scm[toml]>=3.4.3 + +[options.packages.find] +exclude = contrib; docs; test; test.*; test.plugins; test.plugins.* + +[options.extras_require] +all = + autopep8>=1.6.0,<1.7.0 + flake8>=4.0.0,<4.1.0 + mccabe>=0.6.0,<0.7.0 + pycodestyle>=2.8.0,<2.9.0 + pydocstyle>=2.0.0 + pyflakes>=2.4.0,<2.5.0 + pylint>=2.5.0 + rope>=0.10.5 + yapf +autopep8 = autopep8>=1.6.0,<1.7.0 +flake8 = flake8>=4.0.0,<4.1.0 +mccabe = mccabe>=0.6.0,<0.7.0 +pycodestyle = pycodestyle>=2.8.0,<2.9.0 +pydocstyle = pydocstyle>=2.0.0 +pyflakes = pyflakes>=2.4.0,<2.5.0 +pylint = pylint>=2.5.0 +rope = rope>0.10.5 +yapf = yapf +test = + pylint>=2.5.0 + pytest + pytest-cov + coverage + numpy + pandas + matplotlib + pyqt5 + flaky + +[options.entry_points] +console_scripts = pylsp = pylsp.__main__:main +pylsp = + autopep8 = pylsp.plugins.autopep8_format + folding = pylsp.plugins.folding + flake8 = pylsp.plugins.flake8_lint + jedi_completion = pylsp.plugins.jedi_completion + jedi_definition = pylsp.plugins.definition + jedi_hover = pylsp.plugins.hover + jedi_highlight = pylsp.plugins.highlight + jedi_references = pylsp.plugins.references + jedi_rename = pylsp.plugins.jedi_rename + jedi_signature_help = pylsp.plugins.signature + jedi_symbols = pylsp.plugins.symbols + mccabe = pylsp.plugins.mccabe_lint + preload = pylsp.plugins.preload_imports + pycodestyle = pylsp.plugins.pycodestyle_lint + pydocstyle = pylsp.plugins.pydocstyle_lint + pyflakes = pylsp.plugins.pyflakes_lint + pylint = pylsp.plugins.pylint_lint + rope_completion = pylsp.plugins.rope_completion + rope_rename = pylsp.plugins.rope_rename + yapf = pylsp.plugins.yapf_format + [pycodestyle] ignore = E226, E722, W504 max-line-length = 120 exclude = test/plugins/.ropeproject,test/.ropeproject + [tool:pytest] testpaths = test addopts = --cov-report html --cov-report term --junitxml=pytest.xml --cov pylsp --cov test + diff --git a/setup.py b/setup.py index 0c471a6a..28d2d305 100755 --- a/setup.py +++ b/setup.py @@ -1,98 +1,12 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2017-2020 Palantir Technologies, Inc. # Copyright 2021- Python Language Server Contributors. -import ast -import os -from setuptools import find_packages, setup +from setuptools import setup, find_packages -HERE = os.path.abspath(os.path.dirname(__file__)) - - -def get_version(module='pylsp'): - """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() - -install_requires = [ - 'jedi>=0.17.2,<0.19.0', - 'python-lsp-jsonrpc>=1.0.0', - 'pluggy', - 'ujson>=3.0.0', - 'setuptools>=39.0.0' -] - -setup( - name='python-lsp-server', - version=get_version(), - description='Python Language Server for the Language Server Protocol', - long_description=README, - long_description_content_type='text/markdown', - url='https://github.com/python-lsp/python-lsp-server', - author='Python Language Server Contributors', - packages=find_packages(exclude=['contrib', 'docs', 'test', 'test.*']), - install_requires=install_requires, - python_requires='>=3.7', - extras_require={ - 'all': [ - 'autopep8>=1.6.0,<1.7.0', - 'flake8>=4.0.0,<4.1.0', - 'mccabe>=0.6.0,<0.7.0', - 'pycodestyle>=2.8.0,<2.9.0', - 'pydocstyle>=2.0.0', - 'pyflakes>=2.4.0,<2.5.0', - 'pylint>=2.5.0', - 'rope>=0.10.5', - 'yapf', - ], - 'autopep8': ['autopep8>=1.6.0,<1.7.0'], - 'flake8': ['flake8>=4.0.0,<4.1.0'], - 'mccabe': ['mccabe>=0.6.0,<0.7.0'], - 'pycodestyle': ['pycodestyle>=2.8.0,<2.9.0'], - 'pydocstyle': ['pydocstyle>=2.0.0'], - 'pyflakes': ['pyflakes>=2.4.0,<2.5.0'], - 'pylint': ['pylint>=2.5.0'], - 'rope': ['rope>0.10.5'], - 'yapf': ['yapf'], - 'test': ['pylint>=2.5.0', 'pytest', 'pytest-cov', 'coverage', - 'numpy', 'pandas', 'matplotlib', 'pyqt5', 'flaky'], - }, - entry_points={ - 'console_scripts': [ - 'pylsp = pylsp.__main__:main', - ], - 'pylsp': [ - 'autopep8 = pylsp.plugins.autopep8_format', - 'folding = pylsp.plugins.folding', - 'flake8 = pylsp.plugins.flake8_lint', - 'jedi_completion = pylsp.plugins.jedi_completion', - 'jedi_definition = pylsp.plugins.definition', - 'jedi_hover = pylsp.plugins.hover', - 'jedi_highlight = pylsp.plugins.highlight', - 'jedi_references = pylsp.plugins.references', - 'jedi_rename = pylsp.plugins.jedi_rename', - 'jedi_signature_help = pylsp.plugins.signature', - 'jedi_symbols = pylsp.plugins.symbols', - 'mccabe = pylsp.plugins.mccabe_lint', - 'preload = pylsp.plugins.preload_imports', - 'pycodestyle = pylsp.plugins.pycodestyle_lint', - 'pydocstyle = pylsp.plugins.pydocstyle_lint', - 'pyflakes = pylsp.plugins.pyflakes_lint', - 'pylint = pylsp.plugins.pylint_lint', - 'rope_completion = pylsp.plugins.rope_completion', - 'rope_rename = pylsp.plugins.rope_rename', - 'yapf = pylsp.plugins.yapf_format' - ] - }, -) +if __name__ == "__main__": + setup( + name="python-lsp-server", # to allow GitHub dependency tracking work + packages=find_packages(exclude=["contrib", "docs", "test", "test.*"]), # https://github.com/pypa/setuptools/issues/2688 + )