Skip to content

Commit f3983c2

Browse files
authored
Merge pull request #1 from python-lsp/pylsp_migration
PR: Python LSP server migration
2 parents 2ca10aa + e0d3e13 commit f3983c2

File tree

7 files changed

+63
-41
lines changed

7 files changed

+63
-41
lines changed

.github/workflows/python.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [3.6, 3.7, 3.8]
14+
python-version: [3.6, 3.7, 3.8, 3.9]
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Set up Python ${{ matrix.python-version }}
@@ -20,7 +20,13 @@ jobs:
2020
python-version: ${{ matrix.python-version }}
2121
- name: Install dependencies
2222
run: python -m pip install -e .[dev]
23-
- name: Lint
24-
run: make lint
23+
- name: Flake8 lint
24+
run: flake8 .
25+
- name: Black lint
26+
run: black --diff --check .
27+
- name: isort lint
28+
run: isort --check --diff .
29+
- name: MyPy lint
30+
run: mypy .
2531
- name: Test
26-
run: make test
32+
run: pytest -v tests/

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2018 Rupert Bedford
3+
Copyright (c) 2018-2020 Rupert Bedford
4+
Copyright (c) 2021 Python LSP contributors
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

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

33
[![PyPI](https://img.shields.io/pypi/v/pyls-black.svg)](https://pypi.org/project/pyls-black/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
44

5-
> [Black](https://github.com/ambv/black) plugin for the [Python Language Server](https://github.com/palantir/python-language-server).
5+
> [Black](https://github.com/ambv/black) plugin for the [Python LSP Server](https://github.com/python-lsp/python-lsp-server).
66
7-
In the same `virtualenv` as `python-language-server`:
7+
In the same `virtualenv` as `python-lsp-server`:
88

99
```shell
1010
pip3 install pyls-black
File renamed without changes.

pyls_black/plugin.py renamed to pylsp_black/plugin.py

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

33
import black
44
import toml
5-
from pyls import hookimpl
5+
from pylsp import hookimpl
66

77

88
@hookimpl(tryfirst=True)
9-
def pyls_format_document(document):
9+
def pylsp_format_document(document):
1010
return format_document(document)
1111

1212

1313
@hookimpl(tryfirst=True)
14-
def pyls_format_range(document, range):
14+
def pylsp_format_range(document, range):
1515
range["start"]["character"] = 0
1616
range["end"]["line"] += 1
1717
range["end"]["character"] = 0
@@ -97,7 +97,12 @@ def load_config(filename: str) -> Dict:
9797
black.TargetVersion[x.upper()] for x in file_config["target_version"]
9898
)
9999
elif file_config.get("py36"):
100-
target_version = black.PY36_VERSIONS
100+
target_version = {
101+
black.TargetVersion.PY36,
102+
black.TargetVersion.PY37,
103+
black.TargetVersion.PY38,
104+
black.TargetVersion.PY39,
105+
}
101106
else:
102107
target_version = set()
103108

setup.cfg

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[metadata]
2-
name = pyls-black
3-
version = 0.4.6
4-
author = Rupert Bedford
5-
author_email = rupert@rupertb.com
6-
description = Black plugin for the Python Language Server
7-
url = https://github.com/rupert/pyls-black
2+
name = python-lsp-black
3+
version = 1.0.0.dev0
4+
author = Python LSP contributors
5+
author_email = andfoy@gmail.com
6+
description = Black plugin for the Python LSP Server
7+
url = https://github.com/python-lsp/python-lsp-black
88
long_description = file: README.md
99
long_description_content_type = text/markdown
1010
classifiers =
@@ -14,11 +14,11 @@ classifiers =
1414

1515
[options]
1616
packages = find:
17-
install_requires = python-language-server; black>=19.3b0; toml
17+
install_requires = python-lsp-server; black>=19.3b0; toml
1818
python_requires = >= 3.6
1919

2020
[options.entry_points]
21-
pyls = pyls_black = pyls_black.plugin
21+
pylsp = pylsp_black = pylsp_black.plugin
2222

2323
[options.extras_require]
2424
dev = isort>=5.0; flake8; pytest; mypy; pytest

tests/test_plugin.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
# Standard library imports
12
import types
23
from pathlib import Path
34
from unittest.mock import Mock
45

6+
# Third-party imports
57
import black
68
import pkg_resources
79
import pytest
8-
from pyls import uris
9-
from pyls.workspace import Document, Workspace
1010

11-
from pyls_black.plugin import load_config, pyls_format_document, pyls_format_range
11+
# Python LSP imports
12+
from pylsp import uris
13+
from pylsp.workspace import Document, Workspace
14+
15+
# Local imports
16+
from pylsp_black.plugin import load_config, pylsp_format_document, pylsp_format_range
1217

1318
here = Path(__file__).parent
1419
fixtures_dir = here / "fixtures"
@@ -62,8 +67,8 @@ def config_document(workspace):
6267
return Document(uri, workspace)
6368

6469

65-
def test_pyls_format_document(unformatted_document, formatted_document):
66-
result = pyls_format_document(unformatted_document)
70+
def test_pylsp_format_document(unformatted_document, formatted_document):
71+
result = pylsp_format_document(unformatted_document)
6772

6873
assert result == [
6974
{
@@ -77,7 +82,7 @@ def test_pyls_format_document(unformatted_document, formatted_document):
7782

7883

7984
def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_document):
80-
result = pyls_format_document(unformatted_pyi_document)
85+
result = pylsp_format_document(unformatted_pyi_document)
8186

8287
assert result == [
8388
{
@@ -90,26 +95,26 @@ def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_docume
9095
]
9196

9297

93-
def test_pyls_format_document_unchanged(formatted_document):
94-
result = pyls_format_document(formatted_document)
98+
def test_pylsp_format_document_unchanged(formatted_document):
99+
result = pylsp_format_document(formatted_document)
95100

96101
assert result == []
97102

98103

99104
def test_pyls_format_pyi_document_unchanged(formatted_pyi_document):
100-
result = pyls_format_document(formatted_pyi_document)
105+
result = pylsp_format_document(formatted_pyi_document)
101106

102107
assert result == []
103108

104109

105-
def test_pyls_format_document_syntax_error(invalid_document):
106-
result = pyls_format_document(invalid_document)
110+
def test_pylsp_format_document_syntax_error(invalid_document):
111+
result = pylsp_format_document(invalid_document)
107112

108113
assert result == []
109114

110115

111-
def test_pyls_format_document_with_config(config_document):
112-
result = pyls_format_document(config_document)
116+
def test_pylsp_format_document_with_config(config_document):
117+
result = pylsp_format_document(config_document)
113118

114119
assert result == [
115120
{
@@ -134,13 +139,13 @@ def test_pyls_format_document_with_config(config_document):
134139
("start", "end", "expected"),
135140
[(0, 0, 'a = "hello"\n'), (1, 1, "b = 42\n"), (0, 1, 'a = "hello"\nb = 42\n')],
136141
)
137-
def test_pyls_format_range(unformatted_document, start, end, expected):
142+
def test_pylsp_format_range(unformatted_document, start, end, expected):
138143
range = {
139144
"start": {"line": start, "character": 0},
140145
"end": {"line": end, "character": 0},
141146
}
142147

143-
result = pyls_format_range(unformatted_document, range=range)
148+
result = pylsp_format_range(unformatted_document, range=range)
144149

145150
assert result == [
146151
{
@@ -153,18 +158,18 @@ def test_pyls_format_range(unformatted_document, start, end, expected):
153158
]
154159

155160

156-
def test_pyls_format_range_unchanged(formatted_document):
161+
def test_pylsp_format_range_unchanged(formatted_document):
157162
range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}
158163

159-
result = pyls_format_range(formatted_document, range=range)
164+
result = pylsp_format_range(formatted_document, range=range)
160165

161166
assert result == []
162167

163168

164-
def test_pyls_format_range_syntax_error(invalid_document):
169+
def test_pylsp_format_range_syntax_error(invalid_document):
165170
range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}
166171

167-
result = pyls_format_range(invalid_document, range=range)
172+
result = pylsp_format_range(invalid_document, range=range)
168173

169174
assert result == []
170175

@@ -191,7 +196,12 @@ def test_load_config_target_version():
191196
def test_load_config_py36():
192197
config = load_config(str(fixtures_dir / "py36" / "example.py"))
193198

194-
assert config["target_version"] == black.PY36_VERSIONS
199+
assert config["target_version"] == {
200+
black.TargetVersion.PY36,
201+
black.TargetVersion.PY37,
202+
black.TargetVersion.PY38,
203+
black.TargetVersion.PY39,
204+
}
195205

196206

197207
def test_load_config_defaults():
@@ -207,8 +217,8 @@ def test_load_config_defaults():
207217

208218

209219
def test_entry_point():
210-
distribution = pkg_resources.get_distribution("pyls-black")
211-
entry_point = distribution.get_entry_info("pyls", "pyls_black")
220+
distribution = pkg_resources.get_distribution("python-lsp-black")
221+
entry_point = distribution.get_entry_info("pylsp", "pylsp_black")
212222

213223
assert entry_point is not None
214224

0 commit comments

Comments
 (0)