From f50f1fe7e3ed9d99491c18f247c8fc8175408a56 Mon Sep 17 00:00:00 2001 From: Haiyang Date: Wed, 8 Feb 2023 11:33:58 +0100 Subject: [PATCH] Fixed pygls v1.0 module import error (#868) * Fixed pygls v1.0 module import error * Clean up msg and add entry to changelog * Improved version compare * Updated pyproject.toml * Updated isort version to 5.12.0 * Fixed mypy issue * Removed poetry_core version constraint --- .pre-commit-config.yaml | 2 +- docs/changelog.rst | 2 ++ poetry.lock | 20 +++++++++-- pyproject.toml | 3 ++ sphinx_needs/lsp/esbonio.py | 33 ++++++++++++++----- tests/test_lsp/test_lsp.py | 26 ++++++++++++++- .../test_lsp_custom_directive_snippets.py | 5 +++ ..._lsp_custom_need_id_generate_from_title.py | 8 +++++ ...test_lsp_custom_need_id_generate_random.py | 8 +++++ tests/test_lsp/test_lsp_support_MyST.py | 26 ++++++++++++++- 10 files changed, 119 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c67b47b8a..016660f79 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - pep8-naming - repo: https://github.com/pycqa/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort diff --git a/docs/changelog.rst b/docs/changelog.rst index b62afba10..6c286e579 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,8 @@ License ----- Released: under development +* Bugfix: Fixed pygls version compatibility. + 1.2.0 ----- Released: 24.01.2023 diff --git a/poetry.lock b/poetry.lock index f7b2f40da..cdfd1f8a4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -680,6 +680,7 @@ files = [ {file = "lxml-4.9.2-cp35-cp35m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:ca989b91cf3a3ba28930a9fc1e9aeafc2a395448641df1f387a2d394638943b0"}, {file = "lxml-4.9.2-cp35-cp35m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:822068f85e12a6e292803e112ab876bc03ed1f03dddb80154c395f891ca6b31e"}, {file = "lxml-4.9.2-cp35-cp35m-win32.whl", hash = "sha256:be7292c55101e22f2a3d4d8913944cbea71eea90792bf914add27454a13905df"}, + {file = "lxml-4.9.2-cp35-cp35m-win_amd64.whl", hash = "sha256:998c7c41910666d2976928c38ea96a70d1aa43be6fe502f21a651e17483a43c5"}, {file = "lxml-4.9.2-cp36-cp36m-macosx_10_15_x86_64.whl", hash = "sha256:b26a29f0b7fc6f0897f043ca366142d2b609dc60756ee6e4e90b5f762c6adc53"}, {file = "lxml-4.9.2-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_24_i686.whl", hash = "sha256:ab323679b8b3030000f2be63e22cdeea5b47ee0abd2d6a1dc0c8103ddaa56cd7"}, {file = "lxml-4.9.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:689bb688a1db722485e4610a503e3e9210dcc20c520b45ac8f7533c837be76fe"}, @@ -689,6 +690,7 @@ files = [ {file = "lxml-4.9.2-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:58bfa3aa19ca4c0f28c5dde0ff56c520fbac6f0daf4fac66ed4c8d2fb7f22e74"}, {file = "lxml-4.9.2-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:bc718cd47b765e790eecb74d044cc8d37d58562f6c314ee9484df26276d36a38"}, {file = "lxml-4.9.2-cp36-cp36m-win32.whl", hash = "sha256:d5bf6545cd27aaa8a13033ce56354ed9e25ab0e4ac3b5392b763d8d04b08e0c5"}, + {file = "lxml-4.9.2-cp36-cp36m-win_amd64.whl", hash = "sha256:3ab9fa9d6dc2a7f29d7affdf3edebf6ece6fb28a6d80b14c3b2fb9d39b9322c3"}, {file = "lxml-4.9.2-cp37-cp37m-macosx_10_15_x86_64.whl", hash = "sha256:05ca3f6abf5cf78fe053da9b1166e062ade3fa5d4f92b4ed688127ea7d7b1d03"}, {file = "lxml-4.9.2-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_24_i686.whl", hash = "sha256:a5da296eb617d18e497bcf0a5c528f5d3b18dadb3619fbdadf4ed2356ef8d941"}, {file = "lxml-4.9.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl", hash = "sha256:04876580c050a8c5341d706dd464ff04fd597095cc8c023252566a8826505726"}, @@ -1128,6 +1130,20 @@ category = "main" optional = false python-versions = ">=3.7" files = [ + {file = "Pillow-9.4.0-1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:1b4b4e9dda4f4e4c4e6896f93e84a8f0bcca3b059de9ddf67dac3c334b1195e1"}, + {file = "Pillow-9.4.0-1-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:fb5c1ad6bad98c57482236a21bf985ab0ef42bd51f7ad4e4538e89a997624e12"}, + {file = "Pillow-9.4.0-1-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:f0caf4a5dcf610d96c3bd32932bfac8aee61c96e60481c2a0ea58da435e25acd"}, + {file = "Pillow-9.4.0-1-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:3f4cc516e0b264c8d4ccd6b6cbc69a07c6d582d8337df79be1e15a5056b258c9"}, + {file = "Pillow-9.4.0-1-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:b8c2f6eb0df979ee99433d8b3f6d193d9590f735cf12274c108bd954e30ca858"}, + {file = "Pillow-9.4.0-1-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:b70756ec9417c34e097f987b4d8c510975216ad26ba6e57ccb53bc758f490dab"}, + {file = "Pillow-9.4.0-1-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:43521ce2c4b865d385e78579a082b6ad1166ebed2b1a2293c3be1d68dd7ca3b9"}, + {file = "Pillow-9.4.0-2-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:9d9a62576b68cd90f7075876f4e8444487db5eeea0e4df3ba298ee38a8d067b0"}, + {file = "Pillow-9.4.0-2-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:87708d78a14d56a990fbf4f9cb350b7d89ee8988705e58e39bdf4d82c149210f"}, + {file = "Pillow-9.4.0-2-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:8a2b5874d17e72dfb80d917213abd55d7e1ed2479f38f001f264f7ce7bae757c"}, + {file = "Pillow-9.4.0-2-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:83125753a60cfc8c412de5896d10a0a405e0bd88d0470ad82e0869ddf0cb3848"}, + {file = "Pillow-9.4.0-2-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:9e5f94742033898bfe84c93c831a6f552bb629448d4072dd312306bab3bd96f1"}, + {file = "Pillow-9.4.0-2-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:013016af6b3a12a2f40b704677f8b51f72cb007dac785a9933d5c86a72a7fe33"}, + {file = "Pillow-9.4.0-2-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:99d92d148dd03fd19d16175b6d355cc1b01faf80dae93c6c3eb4163709edc0a9"}, {file = "Pillow-9.4.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:2968c58feca624bb6c8502f9564dd187d0e1389964898f5e9e1fbc8533169157"}, {file = "Pillow-9.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c5c1362c14aee73f50143d74389b2c158707b4abce2cb055b7ad37ce60738d47"}, {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bd752c5ff1b4a870b7661234694f24b1d2b9076b8bf337321a814c612665f343"}, @@ -2168,10 +2184,10 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] [extras] -docs = [] +docs = ["sphinx"] immaterial = [] [metadata] lock-version = "2.0" python-versions = ">=3.7.0,<4.0" -content-hash = "9ee8ad0db8f36b0ccfea461220a55a8b912a636b4c101b904fbdbf6e0890bb56" +content-hash = "eb7cfd3f2626049dfccbbe22887db9fc7b0b06ee4bc262edacc43f65a3153526" diff --git a/pyproject.toml b/pyproject.toml index 65ff4624d..c9451c0b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,9 @@ pyparsing = "^3.0.9" # 3.0.5 error: https://github.com/pyparsing/pyparsing/issu pytest-benchmark = "^4.0.0" memray = "^1.3.1" +# package version compare, in case setuptools not available +packaging = "*" + [tool.pytest.ini_options] asyncio_mode= "auto" diff --git a/sphinx_needs/lsp/esbonio.py b/sphinx_needs/lsp/esbonio.py index 654fa3afc..237291e57 100644 --- a/sphinx_needs/lsp/esbonio.py +++ b/sphinx_needs/lsp/esbonio.py @@ -11,15 +11,30 @@ from esbonio.lsp.rst import CompletionContext, DefinitionContext, HoverContext from esbonio.lsp.sphinx import SphinxLanguageServer from jinja2 import BaseLoader, Environment -from pygls.lsp.types import ( - CompletionItem, - CompletionItemKind, - InsertTextFormat, - Location, - Position, - Range, - TextEdit, -) +from packaging import version +from pygls import __version__ + +if version.parse(__version__) < version.parse("1.0"): + from pygls.lsp.types import ( + CompletionItem, + CompletionItemKind, + InsertTextFormat, + Location, + Position, + Range, + TextEdit, + ) +else: + from lsprotocol.types import ( # type: ignore[no-redef] + CompletionItem, + CompletionItemKind, + InsertTextFormat, + Location, + Position, + Range, + TextEdit, + ) + from sphinx.application import Sphinx from sphinx_needs.lsp.needs_store import NeedsStore diff --git a/tests/test_lsp/test_lsp.py b/tests/test_lsp/test_lsp.py index b93513292..5e16134b3 100644 --- a/tests/test_lsp/test_lsp.py +++ b/tests/test_lsp/test_lsp.py @@ -5,7 +5,13 @@ import pytest import pytest_lsp -from pygls.lsp.types import MarkupContent, MarkupKind, Position, Range +from packaging import version +from pygls import __version__ + +if version.parse(__version__) < version.parse("1.0"): + from pygls.lsp.types import MarkupContent, MarkupKind, Position, Range +else: + from lsprotocol.types import MarkupContent, MarkupKind, Position, Range TEST_DOC_ROOT_URI = os.path.join("file://", os.path.abspath(os.path.dirname(__file__)), "doc_example_lsp") TEST_FILE_URI = os.path.join(TEST_DOC_ROOT_URI, "index.rst") @@ -18,6 +24,9 @@ async def client(): pass +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_need_directive_role_completion(client): # check needs directive completion @@ -202,6 +211,9 @@ async def test_need_directive_role_completion(client): assert need_role_need.data["source_feature"] == "sphinx_needs.lsp.esbonio.NeedlsFeatures" +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_need_auto_generated_id_completion(client): # check needs option id snippet, auto-generated need IDs, e.g. :id: REQ_e0bafd9b @@ -222,6 +234,9 @@ async def test_need_auto_generated_id_completion(client): assert needs_option_id.kind == 15 # CompletionItemKind.Snippet +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_need_directive_snippets_completion(client): # check need directive snippets completion @@ -244,6 +259,9 @@ async def test_need_directive_snippets_completion(client): assert need_directive_snippets_req.data["source_feature"] == "sphinx_needs.lsp.esbonio.NeedlsFeatures" +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_need_id_selection_completion(client): # check need ID selection completion for need type, e.g. :need:`->` @@ -275,6 +293,9 @@ async def test_need_id_selection_completion(client): assert id_selection_need_id.data["source_feature"] == "sphinx_needs.lsp.esbonio.NeedlsFeatures" +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_goto_definition(client): # check goto defintion results @@ -292,6 +313,9 @@ async def test_goto_definition(client): assert defined_location.range.end.character == 0 +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_hover(client): # check hover results diff --git a/tests/test_lsp/test_lsp_custom_directive_snippets.py b/tests/test_lsp/test_lsp_custom_directive_snippets.py index 559e892d3..09941a70c 100644 --- a/tests/test_lsp/test_lsp_custom_directive_snippets.py +++ b/tests/test_lsp/test_lsp_custom_directive_snippets.py @@ -5,6 +5,8 @@ import pytest import pytest_lsp +from packaging import version +from pygls import __version__ TEST_DOC_ROOT_URI = os.path.join( "file://", os.path.abspath(os.path.dirname(__file__)), "doc_lsp_custom_directive_snippets" @@ -35,6 +37,9 @@ async def client(): pass +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_custom_directive_snippets(client): # check need custom directive snippets completion diff --git a/tests/test_lsp/test_lsp_custom_need_id_generate_from_title.py b/tests/test_lsp/test_lsp_custom_need_id_generate_from_title.py index d673cc3ea..b2336b92e 100644 --- a/tests/test_lsp/test_lsp_custom_need_id_generate_from_title.py +++ b/tests/test_lsp/test_lsp_custom_need_id_generate_from_title.py @@ -5,6 +5,8 @@ import pytest import pytest_lsp +from packaging import version +from pygls import __version__ TEST_DOC_ROOT_URI = os.path.join( "file://", os.path.abspath(os.path.dirname(__file__)), "doc_lsp_custom_need_id_generate_from_title" @@ -19,6 +21,9 @@ async def client(): pass +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_directive_snippets_with_custom_need_id_generate_from_title(client): need_directive_snippets = await client.completion_request(uri=TEST_FILE_URI, line=10, character=2) @@ -36,6 +41,9 @@ async def test_directive_snippets_with_custom_need_id_generate_from_title(client assert need_directive_snippets_req.insert_text.startswith(" req:: ${1:title}\n\t:id: ${2:TEST_ID_TEST") +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_id_auto_generation_with_custom_id_generate_from_title(client): need_req_options_result = await client.completion_request(uri=TEST_FILE_URI, line=11, character=3) diff --git a/tests/test_lsp/test_lsp_custom_need_id_generate_random.py b/tests/test_lsp/test_lsp_custom_need_id_generate_random.py index b17336ef9..28fa23260 100644 --- a/tests/test_lsp/test_lsp_custom_need_id_generate_random.py +++ b/tests/test_lsp/test_lsp_custom_need_id_generate_random.py @@ -5,6 +5,8 @@ import pytest import pytest_lsp +from packaging import version +from pygls import __version__ TEST_DOC_ROOT_URI = os.path.join( "file://", os.path.abspath(os.path.dirname(__file__)), "doc_lsp_custom_need_id_generate_random" @@ -19,6 +21,9 @@ async def client(): pass +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_directive_snippets_with_custom_need_id_generate_random(client): need_directive_snippets = await client.completion_request(uri=TEST_FILE_URI, line=10, character=2) @@ -37,6 +42,9 @@ async def test_directive_snippets_with_custom_need_id_generate_random(client): assert "_Test" in need_directive_snippets_req.insert_text +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_id_auto_generation_with_custom_id_generate_random(client): need_req_options_result = await client.completion_request(uri=TEST_FILE_URI, line=11, character=3) diff --git a/tests/test_lsp/test_lsp_support_MyST.py b/tests/test_lsp/test_lsp_support_MyST.py index 41f98cf65..328e98b6e 100644 --- a/tests/test_lsp/test_lsp_support_MyST.py +++ b/tests/test_lsp/test_lsp_support_MyST.py @@ -5,7 +5,13 @@ import pytest import pytest_lsp -from pygls.lsp.types import MarkupContent, MarkupKind, Position, Range +from packaging import version +from pygls import __version__ + +if version.parse(__version__) < version.parse("1.0"): + from pygls.lsp.types import MarkupContent, MarkupKind, Position, Range +else: + from lsprotocol.types import MarkupContent, MarkupKind, Position, Range TEST_DOC_ROOT_URI = os.path.join("file://", os.path.abspath(os.path.dirname(__file__)), "doc_lsp_support_MyST") TEST_MD_FILE_URI = os.path.join(TEST_DOC_ROOT_URI, "myfile.md") @@ -18,6 +24,9 @@ async def client(): pass +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_goto_definition_support_for_myst(client): # Check Goto Defintion support for MySt/Markdown file, e.g. myfile.md @@ -62,6 +71,9 @@ async def test_lsp_goto_definition_support_for_myst(client): assert goto_rst_location.range.end.character == 0 +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_hover_support_for_myst(client): # Check Hover support for MyST/Markdown file @@ -84,6 +96,9 @@ async def test_lsp_hover_support_for_myst(client): ) +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_id_selection_completion_support_for_myst(client): # Check ID selection completion support for MyST/Markdown file @@ -169,6 +184,9 @@ async def test_lsp_id_selection_completion_support_for_myst(client): assert need_id_md_result.data["source_feature"] == "sphinx_needs.lsp.esbonio.NeedlsFeatures" +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_need_directive_snippets_completion_for_myst(client): # Check need directive snippets support for MyST/Markdown @@ -242,6 +260,9 @@ async def test_lsp_need_directive_snippets_completion_for_myst(client): assert needs_directive_spec_md_inside_eval_rst.data["source_feature"] == "sphinx_needs.lsp.esbonio.NeedlsFeatures" +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_needs_option_id_completion_for_myst(client): # Needs option id suggestion is the same for MyST/Markdown as for rst/Sphinx file, e.g. :id: @@ -263,6 +284,9 @@ async def test_lsp_needs_option_id_completion_for_myst(client): assert needs_option_id.kind == 15 # CompletionItemKind.Snippet +@pytest.mark.skipif( + version.parse(__version__) >= version.parse("1.0"), reason="Esbonio version >=0.16.0 using pygls >= 1.0 not tested." +) @pytest.mark.asyncio async def test_lsp_need_role_need_completion_for_myst(client): # Need role need support for MyST/Markdown file