|
13 | 13 |
|
14 | 14 | import abc
|
15 | 15 | import collections
|
16 |
| -import os |
17 | 16 | from collections.abc import MutableMapping
|
18 | 17 | from typing import Any, cast
|
19 | 18 |
|
20 | 19 | from .changes import ChangesData, FragmentResolver, PluginResolver
|
21 |
| -from .config import ChangelogConfig, PathsConfig, TextFormat |
22 |
| -from .fragment import ChangelogFragment |
| 20 | +from .config import ChangelogConfig, TextFormat |
23 | 21 | from .logger import LOGGER
|
24 |
| -from .plugins import PluginDescription |
25 |
| -from .rst import RstBuilder |
26 | 22 | from .utils import collect_versions
|
27 | 23 |
|
28 | 24 |
|
@@ -72,23 +68,6 @@ def empty(self) -> bool:
|
72 | 68 | and self.has_no_changes()
|
73 | 69 | )
|
74 | 70 |
|
75 |
| - def add_section_content(self, builder: RstBuilder, section_name: str) -> None: |
76 |
| - """ |
77 |
| - Add a section's content of fragments to the changelog. |
78 |
| -
|
79 |
| - This function is DEPRECATED! It will be removed in a future version. |
80 |
| - """ |
81 |
| - if section_name not in self.changes: |
82 |
| - return |
83 |
| - |
84 |
| - content = self.changes[section_name] |
85 |
| - |
86 |
| - if isinstance(content, list): |
87 |
| - for rst in sorted(content): |
88 |
| - builder.add_list_item(rst) |
89 |
| - else: |
90 |
| - builder.add_raw_rst(content) |
91 |
| - |
92 | 71 |
|
93 | 72 | def get_entry_config(
|
94 | 73 | release_entries: MutableMapping[str, ChangelogEntry], entry_version: str
|
@@ -273,334 +252,3 @@ def get_plugin_name(
|
273 | 252 | if fqcn_prefix:
|
274 | 253 | name = "%s.%s" % (fqcn_prefix, name)
|
275 | 254 | return name
|
276 |
| - |
277 |
| - |
278 |
| -class ChangelogGenerator(ChangelogGeneratorBase): |
279 |
| - # antsibull_changelog.rendering.changelog.ChangelogGenerator is a modified |
280 |
| - # copy of this class adjust to the document rendering framework in |
281 |
| - # antsibull_changelog.rendering. To avoid pylint complaining too much, we |
282 |
| - # disable 'duplicate-code' for this class. |
283 |
| - |
284 |
| - # pylint: disable=duplicate-code |
285 |
| - |
286 |
| - """ |
287 |
| - Generate changelog as reStructuredText. |
288 |
| -
|
289 |
| - This class can be both used to create a full changelog, or to append a |
290 |
| - changelog to an existing RstBuilder. This is for example useful to create |
291 |
| - a combined ACD changelog. |
292 |
| -
|
293 |
| - This class is DEPRECATED! It will be removed in a future version. |
294 |
| - """ |
295 |
| - |
296 |
| - def __init__( # pylint: disable=too-many-arguments |
297 |
| - self, |
298 |
| - config: ChangelogConfig, |
299 |
| - changes: ChangesData, |
300 |
| - *, |
301 |
| - # pylint: disable-next=unused-argument |
302 |
| - plugins: list[PluginDescription] | None = None, # DEPRECATED |
303 |
| - # pylint: disable-next=unused-argument |
304 |
| - fragments: list[ChangelogFragment] | None = None, # DEPRECATED |
305 |
| - flatmap: bool = True, |
306 |
| - ): |
307 |
| - """ |
308 |
| - Create a changelog generator. |
309 |
| - """ |
310 |
| - super().__init__(config, changes, flatmap=flatmap) |
311 |
| - |
312 |
| - def append_changelog_entry( |
313 |
| - self, |
314 |
| - builder: RstBuilder, |
315 |
| - changelog_entry: ChangelogEntry, |
316 |
| - start_level: int = 0, |
317 |
| - add_version: bool = False, |
318 |
| - ) -> None: |
319 |
| - """ |
320 |
| - Append changelog entry to a reStructuredText (RST) builder. |
321 |
| -
|
322 |
| - :arg start_level: Level to add to headings in the generated RST |
323 |
| - """ |
324 |
| - if add_version: |
325 |
| - builder.add_section("v%s" % changelog_entry.version, start_level) |
326 |
| - |
327 |
| - for section_name in self.config.sections: |
328 |
| - self._add_section( |
329 |
| - builder, changelog_entry, section_name, start_level=start_level |
330 |
| - ) |
331 |
| - |
332 |
| - fqcn_prefix = self.get_fqcn_prefix() |
333 |
| - self._add_plugins( |
334 |
| - builder, |
335 |
| - changelog_entry.plugins, |
336 |
| - fqcn_prefix=fqcn_prefix, |
337 |
| - start_level=start_level, |
338 |
| - ) |
339 |
| - self._add_modules( |
340 |
| - builder, |
341 |
| - changelog_entry.modules, |
342 |
| - flatmap=self.flatmap, |
343 |
| - fqcn_prefix=fqcn_prefix, |
344 |
| - start_level=start_level, |
345 |
| - ) |
346 |
| - self._add_objects( |
347 |
| - builder, |
348 |
| - changelog_entry.objects, |
349 |
| - fqcn_prefix=fqcn_prefix, |
350 |
| - start_level=start_level, |
351 |
| - ) |
352 |
| - |
353 |
| - def generate_to( # pylint: disable=too-many-arguments |
354 |
| - self, |
355 |
| - builder: RstBuilder, |
356 |
| - start_level: int = 0, |
357 |
| - squash: bool = False, |
358 |
| - after_version: str | None = None, |
359 |
| - until_version: str | None = None, |
360 |
| - only_latest: bool = False, |
361 |
| - ) -> None: |
362 |
| - """ |
363 |
| - Append changelog to a reStructuredText (RST) builder. |
364 |
| -
|
365 |
| - :arg start_level: Level to add to headings in the generated RST |
366 |
| - :arg squash: Squash all releases into one entry |
367 |
| - :arg after_version: If given, only consider versions after this one |
368 |
| - :arg until_version: If given, do not consider versions following this one |
369 |
| - :arg only_latest: If set to ``True``, only generate the latest entry |
370 |
| - """ |
371 |
| - release_entries = self.collect( |
372 |
| - squash=squash, after_version=after_version, until_version=until_version |
373 |
| - ) |
374 |
| - |
375 |
| - for release in release_entries: |
376 |
| - self.append_changelog_entry( |
377 |
| - builder, |
378 |
| - release, |
379 |
| - start_level=start_level, |
380 |
| - add_version=not squash and not only_latest, |
381 |
| - ) |
382 |
| - if only_latest: |
383 |
| - break |
384 |
| - |
385 |
| - def generate(self, only_latest: bool = False) -> str: |
386 |
| - """ |
387 |
| - Generate the changelog as reStructuredText. |
388 |
| - """ |
389 |
| - builder = RstBuilder() |
390 |
| - |
391 |
| - if not only_latest: |
392 |
| - builder.set_title(self.get_title()) |
393 |
| - builder.add_raw_rst(".. contents:: Topics\n") |
394 |
| - |
395 |
| - if self.changes.ancestor and self.config.mention_ancestor: |
396 |
| - builder.add_raw_rst( |
397 |
| - "This changelog describes changes after version {0}.\n".format( |
398 |
| - self.changes.ancestor |
399 |
| - ) |
400 |
| - ) |
401 |
| - else: |
402 |
| - builder.add_raw_rst("") |
403 |
| - |
404 |
| - self.generate_to(builder, 0, only_latest=only_latest) |
405 |
| - |
406 |
| - return builder.generate() |
407 |
| - |
408 |
| - def _add_section( |
409 |
| - self, |
410 |
| - builder: RstBuilder, |
411 |
| - changelog_entry: ChangelogEntry, |
412 |
| - section_name: str, |
413 |
| - start_level: int, |
414 |
| - ) -> None: |
415 |
| - """ |
416 |
| - Add a section of fragments to the changelog. |
417 |
| - """ |
418 |
| - if section_name not in changelog_entry.changes: |
419 |
| - return |
420 |
| - |
421 |
| - section_title = self.config.sections[section_name] |
422 |
| - builder.add_section(section_title, start_level + 1) |
423 |
| - |
424 |
| - changelog_entry.add_section_content(builder, section_name) |
425 |
| - |
426 |
| - builder.add_raw_rst("") |
427 |
| - |
428 |
| - @staticmethod |
429 |
| - def _add_plugins( |
430 |
| - builder: RstBuilder, |
431 |
| - plugins_database: dict[str, list[dict[str, Any]]], |
432 |
| - fqcn_prefix: str | None, |
433 |
| - start_level: int = 0, |
434 |
| - ) -> None: |
435 |
| - """ |
436 |
| - Add new plugins to the changelog. |
437 |
| - """ |
438 |
| - if not plugins_database: |
439 |
| - return |
440 |
| - |
441 |
| - have_section = False |
442 |
| - |
443 |
| - for plugin_type in sorted(plugins_database): |
444 |
| - plugins = plugins_database.get(plugin_type) |
445 |
| - if not plugins: |
446 |
| - continue |
447 |
| - |
448 |
| - if not have_section: |
449 |
| - have_section = True |
450 |
| - builder.add_section("New Plugins", start_level + 1) |
451 |
| - |
452 |
| - builder.add_section(plugin_type.title(), start_level + 2) |
453 |
| - |
454 |
| - ChangelogGenerator.add_plugins(builder, plugins, fqcn_prefix) |
455 |
| - |
456 |
| - builder.add_raw_rst("") |
457 |
| - |
458 |
| - @staticmethod |
459 |
| - def add_plugins( |
460 |
| - builder: RstBuilder, plugins: list[dict[str, Any]], fqcn_prefix: str | None |
461 |
| - ) -> None: |
462 |
| - """ |
463 |
| - Add new plugins of one type to the changelog. |
464 |
| - """ |
465 |
| - for plugin in sorted(plugins, key=lambda plugin: plugin["name"]): |
466 |
| - plugin_name = get_plugin_name(plugin["name"], fqcn_prefix=fqcn_prefix) |
467 |
| - builder.add_raw_rst("- %s - %s" % (plugin_name, plugin["description"])) |
468 |
| - |
469 |
| - @staticmethod |
470 |
| - def _add_modules( |
471 |
| - builder: RstBuilder, |
472 |
| - modules: list[dict[str, Any]], |
473 |
| - flatmap: bool, |
474 |
| - fqcn_prefix: str | None, |
475 |
| - start_level: int = 0, |
476 |
| - ) -> None: |
477 |
| - """ |
478 |
| - Add new modules to the changelog. |
479 |
| - """ |
480 |
| - if not modules: |
481 |
| - return |
482 |
| - |
483 |
| - builder.add_section("New Modules", start_level + 1) |
484 |
| - ChangelogGenerator.add_modules( |
485 |
| - builder, modules, flatmap, fqcn_prefix, start_level + 2 |
486 |
| - ) |
487 |
| - |
488 |
| - @staticmethod |
489 |
| - def add_modules( |
490 |
| - builder: RstBuilder, |
491 |
| - modules: list[dict[str, Any]], |
492 |
| - flatmap: bool, |
493 |
| - fqcn_prefix: str | None, |
494 |
| - level: int, |
495 |
| - ) -> None: |
496 |
| - """ |
497 |
| - Add new modules to the changelog. |
498 |
| - """ |
499 |
| - modules_by_namespace = collections.defaultdict(list) |
500 |
| - for module in sorted(modules, key=lambda module: module["name"]): |
501 |
| - modules_by_namespace[module["namespace"]].append(module) |
502 |
| - |
503 |
| - previous_section = None |
504 |
| - for namespace in sorted(modules_by_namespace): |
505 |
| - parts = namespace.split(".") |
506 |
| - |
507 |
| - section = parts.pop(0).replace("_", " ").title() |
508 |
| - |
509 |
| - if section != previous_section and section: |
510 |
| - builder.add_section(section, level) |
511 |
| - |
512 |
| - previous_section = section |
513 |
| - |
514 |
| - subsection = ".".join(parts) |
515 |
| - |
516 |
| - if subsection: |
517 |
| - builder.add_section(subsection, level + 1) |
518 |
| - |
519 |
| - for module in modules_by_namespace[namespace]: |
520 |
| - module_name = get_plugin_name( |
521 |
| - module["name"], |
522 |
| - fqcn_prefix=fqcn_prefix, |
523 |
| - namespace=namespace, |
524 |
| - flatmap=flatmap, |
525 |
| - ) |
526 |
| - builder.add_raw_rst("- %s - %s" % (module_name, module["description"])) |
527 |
| - |
528 |
| - builder.add_raw_rst("") |
529 |
| - |
530 |
| - @staticmethod |
531 |
| - def _add_objects( |
532 |
| - builder: RstBuilder, |
533 |
| - objects_database: dict[str, list[dict[str, Any]]], |
534 |
| - fqcn_prefix: str | None, |
535 |
| - start_level: int = 0, |
536 |
| - ) -> None: |
537 |
| - """ |
538 |
| - Add new objects to the changelog. |
539 |
| - """ |
540 |
| - if not objects_database: |
541 |
| - return |
542 |
| - |
543 |
| - for object_type in sorted(objects_database): |
544 |
| - objects = objects_database.get(object_type) |
545 |
| - if not objects: |
546 |
| - continue |
547 |
| - |
548 |
| - builder.add_section("New " + object_type.title() + "s", start_level + 1) |
549 |
| - |
550 |
| - ChangelogGenerator.add_objects(builder, objects, fqcn_prefix) |
551 |
| - |
552 |
| - builder.add_raw_rst("") |
553 |
| - |
554 |
| - @staticmethod |
555 |
| - def add_objects( |
556 |
| - builder: RstBuilder, objects: list[dict[str, Any]], fqcn_prefix: str | None |
557 |
| - ) -> None: |
558 |
| - """ |
559 |
| - Add new objects of one type to the changelog. |
560 |
| - """ |
561 |
| - for ansible_object in sorted( |
562 |
| - objects, key=lambda ansible_object: ansible_object["name"] |
563 |
| - ): |
564 |
| - object_name = get_plugin_name( |
565 |
| - ansible_object["name"], fqcn_prefix=fqcn_prefix |
566 |
| - ) |
567 |
| - builder.add_raw_rst( |
568 |
| - "- %s - %s" % (object_name, ansible_object["description"]) |
569 |
| - ) |
570 |
| - |
571 |
| - |
572 |
| -def generate_changelog( # pylint: disable=too-many-arguments |
573 |
| - paths: PathsConfig, |
574 |
| - config: ChangelogConfig, |
575 |
| - changes: ChangesData, |
576 |
| - *, |
577 |
| - flatmap: bool = True, |
578 |
| - changelog_path: str | None = None, |
579 |
| - only_latest: bool = False, |
580 |
| -): |
581 |
| - """ |
582 |
| - Generate the changelog as reStructuredText. |
583 |
| -
|
584 |
| - This function is DEPRECATED! It will be removed in a future version. |
585 |
| -
|
586 |
| - :arg flatmap: Whether the collection uses flatmapping or not |
587 |
| - :arg changelog_path: Write the output to this path instead of the default path. |
588 |
| - :arg only_latest: Only write the last changelog entry without any preamble |
589 |
| - """ |
590 |
| - if changelog_path is None: |
591 |
| - major_minor_version = ".".join( |
592 |
| - changes.latest_version.split(".")[: config.changelog_filename_version_depth] |
593 |
| - ) |
594 |
| - if "%s" in config.changelog_filename_template: |
595 |
| - changelog_filename = config.changelog_filename_template % ( |
596 |
| - major_minor_version, |
597 |
| - ) |
598 |
| - else: |
599 |
| - changelog_filename = config.changelog_filename_template |
600 |
| - changelog_path = os.path.join(paths.changelog_dir, changelog_filename) |
601 |
| - |
602 |
| - generator = ChangelogGenerator(config, changes, flatmap=flatmap) |
603 |
| - rst = generator.generate(only_latest=only_latest) |
604 |
| - |
605 |
| - with open(changelog_path, "wb") as changelog_fd: |
606 |
| - changelog_fd.write(rst.encode("utf-8")) |
0 commit comments