diff options
Diffstat (limited to 'src/debputy/analysis/debian_dir.py')
-rw-r--r-- | src/debputy/analysis/debian_dir.py | 84 |
1 files changed, 28 insertions, 56 deletions
diff --git a/src/debputy/analysis/debian_dir.py b/src/debputy/analysis/debian_dir.py index d63b0c9..1e88b14 100644 --- a/src/debputy/analysis/debian_dir.py +++ b/src/debputy/analysis/debian_dir.py @@ -3,6 +3,7 @@ import os import stat import subprocess from typing import ( + AbstractSet, List, Mapping, Iterable, @@ -15,12 +16,14 @@ from typing import ( Iterator, TypedDict, NotRequired, - FrozenSet, ) from debputy.analysis import REFERENCE_DATA_TABLE from debputy.analysis.analysis_util import flatten_ppfs -from debputy.dh_migration.migrators_impl import read_dh_addon_sequences +from debputy.dh.dh_assistant import ( + resolve_active_and_inactive_dh_commands, + read_dh_addon_sequences, +) from debputy.packager_provided_files import ( PackagerProvidedFile, detect_all_packager_provided_files, @@ -71,6 +74,9 @@ def scan_debian_dir( feature_set: PluginProvidedFeatureSet, binary_packages: Mapping[str, BinaryPackage], debian_dir: VirtualPath, + *, + uses_dh_sequencer: bool = True, + dh_sequences: Optional[AbstractSet[str]] = None, ) -> Tuple[List[PackagingFileInfo], List[str], int, Optional[object]]: known_packaging_files = feature_set.known_packaging_files debputy_plugin_metadata = plugin_metadata_for_debputys_own_plugin() @@ -85,18 +91,19 @@ def scan_debian_dir( annotated: List[PackagingFileInfo] = [] seen_paths: Dict[str, PackagingFileInfo] = {} - r = read_dh_addon_sequences(debian_dir) - if r is not None: - bd_sequences, dr_sequences, saw_dh = r - drules_sequences = bd_sequences | dr_sequences - else: - drules_sequences = set() - saw_dh = False + if dh_sequences is None: + r = read_dh_addon_sequences(debian_dir) + if r is not None: + bd_sequences, dr_sequences, uses_dh_sequencer = r + dh_sequences = bd_sequences | dr_sequences + else: + dh_sequences = set() + uses_dh_sequencer = False is_debputy_package = ( - "debputy" in drules_sequences - or "zz-debputy" in drules_sequences - or "zz_debputy" in drules_sequences - or "zz-debputy-rrr" in drules_sequences + "debputy" in dh_sequences + or "zz-debputy" in dh_sequences + or "zz_debputy" in dh_sequences + or "zz-debputy-rrr" in dh_sequences ) dh_compat_level, dh_assistant_exit_code = _extract_dh_compat_level() dh_issues = [] @@ -137,9 +144,9 @@ def scan_debian_dir( binary_packages, debputy_plugin_metadata, dh_pkgfile_docs, - drules_sequences, + dh_sequences, dh_compat_level, - saw_dh, + uses_dh_sequencer, ) else: @@ -278,49 +285,12 @@ def _kpf_install_pattern( return ppkpf.info.get("install_pattern") -def _parse_dh_cmd_list( - cmd_list: Optional[List[Union[Mapping[str, Any], object]]] -) -> Iterable[str]: - if not isinstance(cmd_list, list): - return - - for command in cmd_list: - if not isinstance(command, dict): - continue - command_name = command.get("command") - if isinstance(command_name, str): - yield command_name - - -def _resolve_active_and_inactive_dh_commands( - dh_rules_addons: Iterable[str], -) -> Tuple[FrozenSet[str], FrozenSet[str]]: - cmd = ["dh_assistant", "list-commands", "--output-format=json"] - if dh_rules_addons: - addons = ",".join(dh_rules_addons) - cmd.append(f"--with={addons}") - try: - output = subprocess.check_output( - cmd, - stderr=subprocess.DEVNULL, - ) - except (subprocess.CalledProcessError, FileNotFoundError): - return frozenset(), frozenset() - else: - result = json.loads(output) - active_commands = frozenset(_parse_dh_cmd_list(result.get("commands"))) - disabled_commands = frozenset( - _parse_dh_cmd_list(result.get("disabled-commands")) - ) - return active_commands, disabled_commands - - def _resolve_debhelper_config_files( debian_dir: VirtualPath, binary_packages: Mapping[str, BinaryPackage], debputy_plugin_metadata: DebputyPluginMetadata, dh_ppf_docs: Dict[str, PluginProvidedKnownPackagingFile], - dh_rules_addons: Sequence[str], + dh_rules_addons: AbstractSet[str], dh_compat_level: int, saw_dh: bool, ) -> Tuple[List[PackagerProvidedFile], Optional[object], int]: @@ -349,7 +319,7 @@ def _resolve_debhelper_config_files( "config-files", [] ) issues = result.get("issues") - active_commands, _ = _resolve_active_and_inactive_dh_commands(dh_rules_addons) + dh_commands = resolve_active_and_inactive_dh_commands(dh_rules_addons) for config_file in config_files: if not isinstance(config_file, dict): continue @@ -408,7 +378,7 @@ def _resolve_debhelper_config_files( else: continue is_active = command.get("is-active", True) - if is_active is None and command_name in active_commands: + if is_active is None and command_name in dh_commands.active_commands: is_active = True if not isinstance(is_active, bool): continue @@ -443,7 +413,9 @@ def _resolve_debhelper_config_files( if not has_active_command: dh_cmds = ppkpf.info.get("debhelper_commands") if dh_cmds: - has_active_command = any(c in active_commands for c in dh_cmds) + has_active_command = any( + c in dh_commands.active_commands for c in dh_cmds + ) dh_ppfs[stem] = _fake_PPFClassSpec( debputy_plugin_metadata, stem, |