diff --git a/external-deps/python-lsp-server/.gitrepo b/external-deps/python-lsp-server/.gitrepo index 3df24fa3919..84f938cb79d 100644 --- a/external-deps/python-lsp-server/.gitrepo +++ b/external-deps/python-lsp-server/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/python-lsp/python-lsp-server.git branch = develop - commit = 5a383df418d2800b5abc5dd3a43b3061026fda07 - parent = 71e053bf7d815c0176974f9c9d5031b64946a8d9 + commit = 4c0e99b41ed39c514d0173fde72f7ac9d147662b + parent = 1800d90cb7f94df24ca762cc51537dc27b8df5a6 method = merge - cmdver = 0.4.3 + cmdver = 0.4.6 diff --git a/external-deps/python-lsp-server/CHANGELOG.md b/external-deps/python-lsp-server/CHANGELOG.md index 2993da97172..dcc85065903 100644 --- a/external-deps/python-lsp-server/CHANGELOG.md +++ b/external-deps/python-lsp-server/CHANGELOG.md @@ -1,5 +1,49 @@ # History of changes +## Version 1.11.0 (2024/03/29) + +### New features + +* Remove the `rope_rename` plugin. People that were using it need to install + the `pylsp-rope` third-party plugin instead. +* Add support for Pylint 3.1 + +### Issues Closed + +* [Issue 255](https://github.com/python-lsp/python-lsp-server/issues/255) - Confusion about rename support ([PR 515](https://github.com/python-lsp/python-lsp-server/pull/515) by [@doolio](https://github.com/doolio)) + +In this release 1 issue was closed. + +### Pull Requests Merged + +* [PR 543](https://github.com/python-lsp/python-lsp-server/pull/543) - Bump pylint to `>=3.1,<4`, by [@bnavigator](https://github.com/bnavigator) +* [PR 541](https://github.com/python-lsp/python-lsp-server/pull/541) - Add fallback for `ujson` import, by [@Savalek](https://github.com/Savalek) +* [PR 538](https://github.com/python-lsp/python-lsp-server/pull/538) - Remove `.config/flake8` reference in Readme, by [@justin-f-perez](https://github.com/justin-f-perez) +* [PR 536](https://github.com/python-lsp/python-lsp-server/pull/536) - Fix isort plugin name in Readme, by [@Piraty](https://github.com/Piraty) +* [PR 515](https://github.com/python-lsp/python-lsp-server/pull/515) - Remove built-in `rope_rename` plugin, by [@doolio](https://github.com/doolio) ([255](https://github.com/python-lsp/python-lsp-server/issues/255)) +* [PR 470](https://github.com/python-lsp/python-lsp-server/pull/470) - Add contributing guide to setup dev environment, by [@staticf0x](https://github.com/staticf0x) + +In this release 6 pull requests were closed. + +---- + +## Version 1.10.1 (2024/03/12) + +### Issues Closed + +* [Issue 529](https://github.com/python-lsp/python-lsp-server/issues/529) - Autoimports: sqlite3.OperationalError: database is locked ([PR 530](https://github.com/python-lsp/python-lsp-server/pull/530) by [@last-partizan](https://github.com/last-partizan)) + +In this release 1 issue was closed. + +### Pull Requests Merged + +* [PR 530](https://github.com/python-lsp/python-lsp-server/pull/530) - Fix progress reporting with autoimport plugin, by [@last-partizan](https://github.com/last-partizan) ([529](https://github.com/python-lsp/python-lsp-server/issues/529)) +* [PR 528](https://github.com/python-lsp/python-lsp-server/pull/528) - Improve error message about missing `websockets` module, by [@tomplus](https://github.com/tomplus) + +In this release 2 pull requests were closed. + +---- + ## Version 1.10.0 (2024/01/21) ### New features diff --git a/external-deps/python-lsp-server/CONTRIBUTING.md b/external-deps/python-lsp-server/CONTRIBUTING.md new file mode 100644 index 00000000000..5a24957b136 --- /dev/null +++ b/external-deps/python-lsp-server/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Setup the environment + +1. Clone the repo: `git clone git@github.com:python-lsp/python-lsp-server.git` +2. Create the virtual environment: `python -m venv .venv` +3. Activate: `source .venv/bin/activate` +4. Install an editable installation: `pip install -e .` + - This will ensure you'll see your edits immediately without reinstalling the project +5. Configure your editor to point the pylsp executable to the one in `.venv` + +## Trying out if it works + +Go to file `pylsp/python_lsp.py`, function `start_io_lang_server`, +and on the first line of the function, add some logging: + +```py +log.info("It works!") +``` + +Save the file, restart the LSP server and you should see the log line: + +``` +2023-10-12 16:46:38,320 CEST - INFO - pylsp._utils - It works! +``` + +Now the project is setup in a way you can quickly iterate change you want to add. + +# Running tests + +1. Install runtime dependencies: `pip install .[all]` +2. Install test dependencies: `pip install .[test]` +3. Run `pytest`: `pytest -v` + +## Useful pytest options + +- To run a specific test file, use `pytest test/test_utils.py` +- To run a specific test function within a test file, + use `pytest test/test_utils.py::test_debounce` +- To run tests matching a certain expression, use `pytest -k format` +- To increase verbosity of pytest, use `pytest -v` or `pytest -vv` +- To enter a debugger on failed tests, use `pytest --pdb` diff --git a/external-deps/python-lsp-server/README.md b/external-deps/python-lsp-server/README.md index 51ec4f7e7a9..85d64522d4c 100644 --- a/external-deps/python-lsp-server/README.md +++ b/external-deps/python-lsp-server/README.md @@ -82,7 +82,7 @@ apk add py3-lsp-server Installing these plugins will add extra functionality to the language server: - [pylsp-mypy](https://github.com/Richardk2n/pylsp-mypy): [MyPy](http://mypy-lang.org/) type checking for Python >=3.8. -- [pyls-isort](https://github.com/chantera/python-lsp-isort): code formatting using [isort](https://github.com/PyCQA/isort) (automatic import sorting). +- [python-lsp-isort](https://github.com/chantera/python-lsp-isort): code formatting using [isort](https://github.com/PyCQA/isort) (automatic import sorting). - [python-lsp-black](https://github.com/python-lsp/python-lsp-black): code formatting using [Black](https://github.com/psf/black). - [pyls-memestra](https://github.com/QuantStack/pyls-memestra): detecting the use of deprecated APIs. - [pylsp-rope](https://github.com/python-rope/pylsp-rope): Extended refactoring capabilities using [Rope](https://github.com/python-rope/rope). @@ -101,7 +101,7 @@ Like all language servers, configuration can be passed from the client that talk `python-lsp-server` depends on other tools, like flake8 and pycodestyle. These tools can be configured via settings passed from the client (as above), or alternatively from other configuration sources. The following sources are available: - `pycodestyle`: discovered in `~/.config/pycodestyle`, `setup.cfg`, `tox.ini` and `pycodestyle.cfg`. -- `flake8`: discovered in `~/.config/flake8`, `.flake8`, `setup.cfg` and `tox.ini` +- `flake8`: discovered in `.flake8`, `setup.cfg` and `tox.ini` The default configuration sources are `pycodestyle` and `pyflakes`. If you would like to use `flake8`, you will need to: diff --git a/external-deps/python-lsp-server/pylsp/_utils.py b/external-deps/python-lsp-server/pylsp/_utils.py index e1d2b53cb8d..0293ee32f14 100644 --- a/external-deps/python-lsp-server/pylsp/_utils.py +++ b/external-deps/python-lsp-server/pylsp/_utils.py @@ -175,8 +175,8 @@ def escape_plain_text(contents: str) -> str: """ Format plain text to display nicely in environments which do not respect whitespaces. """ - contents = contents.replace("\t", "\u00A0" * 4) - contents = contents.replace(" ", "\u00A0" * 2) + contents = contents.replace("\t", "\u00a0" * 4) + contents = contents.replace(" ", "\u00a0" * 2) return contents diff --git a/external-deps/python-lsp-server/pylsp/plugins/flake8_lint.py b/external-deps/python-lsp-server/pylsp/plugins/flake8_lint.py index eed673f7367..47121018f0c 100644 --- a/external-deps/python-lsp-server/pylsp/plugins/flake8_lint.py +++ b/external-deps/python-lsp-server/pylsp/plugins/flake8_lint.py @@ -2,6 +2,7 @@ # Copyright 2021- Python Language Server Contributors. """Linter pluging for flake8""" + import logging import os.path import re diff --git a/external-deps/python-lsp-server/pylsp/plugins/jedi_rename.py b/external-deps/python-lsp-server/pylsp/plugins/jedi_rename.py index 5606a88132c..b35e321afd5 100644 --- a/external-deps/python-lsp-server/pylsp/plugins/jedi_rename.py +++ b/external-deps/python-lsp-server/pylsp/plugins/jedi_rename.py @@ -20,7 +20,7 @@ def pylsp_rename(config, workspace, document, position, new_name): except NotImplementedError as exc: raise Exception( "No support for renaming in Python 2/3.5 with Jedi. " - "Consider using the rope_rename plugin instead" + "Consider using the pylsp-rope plugin instead" ) from exc log.debug("Finished rename: %s", refactoring.get_diff()) changes = [] diff --git a/external-deps/python-lsp-server/pylsp/plugins/pylint_lint.py b/external-deps/python-lsp-server/pylsp/plugins/pylint_lint.py index 784627b1f0e..beffe6f3bee 100644 --- a/external-deps/python-lsp-server/pylsp/plugins/pylint_lint.py +++ b/external-deps/python-lsp-server/pylsp/plugins/pylint_lint.py @@ -3,6 +3,7 @@ # Copyright 2021- Python Language Server Contributors. """Linter plugin for pylint.""" + import collections import logging import os diff --git a/external-deps/python-lsp-server/pylsp/plugins/rope_autoimport.py b/external-deps/python-lsp-server/pylsp/plugins/rope_autoimport.py index 1a235c3da6b..759f0922ff2 100644 --- a/external-deps/python-lsp-server/pylsp/plugins/rope_autoimport.py +++ b/external-deps/python-lsp-server/pylsp/plugins/rope_autoimport.py @@ -37,7 +37,7 @@ def reload_cache( config: Config, workspace: Workspace, files: Optional[List[Document]] = None, - single_thread: Optional[bool] = False, + single_thread: Optional[bool] = True, ): if self.is_blocked(): return diff --git a/external-deps/python-lsp-server/pylsp/plugins/rope_rename.py b/external-deps/python-lsp-server/pylsp/plugins/rope_rename.py deleted file mode 100644 index 9e386944819..00000000000 --- a/external-deps/python-lsp-server/pylsp/plugins/rope_rename.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -import logging - -from rope.base import libutils -from rope.refactor.rename import Rename - -from pylsp import _utils, hookimpl, uris - -log = logging.getLogger(__name__) - - -@hookimpl -def pylsp_settings(): - # Default rope_rename to disabled - return {"plugins": {"rope_rename": {"enabled": False}}} - - -@hookimpl -def pylsp_rename(config, workspace, document, position, new_name): - rope_config = config.settings(document_path=document.path).get("rope", {}) - rope_project = workspace._rope_project_builder(rope_config) - - rename = Rename( - rope_project, - libutils.path_to_resource(rope_project, document.path), - document.offset_at_position(position), - ) - - log.debug( - "Executing rename of %s to %s", document.word_at_position(position), new_name - ) - changeset = rename.get_changes(new_name, in_hierarchy=True, docs=True) - log.debug("Finished rename: %s", changeset.changes) - changes = [] - for change in changeset.changes: - uri = uris.from_fs_path(change.resource.path) - doc = workspace.get_maybe_document(uri) - changes.append( - { - "textDocument": {"uri": uri, "version": doc.version if doc else None}, - "edits": [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": { - "line": _num_lines(change.resource), - "character": 0, - }, - }, - "newText": change.new_contents, - } - ], - } - ) - return {"documentChanges": changes} - - -def _num_lines(resource): - "Count the number of lines in a `File` resource." - text = resource.read() - - if _utils.get_eol_chars(text): - return len(text.splitlines()) - return 0 diff --git a/external-deps/python-lsp-server/pylsp/python_lsp.py b/external-deps/python-lsp-server/pylsp/python_lsp.py index a3f737ac373..528ffdb4a85 100644 --- a/external-deps/python-lsp-server/pylsp/python_lsp.py +++ b/external-deps/python-lsp-server/pylsp/python_lsp.py @@ -9,7 +9,11 @@ from functools import partial from typing import Any, Dict, List -import ujson as json +try: + import ujson as json +except Exception: + import json + from pylsp_jsonrpc.dispatchers import MethodDispatcher from pylsp_jsonrpc.endpoint import Endpoint from pylsp_jsonrpc.streams import JsonRpcStreamReader, JsonRpcStreamWriter @@ -109,7 +113,7 @@ def start_ws_lang_server(port, check_parent_process, handler_class): import websockets except ImportError as e: raise ImportError( - "websocket modules missing. Please run pip install 'python-lsp-server[websockets]" + "websocket modules missing. Please run: pip install 'python-lsp-server[websockets]'" ) from e with ThreadPoolExecutor(max_workers=10) as tpool: diff --git a/external-deps/python-lsp-server/pylsp/uris.py b/external-deps/python-lsp-server/pylsp/uris.py index 45ad280b00b..cba5b2909d9 100644 --- a/external-deps/python-lsp-server/pylsp/uris.py +++ b/external-deps/python-lsp-server/pylsp/uris.py @@ -5,6 +5,7 @@ https://github.com/Microsoft/vscode-uri/blob/e59cab84f5df6265aed18ae5f43552d3eef13bb9/lib/index.ts """ + import re from urllib import parse diff --git a/external-deps/python-lsp-server/pyproject.toml b/external-deps/python-lsp-server/pyproject.toml index 4665dcbebf9..f68cc2ede00 100644 --- a/external-deps/python-lsp-server/pyproject.toml +++ b/external-deps/python-lsp-server/pyproject.toml @@ -33,7 +33,7 @@ all = [ "pycodestyle>=2.11.0,<2.12.0", "pydocstyle>=6.3.0,<6.4.0", "pyflakes>=3.2.0,<3.3.0", - "pylint>=2.5.0,<3.1", + "pylint>=3.1,<4", "rope>=1.11.0", "yapf>=0.33.0", "whatthepatch>=1.0.2,<2.0.0" @@ -44,12 +44,12 @@ mccabe = ["mccabe>=0.7.0,<0.8.0"] pycodestyle = ["pycodestyle>=2.11.0,<2.12.0"] pydocstyle = ["pydocstyle>=6.3.0,<6.4.0"] pyflakes = ["pyflakes>=3.2.0,<3.3.0"] -pylint = ["pylint>=2.5.0,<3.1"] +pylint = ["pylint>=3.1,<4"] rope = ["rope>=1.11.0"] yapf = ["yapf>=0.33.0", "whatthepatch>=1.0.2,<2.0.0"] websockets = ["websockets>=10.3"] test = [ - "pylint>=2.5.0,<3.1", + "pylint>=3.1,<4", "pytest", "pytest-cov", "coverage", @@ -79,7 +79,6 @@ 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" rope_autoimport = "pylsp.plugins.rope_autoimport" yapf = "pylsp.plugins.yapf_format" diff --git a/external-deps/python-lsp-server/test/conftest.py b/external-deps/python-lsp-server/test/conftest.py index 5c4ab8f1fc0..a9010517994 100644 --- a/external-deps/python-lsp-server/test/conftest.py +++ b/external-deps/python-lsp-server/test/conftest.py @@ -1,7 +1,8 @@ # Copyright 2017-2020 Palantir Technologies, Inc. # Copyright 2021- Python Language Server Contributors. -""" py.test configuration""" +"""pytest configuration""" + import logging from pylsp.__main__ import LOG_FORMAT diff --git a/external-deps/python-lsp-server/test/plugins/test_autoimport.py b/external-deps/python-lsp-server/test/plugins/test_autoimport.py index 0d1e2d73e7b..4ac635ad5f1 100644 --- a/external-deps/python-lsp-server/test/plugins/test_autoimport.py +++ b/external-deps/python-lsp-server/test/plugins/test_autoimport.py @@ -313,7 +313,7 @@ def test_autoimport_code_actions_and_completions_for_notebook_document( ) assert rope_autoimport_settings.get("completions", {}).get("enabled", False) is True assert rope_autoimport_settings.get("memory", False) is True - wait_for_condition(lambda: not cache.thread.is_alive()) + wait_for_condition(lambda: not cache.is_blocked()) # 1. quick_fixes = server.code_actions("cell_1_uri", {}, make_context("os", 0, 0, 2)) diff --git a/external-deps/python-lsp-server/test/plugins/test_rope_rename.py b/external-deps/python-lsp-server/test/plugins/test_rope_rename.py deleted file mode 100644 index c55ead0adeb..00000000000 --- a/external-deps/python-lsp-server/test/plugins/test_rope_rename.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2017-2020 Palantir Technologies, Inc. -# Copyright 2021- Python Language Server Contributors. - -import os - -import pytest - -from pylsp import uris -from pylsp.plugins.rope_rename import pylsp_rename -from pylsp.workspace import Document - -DOC_NAME = "test1.py" -DOC = """class Test1(): - pass - -class Test2(Test1): - pass -""" - -DOC_NAME_SIMPLE = "test2.py" -DOC_SIMPLE = "foo = 12" - - -@pytest.fixture -def tmp_workspace(temp_workspace_factory): - return temp_workspace_factory({DOC_NAME: DOC, DOC_NAME_SIMPLE: DOC_SIMPLE}) - - -def test_rope_rename(tmp_workspace, config): - position = {"line": 0, "character": 6} - DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME)) - doc = Document(DOC_URI, tmp_workspace) - - result = pylsp_rename(config, tmp_workspace, doc, position, "ShouldBeRenamed") - assert len(result.keys()) == 1 - - changes = result.get("documentChanges") - assert len(changes) == 1 - changes = changes[0] - - # Note that this test differs from test_jedi_rename, because rope does not - # seem to modify files that haven't been opened with textDocument/didOpen. - assert changes.get("edits") == [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": {"line": 5, "character": 0}, - }, - "newText": "class ShouldBeRenamed():\n pass\n\nclass Test2(ShouldBeRenamed):\n pass\n", - } - ] - - # Regression test for issue python-lsp/python-lsp-server#413 - # rename foo - position = {"line": 0, "character": 0} - DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME_SIMPLE)) - doc = Document(DOC_URI, tmp_workspace) - - result = pylsp_rename(config, tmp_workspace, doc, position, "bar") - assert len(result.keys()) == 1 - - changes = result.get("documentChanges") - assert len(changes) == 1 - - assert changes[0].get("edits") == [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": {"line": 0, "character": 0}, - }, - "newText": "bar = 12", - } - ]