summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 17:11:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 17:11:02 +0000
commitfd789a6d95e69c38bef1aa8625f7fbd16660a201 (patch)
treeffbd8a5e6915119a32cbf70cd2e1aa62ebe0ca72 /src
parentAdding debian version 0.1.35. (diff)
downloaddebputy-fd789a6d95e69c38bef1aa8625f7fbd16660a201.tar.xz
debputy-fd789a6d95e69c38bef1aa8625f7fbd16660a201.zip
Merging upstream version 0.1.36.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src')
-rw-r--r--src/debputy/dh_migration/migration.py12
-rw-r--r--src/debputy/linting/lint_impl.py2
-rw-r--r--src/debputy/linting/lint_util.py27
-rw-r--r--src/debputy/lsp/debputy_ls.py2
-rw-r--r--src/debputy/lsp/lsp_debian_changelog.py2
-rw-r--r--src/debputy/lsp/lsp_debian_control.py2
-rw-r--r--src/debputy/lsp/lsp_debian_control_reference_data.py2
-rw-r--r--src/debputy/lsp/lsp_debian_copyright.py2
-rw-r--r--src/debputy/lsp/lsp_debian_debputy_manifest.py2
-rw-r--r--src/debputy/lsp/lsp_debian_patches_series.py2
-rw-r--r--src/debputy/lsp/lsp_debian_rules.py45
-rw-r--r--src/debputy/lsp/lsp_debian_tests_control.py2
-rw-r--r--src/debputy/lsp/lsp_dispatch.py2
-rw-r--r--src/debputy/lsp/lsp_features.py2
-rw-r--r--src/debputy/lsp/lsp_generic_deb822.py2
-rw-r--r--src/debputy/lsp/lsp_generic_yaml.py2
-rw-r--r--src/debputy/lsp/quickfixes.py2
-rw-r--r--src/debputy/lsp/spellchecking.py2
-rw-r--r--src/debputy/lsp/text_edit.py2
-rw-r--r--src/debputy/lsp/text_util.py2
-rw-r--r--src/debputy/lsprotocol/__init__.py0
-rw-r--r--src/debputy/lsprotocol/types.py48
22 files changed, 144 insertions, 22 deletions
diff --git a/src/debputy/dh_migration/migration.py b/src/debputy/dh_migration/migration.py
index bcdd3f9..a1bd15a 100644
--- a/src/debputy/dh_migration/migration.py
+++ b/src/debputy/dh_migration/migration.py
@@ -3,7 +3,7 @@ import os
import re
import subprocess
from itertools import chain
-from typing import Optional, List, Callable, Set
+from typing import Optional, List, Callable, Set, Container
from debian.deb822 import Deb822
@@ -140,6 +140,16 @@ def _requested_debputy_plugins(debian_dir: VirtualPath) -> Optional[Set[str]]:
return plugins
+def determine_debputy_integration_level(sequences: Container[str]) -> Optional[str]:
+ has_zz_debputy = "zz-debputy" in sequences or "debputy" in sequences
+ has_zz_debputy_rrr = "zz-debputy-rrr" in sequences
+ if has_zz_debputy:
+ return MIGRATION_TARGET_DH_DEBPUTY
+ if has_zz_debputy_rrr:
+ return MIGRATION_TARGET_DH_DEBPUTY_RRR
+ return None
+
+
def _check_migration_target(
debian_dir: VirtualPath,
migration_target: Optional[str],
diff --git a/src/debputy/linting/lint_impl.py b/src/debputy/linting/lint_impl.py
index 63f4e77..b424460 100644
--- a/src/debputy/linting/lint_impl.py
+++ b/src/debputy/linting/lint_impl.py
@@ -6,7 +6,7 @@ import sys
import textwrap
from typing import Optional, List, Union, NoReturn, Mapping
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
CodeAction,
Command,
CodeActionParams,
diff --git a/src/debputy/linting/lint_util.py b/src/debputy/linting/lint_util.py
index 1fde104..0c293f0 100644
--- a/src/debputy/linting/lint_util.py
+++ b/src/debputy/linting/lint_util.py
@@ -17,9 +17,17 @@ from typing import (
cast,
)
-from lsprotocol.types import Position, Range, Diagnostic, DiagnosticSeverity, TextEdit
+from debputy.lsprotocol.types import (
+ Position,
+ Range,
+ Diagnostic,
+ DiagnosticSeverity,
+ TextEdit,
+)
from debputy.commands.debputy_cmd.output import OutputStylingBase
+from debputy.debhelper_emulation import extract_dh_addons_from_control
+from debputy.dh_migration.migration import determine_debputy_integration_level
from debputy.filesystem_scan import VirtualPathBase
from debputy.lsp.diagnostics import LintSeverity
from debputy.lsp.vendoring._deb822_repro import Deb822FileElement, parse_deb822_file
@@ -39,6 +47,19 @@ LinterImpl = Callable[["LintState"], Optional[List[Diagnostic]]]
FormatterImpl = Callable[["LintState"], Optional[Sequence[TextEdit]]]
+@dataclasses.dataclass(slots=True)
+class DebputyMetadata:
+ debputy_integration_level: Optional[str]
+
+ @classmethod
+ def from_data(cls, source_data: Optional[SourcePackage]) -> typing.Self:
+ sequences = set()
+ if source_data:
+ extract_dh_addons_from_control(source_data.fields, sequences)
+ integration_level = determine_debputy_integration_level(sequences)
+ return cls(integration_level)
+
+
class LintState:
@property
@@ -93,6 +114,10 @@ class LintState:
def effective_preference(self) -> Optional["EffectivePreference"]:
raise NotImplementedError
+ @property
+ def debputy_metadata(self) -> DebputyMetadata:
+ return DebputyMetadata.from_data(self.source_package)
+
@dataclasses.dataclass(slots=True)
class LintStateImpl(LintState):
diff --git a/src/debputy/lsp/debputy_ls.py b/src/debputy/lsp/debputy_ls.py
index 290997f..2009fd7 100644
--- a/src/debputy/lsp/debputy_ls.py
+++ b/src/debputy/lsp/debputy_ls.py
@@ -11,7 +11,7 @@ from typing import (
Literal,
)
-from lsprotocol.types import MarkupKind
+from debputy.lsprotocol.types import MarkupKind
from debputy.filesystem_scan import FSROOverlay, VirtualPathBase
from debputy.linting.lint_util import (
diff --git a/src/debputy/lsp/lsp_debian_changelog.py b/src/debputy/lsp/lsp_debian_changelog.py
index 824bc87..bde15b5 100644
--- a/src/debputy/lsp/lsp_debian_changelog.py
+++ b/src/debputy/lsp/lsp_debian_changelog.py
@@ -9,7 +9,7 @@ from typing import (
Iterable,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
Diagnostic,
DidOpenTextDocumentParams,
DidChangeTextDocumentParams,
diff --git a/src/debputy/lsp/lsp_debian_control.py b/src/debputy/lsp/lsp_debian_control.py
index 42f6a65..6e775c5 100644
--- a/src/debputy/lsp/lsp_debian_control.py
+++ b/src/debputy/lsp/lsp_debian_control.py
@@ -11,7 +11,7 @@ from typing import (
Dict,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
DiagnosticSeverity,
Range,
Diagnostic,
diff --git a/src/debputy/lsp/lsp_debian_control_reference_data.py b/src/debputy/lsp/lsp_debian_control_reference_data.py
index 42af500..f4a962a 100644
--- a/src/debputy/lsp/lsp_debian_control_reference_data.py
+++ b/src/debputy/lsp/lsp_debian_control_reference_data.py
@@ -26,7 +26,7 @@ from typing import (
)
from debian.debian_support import DpkgArchTable, Version
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
DiagnosticSeverity,
Diagnostic,
DiagnosticTag,
diff --git a/src/debputy/lsp/lsp_debian_copyright.py b/src/debputy/lsp/lsp_debian_copyright.py
index 54fb75e..a6d5573 100644
--- a/src/debputy/lsp/lsp_debian_copyright.py
+++ b/src/debputy/lsp/lsp_debian_copyright.py
@@ -9,7 +9,7 @@ from typing import (
Dict,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
DiagnosticSeverity,
Range,
Diagnostic,
diff --git a/src/debputy/lsp/lsp_debian_debputy_manifest.py b/src/debputy/lsp/lsp_debian_debputy_manifest.py
index bd3c746..78575cb 100644
--- a/src/debputy/lsp/lsp_debian_debputy_manifest.py
+++ b/src/debputy/lsp/lsp_debian_debputy_manifest.py
@@ -11,7 +11,7 @@ from typing import (
get_origin,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
Diagnostic,
TEXT_DOCUMENT_WILL_SAVE_WAIT_UNTIL,
Position,
diff --git a/src/debputy/lsp/lsp_debian_patches_series.py b/src/debputy/lsp/lsp_debian_patches_series.py
index 81ae32f..8fb5122 100644
--- a/src/debputy/lsp/lsp_debian_patches_series.py
+++ b/src/debputy/lsp/lsp_debian_patches_series.py
@@ -28,7 +28,7 @@ from debputy.lsp.quickfixes import (
from debputy.lsp.text_util import (
SemanticTokensState,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
CompletionItem,
Diagnostic,
CompletionList,
diff --git a/src/debputy/lsp/lsp_debian_rules.py b/src/debputy/lsp/lsp_debian_rules.py
index c2bf56d..072b785 100644
--- a/src/debputy/lsp/lsp_debian_rules.py
+++ b/src/debputy/lsp/lsp_debian_rules.py
@@ -13,9 +13,10 @@ from typing import (
Iterator,
Tuple,
Set,
+ FrozenSet,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
CompletionItem,
Diagnostic,
Range,
@@ -28,6 +29,7 @@ from lsprotocol.types import (
)
from debputy.debhelper_emulation import parse_drules_for_addons
+from debputy.dh_migration.migrators_impl import DH_COMMANDS_REPLACED
from debputy.linting.lint_util import LintState
from debputy.lsp.diagnostics import DiagnosticData
from debputy.lsp.lsp_features import (
@@ -226,6 +228,18 @@ def iter_make_lines(
yield line_no, line
+def _forbidden_hook_targets(lint_state: LintState) -> FrozenSet[str]:
+ debputy_integration_level = lint_state.debputy_metadata.debputy_integration_level
+ if debputy_integration_level is None:
+ return frozenset()
+ commands = DH_COMMANDS_REPLACED.get(debputy_integration_level)
+ if not commands:
+ return frozenset()
+ return frozenset(
+ itertools.chain.from_iterable(_as_hook_targets(c) for c in commands)
+ )
+
+
def _lint_debian_rules_impl(
lint_state: LintState,
) -> Optional[List[Diagnostic]]:
@@ -251,6 +265,8 @@ def _lint_debian_rules_impl(
source = "debputy"
missing_targets = {}
+ forbidden_hook_targets = _forbidden_hook_targets(lint_state)
+ all_allowed_hook_targets = all_hook_targets - forbidden_hook_targets
for line_no, line in iter_make_lines(lines, position_codec, diagnostics):
try:
@@ -268,14 +284,37 @@ def _lint_debian_rules_impl(
break
if "%" in target or "$" in target:
continue
- if target in all_hook_targets or target in missing_targets:
+ if target in forbidden_hook_targets:
+ pos, endpos = m.span(1)
+ r_server_units = Range(
+ Position(
+ line_no,
+ pos,
+ ),
+ Position(
+ line_no,
+ endpos,
+ ),
+ )
+ r = position_codec.range_to_client_units(lines, r_server_units)
+ diagnostics.append(
+ Diagnostic(
+ r,
+ f"The hook target {target} will not be run due to the choice of sequences.",
+ severity=DiagnosticSeverity.Error,
+ source=source,
+ )
+ )
+ continue
+
+ if target in all_allowed_hook_targets or target in missing_targets:
continue
pos, endpos = m.span(1)
hook_location = line_no, pos, endpos
missing_targets[target] = hook_location
for target, (line_no, pos, endpos) in missing_targets.items():
- candidates = _detect_possible_typo(target, all_hook_targets)
+ candidates = _detect_possible_typo(target, all_allowed_hook_targets)
if not candidates and not target.startswith(
("override_", "execute_before_", "execute_after_")
):
diff --git a/src/debputy/lsp/lsp_debian_tests_control.py b/src/debputy/lsp/lsp_debian_tests_control.py
index 111aae8..3562917 100644
--- a/src/debputy/lsp/lsp_debian_tests_control.py
+++ b/src/debputy/lsp/lsp_debian_tests_control.py
@@ -9,7 +9,7 @@ from typing import (
Dict,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
DiagnosticSeverity,
Range,
Diagnostic,
diff --git a/src/debputy/lsp/lsp_dispatch.py b/src/debputy/lsp/lsp_dispatch.py
index 8f370ef..e5def62 100644
--- a/src/debputy/lsp/lsp_dispatch.py
+++ b/src/debputy/lsp/lsp_dispatch.py
@@ -24,7 +24,7 @@ from debputy.lsp.lsp_features import (
C,
)
from debputy.util import _info
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
DidOpenTextDocumentParams,
DidChangeTextDocumentParams,
TEXT_DOCUMENT_DID_CHANGE,
diff --git a/src/debputy/lsp/lsp_features.py b/src/debputy/lsp/lsp_features.py
index 16e9d4d..800f738 100644
--- a/src/debputy/lsp/lsp_features.py
+++ b/src/debputy/lsp/lsp_features.py
@@ -18,7 +18,7 @@ from typing import (
from debputy.commands.debputy_cmd.context import CommandContext
from debputy.commands.debputy_cmd.output import _output_styling
from debputy.lsp.lsp_self_check import LSP_CHECKS
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
TEXT_DOCUMENT_WILL_SAVE_WAIT_UNTIL,
TEXT_DOCUMENT_CODE_ACTION,
DidChangeTextDocumentParams,
diff --git a/src/debputy/lsp/lsp_generic_deb822.py b/src/debputy/lsp/lsp_generic_deb822.py
index c8b476a..d8b9596 100644
--- a/src/debputy/lsp/lsp_generic_deb822.py
+++ b/src/debputy/lsp/lsp_generic_deb822.py
@@ -15,7 +15,7 @@ from typing import (
cast,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
CompletionParams,
CompletionList,
CompletionItem,
diff --git a/src/debputy/lsp/lsp_generic_yaml.py b/src/debputy/lsp/lsp_generic_yaml.py
index e464bdc..94267f7 100644
--- a/src/debputy/lsp/lsp_generic_yaml.py
+++ b/src/debputy/lsp/lsp_generic_yaml.py
@@ -14,7 +14,7 @@ from debputy.plugin.api.impl_types import (
DispatchingParserBase,
)
from debputy.util import _info, _warn
-from lsprotocol.types import MarkupContent, MarkupKind, Hover, Position, Range
+from debputy.lsprotocol.types import MarkupContent, MarkupKind, Hover, Position, Range
try:
from pygls.server import LanguageServer
diff --git a/src/debputy/lsp/quickfixes.py b/src/debputy/lsp/quickfixes.py
index 8787d9f..952506d 100644
--- a/src/debputy/lsp/quickfixes.py
+++ b/src/debputy/lsp/quickfixes.py
@@ -13,7 +13,7 @@ from typing import (
NotRequired,
)
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
CodeAction,
Command,
CodeActionParams,
diff --git a/src/debputy/lsp/spellchecking.py b/src/debputy/lsp/spellchecking.py
index 4cf71f2..223582d 100644
--- a/src/debputy/lsp/spellchecking.py
+++ b/src/debputy/lsp/spellchecking.py
@@ -6,7 +6,7 @@ import subprocess
from typing import Iterable, FrozenSet, Tuple, Optional, List
from debian.debian_support import Release
-from lsprotocol.types import Diagnostic, Range, Position, DiagnosticSeverity
+from debputy.lsprotocol.types import Diagnostic, Range, Position, DiagnosticSeverity
from debputy.lsp.diagnostics import DiagnosticData
from debputy.lsp.quickfixes import propose_correct_text_quick_fix
diff --git a/src/debputy/lsp/text_edit.py b/src/debputy/lsp/text_edit.py
index 4b210b2..af13e7d 100644
--- a/src/debputy/lsp/text_edit.py
+++ b/src/debputy/lsp/text_edit.py
@@ -6,7 +6,7 @@
#
from typing import List, Sequence
-from lsprotocol.types import Range, TextEdit, Position
+from debputy.lsprotocol.types import Range, TextEdit, Position
def get_well_formatted_range(lsp_range: Range) -> Range:
diff --git a/src/debputy/lsp/text_util.py b/src/debputy/lsp/text_util.py
index dd87571..8228fef 100644
--- a/src/debputy/lsp/text_util.py
+++ b/src/debputy/lsp/text_util.py
@@ -1,6 +1,6 @@
from typing import List, Optional, Sequence, Union, Iterable, TYPE_CHECKING
-from lsprotocol.types import (
+from debputy.lsprotocol.types import (
TextEdit,
Position,
Range,
diff --git a/src/debputy/lsprotocol/__init__.py b/src/debputy/lsprotocol/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/debputy/lsprotocol/__init__.py
diff --git a/src/debputy/lsprotocol/types.py b/src/debputy/lsprotocol/types.py
new file mode 100644
index 0000000..a57c4e0
--- /dev/null
+++ b/src/debputy/lsprotocol/types.py
@@ -0,0 +1,48 @@
+"""Wrapper module around `lsprotocol.types`
+
+This wrapper module is here to facility making `lsprotocol` optional
+for -backports. When available, it is a (mostly) transparent wrapper
+for the real module. When missing, it returns a placeholder object
+for anything for the purpose of making things simpler.
+"""
+
+from typing import TYPE_CHECKING, Any, Iterator, List
+
+if TYPE_CHECKING:
+ from lsprotocol import types
+
+ # To defeat "unused" detections that might attempt to
+ # optimize out the import
+ assert types is not None
+ __all__ = dir(types)
+
+else:
+ try:
+ from lsprotocol import types
+
+ __all__ = dir(types)
+
+ except ImportError:
+
+ class StubModule:
+
+ @staticmethod
+ def __getattr__(item: Any) -> Any:
+ return types
+
+ def __call__(self, *args, **kwargs) -> Any:
+ return self
+
+ def __iter__(self) -> Iterator[Any]:
+ return iter(())
+
+ types = StubModule()
+ __all__ = []
+
+
+def __dir__() -> List[str]:
+ return dir(types)
+
+
+def __getattr__(name: str) -> Any:
+ return getattr(types, name)