Coverage for src/debputy/analysis/debian_dir.py: 30%
344 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-28 20:14 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-28 20:14 +0000
1import dataclasses
2import json
3import os
4import stat
5import subprocess
6from typing import (
7 AbstractSet,
8 Any,
9 TypedDict,
10 NotRequired,
11 Literal,
12)
13from collections.abc import Mapping, Iterable, Sequence, Iterator, Container
15from debputy.analysis import REFERENCE_DATA_TABLE
16from debputy.analysis.analysis_util import flatten_ppfs
17from debputy.dh.dh_assistant import (
18 resolve_active_and_inactive_dh_commands,
19 read_dh_addon_sequences,
20 extract_dh_compat_level,
21)
22from debputy.integration_detection import determine_debputy_integration_mode
23from debputy.packager_provided_files import (
24 PackagerProvidedFile,
25 detect_all_packager_provided_files,
26)
27from debputy.packages import BinaryPackage, SourcePackage
28from debputy.plugin.api import (
29 VirtualPath,
30 packager_provided_file_reference_documentation,
31)
32from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
33from debputy.plugin.api.impl import plugin_metadata_for_debputys_own_plugin
34from debputy.plugin.api.impl_types import (
35 PluginProvidedKnownPackagingFile,
36 DebputyPluginMetadata,
37 KnownPackagingFileInfo,
38 DHCompatibilityBasedRule,
39 PackagerProvidedFileClassSpec,
40 expand_known_packaging_config_features,
41)
42from debputy.plugin.api.spec import DebputyIntegrationMode
43from debputy.util import (
44 assume_not_none,
45 escape_shell,
46 _trace_log,
47 _is_trace_log_enabled,
48 render_command,
49 PackageTypeSelector,
50)
52PackagingFileInfo = TypedDict(
53 "PackagingFileInfo",
54 {
55 "path": str,
56 "binary-package": NotRequired[str],
57 "install-path": NotRequired[str],
58 "install-pattern": NotRequired[str],
59 "file-categories": NotRequired[list[str]],
60 "config-features": NotRequired[list[str]],
61 "pkgfile-is-active-in-build": NotRequired[bool],
62 "pkgfile-stem": NotRequired[str],
63 "pkgfile-explicit-package-name": NotRequired[bool],
64 "pkgfile-name-segment": NotRequired[str],
65 "pkgfile-architecture-restriction": NotRequired[str],
66 "likely-typo-of": NotRequired[str],
67 "likely-generated-from": NotRequired[list[str]],
68 "related-tools": NotRequired[list[str]],
69 "documentation-uris": NotRequired[list[str]],
70 "debputy-cmd-templates": NotRequired[list[str]],
71 "generates": NotRequired[str],
72 "generated-from": NotRequired[str],
73 },
74)
75PackagingFileInfoStringListFieldKey = Literal[
76 "config-features",
77 "debputy-cmd-templates",
78 "documentation-uris",
79 "file-categories",
80]
83def _perl_json_bool(base: Any | None) -> Any | None:
84 if base is None: 84 ↛ 85line 84 didn't jump to line 85 because the condition on line 84 was never true
85 return None
87 if isinstance(base, bool): 87 ↛ 94line 87 didn't jump to line 94 because the condition on line 87 was always true
88 return base
90 # Account for different ways that Perl will or could return a JSON bool,
91 # when not using `JSON::PP::{true,false}`.
92 #
93 # https://salsa.debian.org/debian/debputy/-/issues/119#note_627057
94 if isinstance(base, int):
95 if base == 0:
96 return False
97 return True if base == 1 else base
98 if isinstance(base, str):
99 return False if base == "" else base
100 return base
103def scan_debian_dir(
104 feature_set: PluginProvidedFeatureSet,
105 source_package: SourcePackage,
106 binary_packages: Mapping[str, BinaryPackage],
107 debian_dir: VirtualPath,
108 *,
109 uses_dh_sequencer: bool = True,
110 dh_sequences: AbstractSet[str] | None = None,
111) -> tuple[list[PackagingFileInfo], list[str], int, object | None]:
112 known_packaging_files = feature_set.known_packaging_files
113 debputy_plugin_metadata = plugin_metadata_for_debputys_own_plugin()
114 reference_data_set_names = [
115 "config-features",
116 "file-categories",
117 ]
118 for n in reference_data_set_names:
119 assert n in REFERENCE_DATA_TABLE
121 annotated: list[PackagingFileInfo] = []
122 seen_paths: dict[str, PackagingFileInfo] = {}
124 if dh_sequences is None:
125 r = read_dh_addon_sequences(debian_dir)
126 if r is not None:
127 bd_sequences, dr_sequences, uses_dh_sequencer = r
128 dh_sequences = bd_sequences | dr_sequences
129 else:
130 dh_sequences = set()
131 uses_dh_sequencer = False
132 debputy_integration_mode = determine_debputy_integration_mode(
133 source_package.fields,
134 dh_sequences,
135 )
136 is_debputy_package = debputy_integration_mode is not None
137 dh_compat_level, dh_assistant_exit_code = extract_dh_compat_level()
138 dh_issues: object | None = []
140 static_packaging_files = {
141 kpf.detection_value: kpf
142 for kpf in known_packaging_files.values()
143 if kpf.detection_method == "path"
144 }
145 dh_pkgfile_docs = {
146 kpf.detection_value: kpf
147 for kpf in known_packaging_files.values()
148 if kpf.detection_method == "dh.pkgfile"
149 }
150 if is_debputy_package:
151 all_debputy_ppfs = list(
152 flatten_ppfs(
153 detect_all_packager_provided_files(
154 feature_set,
155 debian_dir,
156 binary_packages,
157 allow_fuzzy_matches=True,
158 detect_typos=True,
159 ignore_paths=static_packaging_files,
160 )
161 )
162 )
163 else:
164 all_debputy_ppfs = []
166 if dh_compat_level is not None:
167 (
168 all_dh_ppfs,
169 _,
170 dh_issues,
171 dh_assistant_exit_code,
172 ) = resolve_debhelper_config_files(
173 debian_dir,
174 binary_packages,
175 debputy_plugin_metadata,
176 feature_set,
177 dh_sequences,
178 dh_compat_level,
179 uses_dh_sequencer,
180 debputy_integration_mode=debputy_integration_mode,
181 ignore_paths=static_packaging_files,
182 )
184 else:
185 all_dh_ppfs = []
187 for ppf in all_debputy_ppfs:
188 key = ppf.path.path
189 ref_doc = ppf.definition.reference_documentation
190 documentation_uris = (
191 ref_doc.format_documentation_uris if ref_doc is not None else None
192 )
193 details: PackagingFileInfo = {
194 "path": key,
195 "binary-package": ppf.package_name,
196 "pkgfile-stem": ppf.definition.stem,
197 "pkgfile-explicit-package-name": ppf.uses_explicit_package_name,
198 "pkgfile-is-active-in-build": ppf.definition.has_active_command,
199 "debputy-cmd-templates": [
200 f"debputy plugin show p-p-f {ppf.definition.stem}",
201 ],
202 }
203 if ppf.fuzzy_match and key.endswith(".in"):
204 _merge_list(details, "file-categories", ["generic-template"])
205 details["generates"] = key[:-3]
206 elif assume_not_none(ppf.path.parent_dir).get(ppf.path.name + ".in"):
207 _merge_list(details, "file-categories", ["generated"])
208 details["generated-from"] = key + ".in"
209 name_segment = ppf.name_segment
210 arch_restriction = ppf.architecture_restriction
211 if name_segment is not None:
212 details["pkgfile-name-segment"] = name_segment
213 if arch_restriction:
214 details["pkgfile-architecture-restriction"] = arch_restriction
215 seen_paths[key] = details
216 annotated.append(details)
217 static_details = static_packaging_files.get(key)
218 if static_details is not None:
219 # debhelper compat rules does not apply to debputy files
220 _add_known_packaging_data(details, static_details, None)
221 if documentation_uris:
222 details["documentation-uris"] = list(documentation_uris)
224 _merge_ppfs(annotated, seen_paths, all_dh_ppfs, dh_pkgfile_docs, dh_compat_level)
226 for virtual_path in _scan_debian_dir(debian_dir):
227 key = virtual_path.path
228 if key in seen_paths or _skip_path(virtual_path):
229 continue
231 static_match = static_packaging_files.get(virtual_path.path)
232 if static_match is not None:
233 details = {
234 "path": key,
235 }
236 annotated.append(details)
237 if assume_not_none(virtual_path.parent_dir).get(virtual_path.name + ".in"):
238 details["generated-from"] = key + ".in"
239 _merge_list(details, "file-categories", ["generated"])
240 _add_known_packaging_data(details, static_match, dh_compat_level)
242 return annotated, reference_data_set_names, dh_assistant_exit_code, dh_issues
245def _skip_path(virtual_path: VirtualPath) -> bool:
246 if virtual_path.is_symlink:
247 try:
248 st = os.stat(virtual_path.fs_path)
249 except FileNotFoundError:
250 return True
251 else:
252 if not stat.S_ISREG(st.st_mode):
253 return True
254 elif not virtual_path.is_file:
255 return True
256 return False
259def _fake_PPFClassSpec(
260 debputy_plugin_metadata: DebputyPluginMetadata,
261 stem: str,
262 doc_uris: Sequence[str] | None,
263 install_pattern: str | None,
264 *,
265 default_priority: int | None = None,
266 packageless_is_fallback_for_all_packages: bool = False,
267 package_types: PackageTypeSelector = PackageTypeSelector.ALL,
268 post_formatting_rewrite: str | None = None,
269 bug_950723: bool = False,
270 has_active_command: bool = False,
271) -> PackagerProvidedFileClassSpec:
272 if install_pattern is None: 272 ↛ 274line 272 didn't jump to line 274 because the condition on line 272 was always true
273 install_pattern = "not-a-real-ppf"
274 if post_formatting_rewrite is not None: 274 ↛ 275line 274 didn't jump to line 275 because the condition on line 274 was never true
275 formatting_hook = _POST_FORMATTING_REWRITE[post_formatting_rewrite]
276 else:
277 formatting_hook = None
278 return PackagerProvidedFileClassSpec(
279 debputy_plugin_metadata,
280 stem,
281 install_pattern,
282 allow_architecture_segment=True,
283 allow_name_segment=True,
284 default_priority=default_priority,
285 default_mode=0o644,
286 post_formatting_rewrite=formatting_hook,
287 packageless_is_fallback_for_all_packages=packageless_is_fallback_for_all_packages,
288 package_types=package_types,
289 reservation_only=False,
290 formatting_callback=None,
291 bug_950723=bug_950723,
292 has_active_command=has_active_command,
293 reference_documentation=packager_provided_file_reference_documentation(
294 format_documentation_uris=doc_uris,
295 ),
296 )
299def _relevant_dh_compat_rules(
300 compat_level: int | None,
301 info: KnownPackagingFileInfo,
302) -> Iterable[DHCompatibilityBasedRule]:
303 if compat_level is None:
304 return
305 dh_compat_rules = info.get("dh_compat_rules")
306 if not dh_compat_rules:
307 return
308 for dh_compat_rule in dh_compat_rules:
309 rule_compat_level = dh_compat_rule.get("starting_with_compat_level")
310 if rule_compat_level is not None and compat_level < rule_compat_level:
311 continue
312 yield dh_compat_rule
315def _kpf_install_pattern(
316 compat_level: int | None,
317 ppkpf: PluginProvidedKnownPackagingFile,
318) -> str | None:
319 for compat_rule in _relevant_dh_compat_rules(compat_level, ppkpf.info):
320 install_pattern = compat_rule.get("install_pattern")
321 if install_pattern is not None:
322 return install_pattern
323 return ppkpf.info.get("install_pattern")
326def resolve_debhelper_config_files(
327 debian_dir: VirtualPath,
328 binary_packages: Mapping[str, BinaryPackage],
329 debputy_plugin_metadata: DebputyPluginMetadata,
330 plugin_feature_set: PluginProvidedFeatureSet,
331 dh_rules_addons: AbstractSet[str],
332 dh_compat_level: int | None,
333 saw_dh: bool,
334 ignore_paths: Container[str] = frozenset(),
335 *,
336 debputy_integration_mode: DebputyIntegrationMode | None = None,
337 cwd: str | None = None,
338 match_arch: frozenset[str] | set[str] | None = None,
339 match_arch_os: frozenset[str] | set[str] | None = None,
340 multi_match: bool = False,
341) -> tuple[list[PackagerProvidedFile], list[str], object | None, int]:
343 dh_ppf_docs = {
344 kpf.detection_value: kpf
345 for kpf in plugin_feature_set.known_packaging_files.values()
346 if kpf.detection_method == "dh.pkgfile"
347 }
349 dh_ppfs = {}
350 commands, exit_code = _relevant_dh_commands(dh_rules_addons, cwd=cwd)
352 cmd = ["dh_assistant", "list-guessed-dh-config-files"]
353 if dh_rules_addons:
354 addons = ",".join(dh_rules_addons)
355 cmd.append(f"--with={addons}")
356 try:
357 output = subprocess.check_output(
358 cmd,
359 stderr=subprocess.DEVNULL,
360 cwd=cwd,
361 encoding="utf-8",
362 )
363 except (subprocess.CalledProcessError, FileNotFoundError) as e:
364 config_files = []
365 issues = None
366 missing_introspection: list[str] = []
367 if isinstance(e, subprocess.CalledProcessError):
368 exit_code = e.returncode
369 else:
370 exit_code = 127
371 if _is_trace_log_enabled():
372 _trace_log(
373 f"Command {render_command(*cmd, cwd=cwd)} failed with {exit_code} ({cwd=})"
374 )
375 else:
376 result = json.loads(output)
377 config_files = result.get("config-files", [])
378 missing_introspection = result.get("commands-not-introspectable", [])
379 issues = result.get("issues")
380 if _is_trace_log_enabled(): 380 ↛ 381line 380 didn't jump to line 381 because the condition on line 380 was never true
381 _trace_log(
382 f"Command {render_command(*cmd, cwd=cwd)} returned successfully: {output}"
383 )
384 dh_commands = resolve_active_and_inactive_dh_commands(dh_rules_addons)
385 for config_file in config_files:
386 if not isinstance(config_file, dict): 386 ↛ 387line 386 didn't jump to line 387 because the condition on line 386 was never true
387 continue
388 if config_file.get("file-type") != "pkgfile":
389 continue
390 stem = config_file.get("pkgfile")
391 if stem is None: 391 ↛ 392line 391 didn't jump to line 392 because the condition on line 391 was never true
392 continue
393 internal = config_file.get("internal")
394 if isinstance(internal, dict):
395 bug_950723 = internal.get("bug#950723", False) is True
396 else:
397 bug_950723 = False
398 commands = config_file.get("commands") or []
399 documentation_uris = []
400 related_tools = []
401 seen_commands = set()
402 seen_docs = set()
403 ppkpf = dh_ppf_docs.get(stem)
405 if ppkpf: 405 ↛ 406line 405 didn't jump to line 406 because the condition on line 405 was never true
406 dh_cmds = ppkpf.info.get("debhelper_commands")
407 doc_uris = ppkpf.info.get("documentation_uris")
408 default_priority = ppkpf.info.get("default_priority")
409 if doc_uris is not None:
410 seen_docs.update(doc_uris)
411 documentation_uris.extend(doc_uris)
412 if dh_cmds is not None:
413 seen_commands.update(dh_cmds)
414 related_tools.extend(dh_cmds)
415 install_pattern = _kpf_install_pattern(dh_compat_level, ppkpf)
416 post_formatting_rewrite = ppkpf.info.get("post_formatting_rewrite")
417 packageless_is_fallback_for_all_packages = ppkpf.info.get(
418 "packageless_is_fallback_for_all_packages",
419 False,
420 )
421 # If it is a debhelper PPF, then `has_active_command` is false by default.
422 has_active_command = ppkpf.info.get("has_active_command", False)
423 else:
424 install_pattern = None
425 default_priority = None
426 post_formatting_rewrite = None
427 packageless_is_fallback_for_all_packages = False
428 has_active_command = False
429 for command in commands:
430 if isinstance(command, dict): 430 ↛ 429line 430 didn't jump to line 429 because the condition on line 430 was always true
431 command_name = command.get("command")
432 if isinstance(command_name, str) and command_name: 432 ↛ 441line 432 didn't jump to line 441 because the condition on line 432 was always true
433 if command_name not in seen_commands: 433 ↛ 436line 433 didn't jump to line 436 because the condition on line 433 was always true
434 related_tools.append(command_name)
435 seen_commands.add(command_name)
436 manpage = f"man:{command_name}(1)"
437 if manpage not in seen_docs: 437 ↛ 442line 437 didn't jump to line 442 because the condition on line 437 was always true
438 documentation_uris.append(manpage)
439 seen_docs.add(manpage)
440 else:
441 continue
442 is_active = _perl_json_bool(command.get("is-active", True))
443 if is_active is None and command_name in dh_commands.active_commands: 443 ↛ 444line 443 didn't jump to line 444 because the condition on line 443 was never true
444 is_active = True
445 if not isinstance(is_active, bool): 445 ↛ 446line 445 didn't jump to line 446 because the condition on line 445 was never true
446 continue
447 if is_active:
448 has_active_command = True
450 if debputy_integration_mode == "full": 450 ↛ 452line 450 didn't jump to line 452 because the condition on line 450 was never true
451 # dh commands are never active in full integration mode.
452 has_active_command = False
453 elif not saw_dh: 453 ↛ 457line 453 didn't jump to line 457 because the condition on line 453 was always true
454 # If we did not see `dh`, we assume classic `debhelper` where we have no way of knowing
455 # which commands are active.
456 has_active_command = True
457 dh_ppfs[stem] = _fake_PPFClassSpec(
458 debputy_plugin_metadata,
459 stem,
460 documentation_uris,
461 install_pattern,
462 default_priority=default_priority,
463 post_formatting_rewrite=post_formatting_rewrite,
464 packageless_is_fallback_for_all_packages=packageless_is_fallback_for_all_packages,
465 bug_950723=bug_950723,
466 has_active_command=has_active_command,
467 )
468 for ppkpf in dh_ppf_docs.values(): 468 ↛ 469line 468 didn't jump to line 469 because the loop on line 468 never started
469 stem = ppkpf.detection_value
470 if stem in dh_ppfs:
471 continue
473 default_priority = ppkpf.info.get("default_priority")
474 install_pattern = _kpf_install_pattern(dh_compat_level, ppkpf)
475 post_formatting_rewrite = ppkpf.info.get("post_formatting_rewrite")
476 packageless_is_fallback_for_all_packages = ppkpf.info.get(
477 "packageless_is_fallback_for_all_packages",
478 False,
479 )
480 has_active_command = (
481 ppkpf.info.get("has_active_command", False) if saw_dh else False
482 )
483 if not has_active_command:
484 dh_cmds = ppkpf.info.get("debhelper_commands")
485 if dh_cmds:
486 has_active_command = any(
487 c in dh_commands.active_commands for c in dh_cmds
488 )
489 dh_ppfs[stem] = _fake_PPFClassSpec(
490 debputy_plugin_metadata,
491 stem,
492 ppkpf.info.get("documentation_uris"),
493 install_pattern,
494 default_priority=default_priority,
495 post_formatting_rewrite=post_formatting_rewrite,
496 packageless_is_fallback_for_all_packages=packageless_is_fallback_for_all_packages,
497 has_active_command=has_active_command,
498 )
499 dh_ppf_feature_set = _fake_plugin_feature_set(plugin_feature_set, dh_ppfs)
500 all_dh_ppfs = list(
501 flatten_ppfs(
502 detect_all_packager_provided_files(
503 dh_ppf_feature_set,
504 debian_dir,
505 binary_packages,
506 allow_fuzzy_matches=True,
507 detect_typos=True,
508 ignore_paths=ignore_paths,
509 match_arch=match_arch,
510 match_arch_os=match_arch_os,
511 multi_match=multi_match,
512 )
513 )
514 )
515 return all_dh_ppfs, missing_introspection, issues, exit_code
518def _fake_plugin_feature_set(
519 plugin_feature_set: PluginProvidedFeatureSet,
520 fake_defs: dict[str, PackagerProvidedFileClassSpec],
521) -> PluginProvidedFeatureSet:
522 return dataclasses.replace(plugin_feature_set, packager_provided_files=fake_defs)
525def _merge_list(
526 existing_table: PackagingFileInfo,
527 key: PackagingFileInfoStringListFieldKey,
528 new_data: Sequence[str] | None,
529) -> None:
530 if not new_data:
531 return
532 existing_values = existing_table.get(key, [])
533 seen = set(existing_values)
534 existing_values.extend(x for x in new_data if x not in seen)
535 existing_table[key] = existing_values
538def _merge_ppfs(
539 identified: list[PackagingFileInfo],
540 seen_paths: dict[str, PackagingFileInfo],
541 ppfs: list[PackagerProvidedFile],
542 context: Mapping[str, PluginProvidedKnownPackagingFile],
543 dh_compat_level: int | None,
544) -> None:
545 for ppf in ppfs:
546 key = ppf.path.path
547 ref_doc = ppf.definition.reference_documentation
548 documentation_uris = (
549 ref_doc.format_documentation_uris if ref_doc is not None else None
550 )
551 if not ppf.definition.installed_as_format.startswith("not-a-real-ppf"):
552 try:
553 parts = ppf.compute_dest()
554 except RuntimeError:
555 dest = None
556 else:
557 dest = "/".join(parts).lstrip(".")
558 else:
559 dest = None
560 orig_details = seen_paths.get(key)
561 if orig_details is None:
562 details: PackagingFileInfo = {
563 "path": key,
564 "pkgfile-stem": ppf.definition.stem,
565 "pkgfile-is-active-in-build": ppf.definition.has_active_command,
566 "pkgfile-explicit-package-name": ppf.uses_explicit_package_name,
567 "binary-package": ppf.package_name,
568 }
569 if ppf.expected_path is not None:
570 details["likely-typo-of"] = ppf.expected_path
571 identified.append(details)
572 else:
573 details = orig_details
574 # We do not merge the "is typo" field; if the original
575 if "pkgfile-stem" not in details:
576 details["pkgfile-stem"] = ppf.definition.stem
577 if "pkgfile-explicit-package-name" not in details:
578 details["pkgfile-explicit-package-name"] = (
579 ppf.definition.has_active_command
580 )
581 if "binary-package" not in details:
582 details["binary-package"] = ppf.package_name
583 if ppf.definition.has_active_command and details.get(
584 "pkgfile-is-active-in-build", False
585 ):
586 details["pkgfile-is-active-in-build"] = True
587 if ppf.expected_path is None and "likely-typo-of" in details:
588 del details["likely-typo-of"]
590 name_segment = ppf.name_segment
591 arch_restriction = ppf.architecture_restriction
592 if name_segment is not None and "pkgfile-name-segment" not in details:
593 details["pkgfile-name-segment"] = name_segment
594 if (
595 arch_restriction is not None
596 and "pkgfile-architecture-restriction" not in details
597 ):
598 details["pkgfile-architecture-restriction"] = arch_restriction
599 if ppf.fuzzy_match and key.endswith(".in"):
600 _merge_list(details, "file-categories", ["generic-template"])
601 details["generates"] = key[:-3]
602 elif assume_not_none(ppf.path.parent_dir).get(ppf.path.name + ".in"):
603 _merge_list(details, "file-categories", ["generated"])
604 details["generated-from"] = key + ".in"
605 if dest is not None and "install-path" not in details:
606 details["install-path"] = dest
608 extra_details = context.get(ppf.definition.stem)
609 if extra_details is not None:
610 _add_known_packaging_data(details, extra_details, dh_compat_level)
612 _merge_list(details, "documentation-uris", documentation_uris)
615def _relevant_dh_commands(
616 dh_rules_addons: Iterable[str],
617 cwd: str | None = None,
618) -> tuple[list[str], int]:
619 cmd = ["dh_assistant", "list-commands", "--output-format=json"]
620 if dh_rules_addons:
621 addons = ",".join(dh_rules_addons)
622 cmd.append(f"--with={addons}")
623 try:
624 output = subprocess.check_output(
625 cmd,
626 stderr=subprocess.DEVNULL,
627 cwd=cwd,
628 encoding="utf-8",
629 )
630 except (FileNotFoundError, subprocess.CalledProcessError) as e:
631 exit_code = 127
632 if isinstance(e, subprocess.CalledProcessError):
633 exit_code = e.returncode
634 if _is_trace_log_enabled():
635 _trace_log(
636 f"Command {render_command(*cmd, cwd=cwd)} failed with {exit_code} ({cwd=})"
637 )
638 return [], exit_code
639 else:
640 data = json.loads(output)
641 commands_json = data.get("commands")
642 commands = []
643 if _is_trace_log_enabled(): 643 ↛ 644line 643 didn't jump to line 644 because the condition on line 643 was never true
644 _trace_log(
645 f"Command {render_command(*cmd, cwd=cwd)} returned successfully: {output}"
646 )
647 for command in commands_json:
648 if isinstance(command, dict): 648 ↛ 647line 648 didn't jump to line 647 because the condition on line 648 was always true
649 command_name = command.get("command")
650 if isinstance(command_name, str) and command_name: 650 ↛ 647line 650 didn't jump to line 647 because the condition on line 650 was always true
651 commands.append(command_name)
652 return commands, 0
655def _add_known_packaging_data(
656 details: PackagingFileInfo,
657 plugin_data: PluginProvidedKnownPackagingFile,
658 dh_compat_level: int | None,
659):
660 install_pattern = _kpf_install_pattern(
661 dh_compat_level,
662 plugin_data,
663 )
664 config_features = plugin_data.info.get("config_features")
665 if config_features:
666 config_features = expand_known_packaging_config_features(
667 dh_compat_level or 0,
668 config_features,
669 )
670 _merge_list(details, "config-features", config_features)
672 if dh_compat_level is not None:
673 extra_config_features = []
674 for dh_compat_rule in _relevant_dh_compat_rules(
675 dh_compat_level, plugin_data.info
676 ):
677 cf = dh_compat_rule.get("add_config_features")
678 if cf:
679 extra_config_features.extend(cf)
680 if extra_config_features:
681 extra_config_features = expand_known_packaging_config_features(
682 dh_compat_level,
683 extra_config_features,
684 )
685 _merge_list(details, "config-features", extra_config_features)
686 if "install-pattern" not in details and install_pattern is not None:
687 details["install-pattern"] = install_pattern
689 _merge_list(details, "file-categories", plugin_data.info.get("file_categories"))
690 _merge_list(
691 details, "documentation-uris", plugin_data.info.get("documentation_uris")
692 )
693 _merge_list(
694 details,
695 "debputy-cmd-templates",
696 [escape_shell(*c) for c in plugin_data.info.get("debputy_cmd_templates", [])],
697 )
700def _scan_debian_dir(debian_dir: VirtualPath) -> Iterator[VirtualPath]:
701 for p in debian_dir.iterdir():
702 yield p
703 if p.is_dir and p.path in ("debian/source", "debian/tests"):
704 yield from p.iterdir()
707_POST_FORMATTING_REWRITE = {
708 "period-to-underscore": lambda n: n.replace(".", "_"),
709}