Skip to content

Commit

Permalink
Rename _utils module to utils (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Nov 6, 2023
1 parent ec876bb commit 1c4ad71
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 71 deletions.
16 changes: 8 additions & 8 deletions 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 utils, hookspecs, uris, PYLSP

# See compatibility note on `group` keyword:
# https://docs.python.org/3/library/importlib.metadata.html#entry-points
Expand Down Expand Up @@ -94,11 +94,11 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
log.info("Loaded pylsp plugin %s from %s", name, plugin)

for plugin_conf in self._pm.hook.pylsp_settings(config=self):
self._plugin_settings = _utils.merge_dicts(
self._plugin_settings = utils.merge_dicts(
self._plugin_settings, plugin_conf
)

self._plugin_settings = _utils.merge_dicts(
self._plugin_settings = utils.merge_dicts(
self._plugin_settings, self._init_opts.get("pylsp", {})
)

Expand Down Expand Up @@ -144,10 +144,10 @@ def settings(self, document_path=None):
sources = self._settings.get("configurationSources", DEFAULT_CONFIG_SOURCES)

# Plugin configuration
settings = _utils.merge_dicts(settings, self._plugin_settings)
settings = utils.merge_dicts(settings, self._plugin_settings)

# LSP configuration
settings = _utils.merge_dicts(settings, self._settings)
settings = utils.merge_dicts(settings, self._settings)

# User configuration
for source_name in reversed(sources):
Expand All @@ -158,7 +158,7 @@ def settings(self, document_path=None):
log.debug(
"Got user config from %s: %s", source.__class__.__name__, source_conf
)
settings = _utils.merge_dicts(settings, source_conf)
settings = utils.merge_dicts(settings, source_conf)

# Project configuration
for source_name in reversed(sources):
Expand All @@ -169,15 +169,15 @@ def settings(self, document_path=None):
log.debug(
"Got project config from %s: %s", source.__class__.__name__, source_conf
)
settings = _utils.merge_dicts(settings, source_conf)
settings = utils.merge_dicts(settings, source_conf)

log.debug("With configuration: %s", settings)

return settings

def find_parents(self, path, names):
root_path = uris.to_fs_path(self._root_uri)
return _utils.find_parents(root_path, path, names)
return utils.find_parents(root_path, path, names)

def plugin_settings(self, plugin, document_path=None):
return (
Expand Down
2 changes: 1 addition & 1 deletion pylsp/config/flake8_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging
import os
from pylsp._utils import find_parents
from pylsp.utils import find_parents
from .source import ConfigSource

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

import pycodestyle
from pylsp._utils import find_parents
from pylsp.utils import find_parents
from .source import ConfigSource


Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/autopep8_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from autopep8 import fix_code, continued_indentation as autopep8_c_i

from pylsp import hookimpl
from pylsp._utils import get_eol_chars
from pylsp.utils import get_eol_chars

log = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions pylsp/plugins/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import jedi

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

if TYPE_CHECKING:
from jedi.api import Script
Expand Down Expand Up @@ -44,7 +44,7 @@ def pylsp_definitions(
config: Config, document: Document, position: Dict[str, int]
) -> List[Dict[str, Any]]:
settings = config.plugin_settings("jedi_definition")
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)
script = document.jedi_script(use_document_path=True)
auto_import_modules = jedi.settings.auto_import_modules

Expand Down
4 changes: 2 additions & 2 deletions pylsp/plugins/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Copyright 2021- Python Language Server Contributors.

import logging
from pylsp import hookimpl, lsp, _utils
from pylsp import hookimpl, lsp, utils

log = logging.getLogger(__name__)


@hookimpl
def pylsp_document_highlight(document, position):
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)
usages = document.jedi_script().get_references(**code_position)

def is_valid(definition):
Expand Down
8 changes: 4 additions & 4 deletions pylsp/plugins/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import logging

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

log = logging.getLogger(__name__)


@hookimpl
def pylsp_hover(config, document, position):
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)
definitions = document.jedi_script(use_document_path=True).infer(**code_position)
word = document.word_at_position(position)

Expand All @@ -28,7 +28,7 @@ def pylsp_hover(config, document, position):

hover_capabilities = config.capabilities.get("textDocument", {}).get("hover", {})
supported_markup_kinds = hover_capabilities.get("contentFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

# Find first exact matching signature
signature = next(
Expand All @@ -41,7 +41,7 @@ def pylsp_hover(config, document, position):
)

return {
"contents": _utils.format_docstring(
"contents": utils.format_docstring(
# raw docstring returns only doc, without signature
definition.docstring(raw=True),
preferred_markup_kind,
Expand Down
10 changes: 5 additions & 5 deletions pylsp/plugins/jedi_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import parso

from pylsp import _utils, hookimpl, lsp
from pylsp import utils, hookimpl, lsp
from pylsp.plugins._resolvers import LABEL_RESOLVER, SNIPPET_RESOLVER

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -41,7 +41,7 @@ def pylsp_completions(config, document, position):
# pylint: disable=too-many-locals
settings = config.plugin_settings("jedi_completion", document_path=document.path)
resolve_eagerly = settings.get("eager", False)
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)

code_position["fuzzy"] = settings.get("fuzzy", False)
completions = document.jedi_script(use_document_path=True).complete(**code_position)
Expand All @@ -55,7 +55,7 @@ def pylsp_completions(config, document, position):
item_capabilities = completion_capabilities.get("completionItem", {})
snippet_support = item_capabilities.get("snippetSupport")
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

should_include_params = settings.get("include_params")
should_include_class_objects = settings.get("include_class_objects", False)
Expand Down Expand Up @@ -146,7 +146,7 @@ def pylsp_completion_item_resolve(config, completion_item, document):
)
item_capabilities = completion_capabilities.get("completionItem", {})
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

if shared_data:
completion, data = shared_data
Expand Down Expand Up @@ -209,7 +209,7 @@ def _resolve_completion(completion, d, markup_kind: str):
# pylint: disable=broad-except
completion["detail"] = _detail(d)
try:
docs = _utils.format_docstring(
docs = utils.format_docstring(
d.docstring(raw=True),
signatures=[signature.to_string() for signature in d.get_signatures()],
markup_kind=markup_kind,
Expand Down
6 changes: 3 additions & 3 deletions 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 hookimpl, uris, utils

log = logging.getLogger(__name__)

Expand All @@ -15,7 +15,7 @@ def pylsp_rename(
log.debug(
"Executing rename of %s to %s", document.word_at_position(position), new_name
)
kwargs = _utils.position_to_jedi_linecolumn(document, position)
kwargs = utils.position_to_jedi_linecolumn(document, position)
kwargs["new_name"] = new_name
try:
refactoring = document.jedi_script().rename(**kwargs)
Expand Down Expand Up @@ -54,6 +54,6 @@ def pylsp_rename(

def _num_lines(file_contents):
"Count the number of lines in the given string."
if _utils.get_eol_chars(file_contents):
if utils.get_eol_chars(file_contents):
return len(file_contents.splitlines())
return 0
2 changes: 1 addition & 1 deletion pylsp/plugins/pycodestyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pycodestyle

from pylsp import hookimpl, lsp
from pylsp._utils import get_eol_chars
from pylsp.utils import get_eol_chars

try:
from autopep8 import continued_indentation as autopep8_c_i
Expand Down
4 changes: 2 additions & 2 deletions pylsp/plugins/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Copyright 2021- Python Language Server Contributors.

import logging
from pylsp import hookimpl, uris, _utils
from pylsp import hookimpl, uris, utils

log = logging.getLogger(__name__)


@hookimpl
def pylsp_references(document, position, exclude_declaration):
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)
usages = document.jedi_script().get_references(**code_position)

if exclude_declaration:
Expand Down
8 changes: 4 additions & 4 deletions pylsp/plugins/rope_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from rope.contrib.codeassist import code_assist, sorted_proposals

from pylsp import _utils, hookimpl, lsp
from pylsp import utils, hookimpl, lsp


log = logging.getLogger(__name__)
Expand All @@ -19,7 +19,7 @@ def pylsp_settings():
def _resolve_completion(completion, data, markup_kind):
# pylint: disable=broad-except
try:
doc = _utils.format_docstring(data.get_doc(), markup_kind=markup_kind)
doc = utils.format_docstring(data.get_doc(), markup_kind=markup_kind)
except Exception as e:
log.debug("Failed to resolve Rope completion: %s", e)
doc = ""
Expand Down Expand Up @@ -57,7 +57,7 @@ def pylsp_completions(config, workspace, document, position):
)
item_capabilities = completion_capabilities.get("completionItem", {})
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

try:
definitions = code_assist(
Expand Down Expand Up @@ -104,7 +104,7 @@ def pylsp_completion_item_resolve(config, completion_item, document):
)
item_capabilities = completion_capabilities.get("completionItem", {})
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

if shared_data:
completion, data = shared_data
Expand Down
4 changes: 2 additions & 2 deletions 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 hookimpl, uris, utils

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,6 +61,6 @@ def _num_lines(resource):
"Count the number of lines in a `File` resource."
text = resource.read()

if _utils.get_eol_chars(text):
if utils.get_eol_chars(text):
return len(text.splitlines())
return 0
10 changes: 5 additions & 5 deletions pylsp/plugins/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging
import re
from pylsp import hookimpl, _utils
from pylsp import hookimpl, utils

log = logging.getLogger(__name__)

Expand All @@ -16,7 +16,7 @@

@hookimpl
def pylsp_signature_help(config, document, position):
code_position = _utils.position_to_jedi_linecolumn(document, position)
code_position = utils.position_to_jedi_linecolumn(document, position)
signatures = document.jedi_script().get_signatures(**code_position)

if not signatures:
Expand All @@ -31,7 +31,7 @@ def pylsp_signature_help(config, document, position):
supported_markup_kinds = signature_information_support.get(
"documentationFormat", ["markdown"]
)
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)
preferred_markup_kind = utils.choose_markup_kind(supported_markup_kinds)

s = signatures[0]

Expand All @@ -42,7 +42,7 @@ def pylsp_signature_help(config, document, position):
function_sig = " ".join([line.strip() for line in function_sig_lines])
sig = {
"label": function_sig,
"documentation": _utils.format_docstring(
"documentation": utils.format_docstring(
s.docstring(raw=True), markup_kind=preferred_markup_kind
),
}
Expand All @@ -52,7 +52,7 @@ def pylsp_signature_help(config, document, position):
sig["parameters"] = [
{
"label": p.name,
"documentation": _utils.format_docstring(
"documentation": utils.format_docstring(
_param_docs(docstring, p.name), markup_kind=preferred_markup_kind
),
}
Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/yapf_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import whatthepatch

from pylsp import hookimpl
from pylsp._utils import get_eol_chars
from pylsp.utils import get_eol_chars

log = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pylsp_jsonrpc.endpoint import Endpoint
from pylsp_jsonrpc.streams import JsonRpcStreamReader, JsonRpcStreamWriter

from . import lsp, _utils, uris
from . import lsp, utils, uris
from .config import config
from .workspace import Workspace, Document, Notebook, Cell
from ._version import __version__
Expand Down Expand Up @@ -250,7 +250,7 @@ def m_exit(self, **_kwargs):
self._jsonrpc_stream_writer.close()

def _match_uri_to_workspace(self, uri):
workspace_uri = _utils.match_uri_to_workspace(uri, self.workspaces)
workspace_uri = utils.match_uri_to_workspace(uri, self.workspaces)
return self.workspaces.get(workspace_uri, self.workspace)

def _hook(self, hook_name, doc_uri=None, **kwargs):
Expand Down Expand Up @@ -360,7 +360,7 @@ def m_initialize(

def watch_parent_process(pid):
# exit when the given pid is not alive
if not _utils.is_process_alive(pid):
if not utils.is_process_alive(pid):
log.info("parent process %s is not alive, exiting!", pid)
self.m_exit()
else:
Expand Down Expand Up @@ -439,7 +439,7 @@ def highlight(self, doc_uri, position):
def hover(self, doc_uri, position):
return self._hook("pylsp_hover", doc_uri, position=position) or {"contents": ""}

@_utils.debounce(LINT_DEBOUNCE_S, keyed_by="doc_uri")
@utils.debounce(LINT_DEBOUNCE_S, keyed_by="doc_uri")
def lint(self, doc_uri, is_saved):
# Since we're debounced, the document may no longer be open
workspace = self._match_uri_to_workspace(doc_uri)
Expand Down
File renamed without changes.
Loading

0 comments on commit 1c4ad71

Please sign in to comment.