Skip to content
Open
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
17 changes: 12 additions & 5 deletions extensions/fine_python_ast/fine_python_ast/ast_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

from fine_python_ast import iast_provider

from finecode_extension_api.interfaces import icache, ifilemanager, ilogger
from finecode_extension_api.interfaces import icache, ifileeditor, ilogger


class PythonSingleAstProvider(iast_provider.IPythonSingleAstProvider):
CACHE_KEY = "PythonSingleAstProvider"
FILE_OPERATION_AUTHOR = ifileeditor.FileOperationAuthor(
id="PythonSingleAstProvider"
)

def __init__(
self,
file_manager: ifilemanager.IFileManager,
file_editor: ifileeditor.IFileEditor,
cache: icache.ICache,
logger: ilogger.ILogger,
):
self.cache = cache
self.file_manager = file_manager
self.file_editor = file_editor
self.logger = logger

async def get_file_ast(self, file_path: Path) -> ast.Module:
Expand All @@ -30,8 +33,12 @@ async def get_file_ast(self, file_path: Path) -> ast.Module:
except icache.CacheMissException:
...

file_content: str = await self.file_manager.get_content(file_path)
file_version: str = await self.file_manager.get_file_version(file_path)
async with self.file_editor.session(
author=self.FILE_OPERATION_AUTHOR
) as session:
async with session.read_file(file_path=file_path) as file_info:
file_content: str = file_info.content
file_version: str = file_info.version

try:
ast_instance = ast.parse(file_content)
Expand Down
4 changes: 4 additions & 0 deletions extensions/fine_python_ast/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
4 changes: 4 additions & 0 deletions extensions/fine_python_black/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
6 changes: 3 additions & 3 deletions extensions/fine_python_flake8/fine_python_flake8/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .action import Flake8LintHandler, Flake8LintHandlerConfig
from .action import Flake8LintFilesHandler, Flake8LintFilesHandlerConfig

__all__ = [
"Flake8LintHandler",
"Flake8LintHandlerConfig",
"Flake8LintFilesHandler",
"Flake8LintFilesHandlerConfig",
]
56 changes: 32 additions & 24 deletions extensions/fine_python_flake8/fine_python_flake8/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
from flake8.plugins import finder

from finecode_extension_api import code_action
from finecode_extension_api.actions import lint as lint_action
from finecode_extension_api.actions import lint_files as lint_files_action
from finecode_extension_api.interfaces import (
icache,
ifilemanager,
ifileeditor,
ilogger,
iprocessexecutor,
)


def map_flake8_check_result_to_lint_message(result: tuple) -> lint_action.LintMessage:
def map_flake8_check_result_to_lint_message(result: tuple) -> lint_files_action.LintMessage:
error_code, line_number, column, text, physical_line = result
return lint_action.LintMessage(
range=lint_action.Range(
start=lint_action.Position(line=line_number, character=column),
end=lint_action.Position(
return lint_files_action.LintMessage(
range=lint_files_action.Range(
start=lint_files_action.Position(line=line_number, character=column),
end=lint_files_action.Position(
line=line_number,
character=len(physical_line) if physical_line is not None else column,
),
Expand All @@ -35,9 +35,9 @@ def map_flake8_check_result_to_lint_message(result: tuple) -> lint_action.LintMe
code=error_code,
source="flake8",
severity=(
lint_action.LintMessageSeverity.WARNING
lint_files_action.LintMessageSeverity.WARNING
if error_code.startswith("W")
else lint_action.LintMessageSeverity.ERROR
else lint_files_action.LintMessageSeverity.ERROR
),
)

Expand All @@ -46,9 +46,9 @@ def run_flake8_on_single_file(
file_path: Path,
file_content: str,
file_ast: ast.Module,
config: Flake8LintHandlerConfig,
) -> list[lint_action.LintMessage]:
lint_messages: list[lint_action.LintMessage] = []
config: Flake8LintFilesHandlerConfig,
) -> list[lint_files_action.LintMessage]:
lint_messages: list[lint_files_action.LintMessage] = []
# flake8 expects lines with newline at the end
file_lines = [line + "\n" for line in file_content.split("\n")]
# TODO: investigate whether guide and decider can be reused. They cannot be
Expand Down Expand Up @@ -109,31 +109,34 @@ def run_flake8_on_single_file(


@dataclasses.dataclass
class Flake8LintHandlerConfig(code_action.ActionHandlerConfig):
class Flake8LintFilesHandlerConfig(code_action.ActionHandlerConfig):
max_line_length: int = 79
select: list[str] | None = None
extend_select: list[str] | None = None
extend_ignore: list[str] | None = None


class Flake8LintHandler(
code_action.ActionHandler[lint_action.LintAction, Flake8LintHandlerConfig]
class Flake8LintFilesHandler(
code_action.ActionHandler[lint_files_action.LintFilesAction, Flake8LintFilesHandlerConfig]
):
CACHE_KEY = "flake8"
FILE_OPERATION_AUTHOR = ifileeditor.FileOperationAuthor(
id="Flake8LintFilesHandler"
)

def __init__(
self,
config: Flake8LintHandlerConfig,
config: Flake8LintFilesHandlerConfig,
cache: icache.ICache,
logger: ilogger.ILogger,
file_manager: ifilemanager.IFileManager,
file_editor: ifileeditor.IFileEditor,
ast_provider: iast_provider.IPythonSingleAstProvider,
process_executor: iprocessexecutor.IProcessExecutor,
) -> None:
self.config = config
self.cache = cache
self.logger = logger
self.file_manager = file_manager
self.file_editor = file_editor
self.ast_provider = ast_provider
self.process_executor = process_executor

Expand All @@ -145,19 +148,24 @@ def __init__(

async def run_on_single_file(
self, file_path: Path
) -> lint_action.LintRunResult | None:
) -> lint_files_action.LintFilesRunResult | None:
messages = {}
try:
cached_lint_messages = await self.cache.get_file_cache(
file_path, self.CACHE_KEY
)
messages[str(file_path)] = cached_lint_messages
return lint_action.LintRunResult(messages=messages)
return lint_files_action.LintFilesRunResult(messages=messages)
except icache.CacheMissException:
pass

file_content = await self.file_manager.get_content(file_path)
file_version = await self.file_manager.get_file_version(file_path)
async with self.file_editor.session(
author=self.FILE_OPERATION_AUTHOR
) as session:
async with session.read_file(file_path=file_path) as file_info:
file_content: str = file_info.content
file_version: str = file_info.version

try:
file_ast = await self.ast_provider.get_file_ast(file_path=file_path)
except SyntaxError:
Expand All @@ -175,11 +183,11 @@ async def run_on_single_file(
file_path, file_version, self.CACHE_KEY, lint_messages
)

return lint_action.LintRunResult(messages=messages)
return lint_files_action.LintFilesRunResult(messages=messages)

async def run(
self,
payload: lint_action.LintRunPayload,
payload: lint_files_action.LintFilesRunPayload,
run_context: code_action.RunActionWithPartialResultsContext,
) -> None:
if self.config.select is not None and len(self.config.select) == 0:
Expand Down
4 changes: 4 additions & 0 deletions extensions/fine_python_import_linter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
4 changes: 4 additions & 0 deletions extensions/fine_python_isort/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
4 changes: 4 additions & 0 deletions extensions/fine_python_module_exports/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
49 changes: 28 additions & 21 deletions extensions/fine_python_mypy/fine_python_mypy/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from finecode_extension_api.interfaces import (
icache,
icommandrunner,
ifilemanager,
ifileeditor,
ilogger,
iextensionrunnerinfoprovider,
iprojectinfoprovider,
Expand All @@ -31,6 +31,7 @@ class MypyLintHandler(
code_action.ActionHandler[lint_action.LintAction, MypyManyCodeActionConfig]
):
CACHE_KEY = "mypy"
FILE_OPERATION_AUTHOR = ifileeditor.FileOperationAuthor(erovid)

DMYPY_ARGS = [
"--no-color-output",
Expand All @@ -50,15 +51,15 @@ def __init__(
project_info_provider: iprojectinfoprovider.IProjectInfoProvider,
cache: icache.ICache,
logger: ilogger.ILogger,
file_manager: ifilemanager.IFileManager,
file_editor: ifileeditor.IFileEditor,
lifecycle: code_action.ActionHandlerLifecycle,
command_runner: icommandrunner.ICommandRunner,
) -> None:
self.extension_runner_info_provider = extension_runner_info_provider
self.project_info_provider = project_info_provider
self.cache = cache
self.logger = logger
self.file_manager = file_manager
self.file_editor = file_editor
self.command_runner = command_runner

lifecycle.on_shutdown(self.shutdown)
Expand Down Expand Up @@ -116,9 +117,12 @@ async def run_on_single_file(
files_versions: dict[Path, str] = {}
# can we exclude cached files here? Using the right cache(one that handles
# dependencies as well) should be possible
for file_path in all_project_files:
file_version = await self.file_manager.get_file_version(file_path)
files_versions[file_path] = file_version
async with self.file_editor.session(
author=self.FILE_OPERATION_AUTHOR
) as session:
for file_path in all_project_files:
file_version = await session.read_file_version(file_path)
files_versions[file_path] = file_version

try:
all_processed_files_with_messages = await self._run_dmypy_on_project(
Expand All @@ -132,22 +136,25 @@ async def run_on_single_file(
) in all_processed_files_with_messages.items()
}

for (
file_path,
lint_messages,
) in all_processed_files_with_messages.items():
try:
file_version = files_versions[file_path]
except KeyError:
# mypy can resolve dependencies which are not in `files_to_lint`
# and as result also not in `files_versions`
file_version = await self.file_manager.get_file_version(
file_path
async with self.file_editor.session(
author=self.FILE_OPERATION_AUTHOR
) as session:
for (
file_path,
lint_messages,
) in all_processed_files_with_messages.items():
try:
file_version = files_versions[file_path]
except KeyError:
# mypy can resolve dependencies which are not in `files_to_lint`
# and as result also not in `files_versions`
file_version = await session.read_file_version(
file_path
)

await self.cache.save_file_cache(
file_path, file_version, self.CACHE_KEY, lint_messages
)

await self.cache.save_file_cache(
file_path, file_version, self.CACHE_KEY, lint_messages
)
finally:
project_checked_event.set()
del self._projects_being_checked_done_events[project_path]
Expand Down
18 changes: 13 additions & 5 deletions extensions/fine_python_mypy/fine_python_mypy/ast_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
import mypy.options as mypy_options
from fine_python_mypy import iast_provider

from finecode_extension_api.interfaces import icache, ifilemanager, ilogger
from finecode_extension_api.interfaces import icache, ifileeditor, ilogger


class MypySingleAstProvider(iast_provider.IMypySingleAstProvider):
CACHE_KEY = "MypySingleAstProvider"
FILE_OPERATION_AUTHOR = ifileeditor.FileOperationAuthor(
id="MypySingleAstProvider"
)

def __init__(
self,
file_manager: ifilemanager.IFileManager,
file_editor: ifileeditor.IFileEditor,
cache: icache.ICache,
logger: ilogger.ILogger,
):
self.cache = cache
self.file_manager = file_manager
self.file_editor = file_editor
self.logger = logger

async def get_file_ast(self, file_path: Path) -> mypy_nodes.MypyFile:
Expand All @@ -34,8 +37,13 @@ async def get_file_ast(self, file_path: Path) -> mypy_nodes.MypyFile:
except icache.CacheMissException:
...

file_text: str = await self.file_manager.get_content(file_path)
file_version: str = await self.file_manager.get_file_version(file_path)
async with self.file_editor.session(
author=self.FILE_OPERATION_AUTHOR
) as session:
async with session.read_file(file_path=file_path) as file_info:
file_text: str = file_info.content
file_version: str = file_info.version

base_dir = self.get_file_package_parent_dir_path(file_path)
module_program_path = self.get_file_program_path(
file_path=file_path, root_package_parent_dir_path=base_dir
Expand Down
4 changes: 4 additions & 0 deletions extensions/fine_python_mypy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editab
finecode = { path = "../../", editable = true }
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .group_project_files_by_lang_python import GroupProjectFilesByLangPythonHandler
from .list_project_files_by_lang_python import ListProjectFilesByLangPythonHandler
from .py_package_layout_info_provider import PyPackageLayoutInfoProvider

__all__ = ["ListProjectFilesByLangPythonHandler", "PyPackageLayoutInfoProvider"]
__all__ = ["GroupProjectFilesByLangPythonHandler","ListProjectFilesByLangPythonHandler", "PyPackageLayoutInfoProvider"]
Loading
Loading