Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -20,7 +20,13 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install -e .[dev]
- name: Lint
run: make lint
- name: Flake8 lint
run: flake8 .
- name: Black lint
run: black --diff --check .
- name: isort lint
run: isort --check --diff .
- name: MyPy lint
run: mypy .
- name: Test
run: make test
run: pytest -v tests/
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2018 Rupert Bedford
Copyright (c) 2018-2020 Rupert Bedford
Copyright (c) 2021 Python LSP contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![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)

> [Black](https://github.com/ambv/black) plugin for the [Python Language Server](https://github.com/palantir/python-language-server).
> [Black](https://github.com/ambv/black) plugin for the [Python LSP Server](https://github.com/python-lsp/python-lsp-server).

In the same `virtualenv` as `python-language-server`:
In the same `virtualenv` as `python-lsp-server`:

```shell
pip3 install pyls-black
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions pyls_black/plugin.py → pylsp_black/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import black
import toml
from pyls import hookimpl
from pylsp import hookimpl


@hookimpl(tryfirst=True)
def pyls_format_document(document):
def pylsp_format_document(document):
return format_document(document)


@hookimpl(tryfirst=True)
def pyls_format_range(document, range):
def pylsp_format_range(document, range):
range["start"]["character"] = 0
range["end"]["line"] += 1
range["end"]["character"] = 0
Expand Down Expand Up @@ -97,7 +97,12 @@ def load_config(filename: str) -> Dict:
black.TargetVersion[x.upper()] for x in file_config["target_version"]
)
elif file_config.get("py36"):
target_version = black.PY36_VERSIONS
target_version = {
black.TargetVersion.PY36,
black.TargetVersion.PY37,
black.TargetVersion.PY38,
black.TargetVersion.PY39,
}
else:
target_version = set()

Expand Down
16 changes: 8 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[metadata]
name = pyls-black
version = 0.4.6
author = Rupert Bedford
author_email = rupert@rupertb.com
description = Black plugin for the Python Language Server
url = https://github.com/rupert/pyls-black
name = python-lsp-black
version = 1.0.0.dev0
author = Python LSP contributors
author_email = andfoy@gmail.com
description = Black plugin for the Python LSP Server
url = https://github.com/python-lsp/python-lsp-black
long_description = file: README.md
long_description_content_type = text/markdown
classifiers =
Expand All @@ -14,11 +14,11 @@ classifiers =

[options]
packages = find:
install_requires = python-language-server; black>=19.3b0; toml
install_requires = python-lsp-server; black>=19.3b0; toml
python_requires = >= 3.6

[options.entry_points]
pyls = pyls_black = pyls_black.plugin
pylsp = pylsp_black = pylsp_black.plugin

[options.extras_require]
dev = isort>=5.0; flake8; pytest; mypy; pytest
Expand Down
54 changes: 32 additions & 22 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Standard library imports
import types
from pathlib import Path
from unittest.mock import Mock

# Third-party imports
import black
import pkg_resources
import pytest
from pyls import uris
from pyls.workspace import Document, Workspace

from pyls_black.plugin import load_config, pyls_format_document, pyls_format_range
# Python LSP imports
from pylsp import uris
from pylsp.workspace import Document, Workspace

# Local imports
from pylsp_black.plugin import load_config, pylsp_format_document, pylsp_format_range

here = Path(__file__).parent
fixtures_dir = here / "fixtures"
Expand Down Expand Up @@ -62,8 +67,8 @@ def config_document(workspace):
return Document(uri, workspace)


def test_pyls_format_document(unformatted_document, formatted_document):
result = pyls_format_document(unformatted_document)
def test_pylsp_format_document(unformatted_document, formatted_document):
result = pylsp_format_document(unformatted_document)

assert result == [
{
Expand All @@ -77,7 +82,7 @@ def test_pyls_format_document(unformatted_document, formatted_document):


def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_document):
result = pyls_format_document(unformatted_pyi_document)
result = pylsp_format_document(unformatted_pyi_document)

assert result == [
{
Expand All @@ -90,26 +95,26 @@ def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_docume
]


def test_pyls_format_document_unchanged(formatted_document):
result = pyls_format_document(formatted_document)
def test_pylsp_format_document_unchanged(formatted_document):
result = pylsp_format_document(formatted_document)

assert result == []


def test_pyls_format_pyi_document_unchanged(formatted_pyi_document):
result = pyls_format_document(formatted_pyi_document)
result = pylsp_format_document(formatted_pyi_document)

assert result == []


def test_pyls_format_document_syntax_error(invalid_document):
result = pyls_format_document(invalid_document)
def test_pylsp_format_document_syntax_error(invalid_document):
result = pylsp_format_document(invalid_document)

assert result == []


def test_pyls_format_document_with_config(config_document):
result = pyls_format_document(config_document)
def test_pylsp_format_document_with_config(config_document):
result = pylsp_format_document(config_document)

assert result == [
{
Expand All @@ -134,13 +139,13 @@ def test_pyls_format_document_with_config(config_document):
("start", "end", "expected"),
[(0, 0, 'a = "hello"\n'), (1, 1, "b = 42\n"), (0, 1, 'a = "hello"\nb = 42\n')],
)
def test_pyls_format_range(unformatted_document, start, end, expected):
def test_pylsp_format_range(unformatted_document, start, end, expected):
range = {
"start": {"line": start, "character": 0},
"end": {"line": end, "character": 0},
}

result = pyls_format_range(unformatted_document, range=range)
result = pylsp_format_range(unformatted_document, range=range)

assert result == [
{
Expand All @@ -153,18 +158,18 @@ def test_pyls_format_range(unformatted_document, start, end, expected):
]


def test_pyls_format_range_unchanged(formatted_document):
def test_pylsp_format_range_unchanged(formatted_document):
range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}

result = pyls_format_range(formatted_document, range=range)
result = pylsp_format_range(formatted_document, range=range)

assert result == []


def test_pyls_format_range_syntax_error(invalid_document):
def test_pylsp_format_range_syntax_error(invalid_document):
range = {"start": {"line": 0, "character": 0}, "end": {"line": 1, "character": 0}}

result = pyls_format_range(invalid_document, range=range)
result = pylsp_format_range(invalid_document, range=range)

assert result == []

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

assert config["target_version"] == black.PY36_VERSIONS
assert config["target_version"] == {
black.TargetVersion.PY36,
black.TargetVersion.PY37,
black.TargetVersion.PY38,
black.TargetVersion.PY39,
}


def test_load_config_defaults():
Expand All @@ -207,8 +217,8 @@ def test_load_config_defaults():


def test_entry_point():
distribution = pkg_resources.get_distribution("pyls-black")
entry_point = distribution.get_entry_info("pyls", "pyls_black")
distribution = pkg_resources.get_distribution("python-lsp-black")
entry_point = distribution.get_entry_info("pylsp", "pylsp_black")

assert entry_point is not None

Expand Down