Skip to content

Commit

Permalink
Introduce isort to check import order
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrabel committed Dec 22, 2023
1 parent de87a80 commit 4b9f32e
Show file tree
Hide file tree
Showing 56 changed files with 98 additions and 89 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ jobs:
# This error cannot be resolved by adding a pylint: disable=unused-argument comment ...
- run: |
pip install -e .[pylint,pycodestyle,pyflakes]
pip install black
pip install isort black
- name: Pylint checks
run: pylint pylsp test
- name: Check import order with isort
run: isort --check --profile black pylsp test
- name: Code style checks with black
run: black --check pylsp test
- name: Pyflakes checks
Expand Down
2 changes: 2 additions & 0 deletions pylsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Copyright 2021- Python Language Server Contributors.

import os

import pluggy

from . import _version
from ._version import __version__

Expand Down
2 changes: 1 addition & 1 deletion pylsp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
except Exception: # pylint: disable=broad-except
import json

from ._version import __version__
from .python_lsp import (
PythonLSPServer,
start_io_lang_server,
start_tcp_lang_server,
start_ws_lang_server,
)
from ._version import __version__

LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(
time.localtime().tm_zone
Expand Down
2 changes: 1 addition & 1 deletion pylsp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pluggy
from pluggy._hooks import HookImpl

from pylsp import _utils, hookspecs, uris, PYLSP
from pylsp import PYLSP, _utils, hookspecs, uris

# See compatibility note on `group` keyword:
# https://docs.python.org/3/library/importlib.metadata.html#entry-points
Expand Down
2 changes: 2 additions & 0 deletions pylsp/config/flake8_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import logging
import os

from pylsp._utils import find_parents

from .source import ConfigSource

log = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion pylsp/config/pycodestyle_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Copyright 2021- Python Language Server Contributors.

import pycodestyle

from pylsp._utils import find_parents
from .source import ConfigSource

from .source import ConfigSource

CONFIG_KEY = "pycodestyle"
USER_CONFIGS = [pycodestyle.USER_CONFIG] if pycodestyle.USER_CONFIG else []
Expand Down
3 changes: 1 addition & 2 deletions pylsp/plugins/_resolvers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

from collections import defaultdict
import logging
from collections import defaultdict
from time import time

from jedi.api.classes import Completion

from pylsp import lsp


log = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions pylsp/plugins/_rope_task_handle.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

import logging

from typing import Callable, ContextManager, List, Optional, Sequence

from rope.base.taskhandle import BaseJobSet, BaseTaskHandle

from pylsp.workspace import Workspace
from pylsp._utils import throttle
from pylsp.workspace import Workspace

log = logging.getLogger(__name__)
Report = Callable[[str, int], None]
Expand Down
3 changes: 2 additions & 1 deletion pylsp/plugins/autopep8_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import logging

import pycodestyle
from autopep8 import fix_code, continued_indentation as autopep8_c_i
from autopep8 import continued_indentation as autopep8_c_i
from autopep8 import fix_code

from pylsp import hookimpl
from pylsp._utils import get_eol_chars
Expand Down
6 changes: 4 additions & 2 deletions pylsp/plugins/definition.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.
from __future__ import annotations

import logging
from typing import Any, Dict, List, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Dict, List

import jedi

from pylsp import hookimpl, uris, _utils
from pylsp import _utils, hookimpl, uris

if TYPE_CHECKING:
from jedi.api import Script
from jedi.api.classes import Name

from pylsp.config.config import Config
from pylsp.workspace import Document

Expand Down
3 changes: 2 additions & 1 deletion pylsp/plugins/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2021- Python Language Server Contributors.

import logging
from pylsp import hookimpl, lsp, _utils

from pylsp import _utils, hookimpl, lsp

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging

from pylsp import hookimpl, _utils
from pylsp import _utils, hookimpl

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/jedi_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging

from pylsp import hookimpl, uris, _utils
from pylsp import _utils, hookimpl, uris

log = logging.getLogger(__name__)

Expand Down
2 changes: 2 additions & 0 deletions pylsp/plugins/mccabe_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import ast
import logging

import mccabe

from pylsp import hookimpl, lsp

log = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions pylsp/plugins/preload_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2021- Python Language Server Contributors.

import logging

from pylsp import hookimpl

log = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions pylsp/plugins/pydocstyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys

import pydocstyle

from pylsp import hookimpl, lsp

log = logging.getLogger(__name__)
Expand Down
4 changes: 3 additions & 1 deletion pylsp/plugins/pyflakes_lint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

from pyflakes import api as pyflakes_api, messages
from pyflakes import api as pyflakes_api
from pyflakes import messages

from pylsp import hookimpl, lsp

# Pyflakes messages that should be reported as Errors instead of Warns
Expand Down
6 changes: 3 additions & 3 deletions pylsp/plugins/pylint_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""Linter plugin for pylint."""
import collections
import logging
import sys
import re
from subprocess import Popen, PIPE
import os
import re
import shlex
import sys
from subprocess import PIPE, Popen

from pylsp import hookimpl, lsp

Expand Down
3 changes: 2 additions & 1 deletion pylsp/plugins/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2021- Python Language Server Contributors.

import logging
from pylsp import hookimpl, uris, _utils

from pylsp import _utils, hookimpl, uris

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2022- Python Language Server Contributors.

import logging
from typing import Any, Dict, Generator, List, Optional, Set, Union
import threading
from typing import Any, Dict, Generator, List, Optional, Set, Union

import parso
from jedi import Script
Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/rope_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Copyright 2021- Python Language Server Contributors.

import logging

from rope.contrib.codeassist import code_assist, sorted_proposals

from pylsp import _utils, hookimpl, lsp


log = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/rope_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rope.base import libutils
from rope.refactor.rename import Rename

from pylsp import hookimpl, uris, _utils
from pylsp import _utils, hookimpl, uris

log = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion pylsp/plugins/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import logging
import re
from pylsp import hookimpl, _utils

from pylsp import _utils, hookimpl

log = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions pylsp/plugins/yapf_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import logging
import os

import whatthepatch
from yapf.yapflib import file_resources, style
from yapf.yapflib.yapf_api import FormatCode

import whatthepatch

from pylsp import hookimpl
from pylsp._utils import get_eol_chars

Expand Down
13 changes: 7 additions & 6 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

from functools import partial
import logging
import os
import socketserver
import threading
import uuid
from typing import List, Dict, Any
import ujson as json
from functools import partial
from typing import Any, Dict, List

import ujson as json
from pylsp_jsonrpc.dispatchers import MethodDispatcher
from pylsp_jsonrpc.endpoint import Endpoint
from pylsp_jsonrpc.streams import JsonRpcStreamReader, JsonRpcStreamWriter

from . import lsp, _utils, uris
from .config import config
from .workspace import Workspace, Document, Notebook, Cell
from . import _utils, lsp, uris
from ._version import __version__
from .config import config
from .workspace import Cell, Document, Notebook, Workspace

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,6 +109,7 @@ def start_ws_lang_server(port, check_parent_process, handler_class):
try:
import asyncio
from concurrent.futures import ThreadPoolExecutor

import websockets
except ImportError as e:
raise ImportError(
Expand Down
1 change: 1 addition & 0 deletions pylsp/uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import re
from urllib import parse

from pylsp import IS_WIN

RE_DRIVE_LETTER_PATH = re.compile(r"^\/[a-zA-Z]:")
Expand Down
8 changes: 4 additions & 4 deletions pylsp/workspace.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import functools
import io
import logging
from contextlib import contextmanager
import os
import re
import uuid
import functools
from typing import Optional, Generator, Callable, List
from contextlib import contextmanager
from threading import RLock
from typing import Callable, Generator, List, Optional

import jedi

from . import lsp, uris, _utils
from . import _utils, lsp, uris

log = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ addopts = "--cov-report html --cov-report term --junitxml=pytest.xml --cov pylsp

[tool.coverage.run]
concurrency = ["multiprocessing", "thread"]

[tool.isort]
profile = "black"
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

from setuptools import setup, find_packages

from setuptools import find_packages, setup

if __name__ == "__main__":
setup(
Expand Down
2 changes: 1 addition & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright 2021- Python Language Server Contributors.

import pytest
from pylsp import IS_WIN

from pylsp import IS_WIN

unix_only = pytest.mark.skipif(IS_WIN, reason="Unix only")
windows_only = pytest.mark.skipif(not IS_WIN, reason="Windows only")
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

""" py.test configuration"""
import logging

from pylsp.__main__ import LOG_FORMAT

logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
Expand Down
Loading

0 comments on commit 4b9f32e

Please sign in to comment.