File: config.py

package info (click to toggle)
python-telegram-bot 22.3-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,060 kB
  • sloc: python: 90,298; makefile: 176; sh: 4
file content (105 lines) | stat: -rw-r--r-- 4,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# noqa: INP001
# pylint: disable=import-error
"""Configuration for the chango changelog tool"""

import re
from collections.abc import Collection
from pathlib import Path
from typing import Optional

from chango import Version
from chango.concrete import DirectoryChanGo, DirectoryVersionScanner, HeaderVersionHistory
from chango.concrete.sections import GitHubSectionChangeNote, Section, SectionVersionNote

version_scanner = DirectoryVersionScanner(base_directory=".", unreleased_directory="unreleased")


class ChangoSectionChangeNote(
    GitHubSectionChangeNote.with_sections(  # type: ignore[misc]
        [
            Section(uid="highlights", title="Highlights", sort_order=0),
            Section(uid="breaking", title="Breaking Changes", sort_order=1),
            Section(uid="security", title="Security Changes", sort_order=2),
            Section(uid="deprecations", title="Deprecations", sort_order=3),
            Section(uid="features", title="New Features", sort_order=4),
            Section(uid="bugfixes", title="Bug Fixes", sort_order=5),
            Section(uid="dependencies", title="Dependencies", sort_order=6),
            Section(uid="other", title="Other Changes", sort_order=7),
            Section(uid="documentation", title="Documentation", sort_order=8),
            Section(uid="internal", title="Internal Changes", sort_order=9),
        ]
    )
):
    """Custom change note type for PTB. Mainly overrides get_sections to map labels to sections"""

    OWNER = "python-telegram-bot"
    REPOSITORY = "python-telegram-bot"

    @classmethod
    def get_sections(
        cls,
        labels: Collection[str],
        issue_types: Optional[Collection[str]],
    ) -> set[str]:
        """Override get_sections to have customized auto-detection of relevant sections based on
        the pull request and linked issues. Certainly not perfect in all cases, but should be a
        good start for most PRs.
        """
        combined_labels = set(labels) | (set(issue_types or []))

        mapping = {
            "๐Ÿ› bug": "bugfixes",
            "๐Ÿ’ก feature": "features",
            "๐Ÿงน chore": "internal",
            "โš™๏ธ bot-api": "features",
            "โš™๏ธ documentation": "documentation",
            "โš™๏ธ tests": "internal",
            "โš™๏ธ ci-cd": "internal",
            "โš™๏ธ security": "security",
            "โš™๏ธ examples": "documentation",
            "โš™๏ธ type-hinting": "other",
            "๐Ÿ›  refactor": "internal",
            "๐Ÿ›  breaking": "breaking",
            "โš™๏ธ dependencies": "dependencies",
            "๐Ÿ”— github-actions": "internal",
            "๐Ÿ›  code-quality": "internal",
        }

        # we want to return *all* from the mapping that are in the combined_labels
        # removing superfluous sections from the fragment is a tad easier than adding them
        found = {section for label, section in mapping.items() if label in combined_labels}

        # if we have not found any sections, we default to "other"
        return found or {"other"}


class CustomChango(DirectoryChanGo):
    """Custom ChanGo class for overriding release"""

    def release(self, version: Version) -> bool:
        """replace "14.5" with version.uid except in the contrib guide
        then call super
        """
        root = Path(__file__).parent.parent / "src"
        python_files = root.rglob("*.py")
        pattern = re.compile(r"NEXT\.VERSION")
        excluded_paths = {root / "docs/source/contribute.rst"}
        for file_path in python_files:
            if str(file_path) in excluded_paths:
                continue

            content = file_path.read_text(encoding="utf-8")
            modified = pattern.sub(version.uid, content)

            if content != modified:
                file_path.write_text(modified, encoding="utf-8")

        return super().release(version)


chango_instance = CustomChango(
    change_note_type=ChangoSectionChangeNote,
    version_note_type=SectionVersionNote,
    version_history_type=HeaderVersionHistory,
    scanner=version_scanner,
)