Skip to content

changelog utils

changelog_files

changelog_files(changelog: str) -> list[Path]

Get the ordered list of SQL files in the changelog directory. This is not recursive, it only returns the files in the given changelog directory. Args: changelog (str): The changelog directory. Returns: list[Path]: A list of paths to the changelog files.

Source code in pum/changelog_utils.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def changelog_files(changelog: str) -> list[Path]:
    """
    Get the ordered list of SQL files in the changelog directory.
    This is not recursive, it only returns the files in the given changelog directory.
    Args:
        changelog (str): The changelog directory.
    Returns:
        list[Path]: A list of paths to the changelog files.
    """
    files = [
        changelog.dir / f
        for f in listdir(changelog.dir)
        if (changelog.dir / f).is_file() and f.endswith(".sql")
    ]
    files.sort()
    return files

last_version

last_version(config: PumConfig, dir: str | Path = '.', min_version: str | None = None, max_version: str | None = None) -> str | None

Return the last version of the changelogs. The changelogs are sorted by version. If after_current_version is True, only the changelogs that are after the current version will be returned. If after_current_version is False, all changelogs will be returned.

Parameters:

Name Type Description Default
config PumConfig

The configuration object.

required
dir str | Path

The directory where the changelogs are located.

'.'
min_version str | None

The version to start from (inclusive).

None
max_version str | None

The version to end at (inclusive).

None

Returns:

Type Description
str | None

str | None: The last version of the changelogs. If no changelogs are found, None is returned.

Source code in pum/changelog_utils.py
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
def last_version(
    config: PumConfig,
    dir: str | Path = ".",
    min_version: str | None = None,
    max_version: str | None = None,
) -> str | None:
    """
    Return the last version of the changelogs.
    The changelogs are sorted by version.
    If after_current_version is True, only the changelogs that are after the current version will be returned.
    If after_current_version is False, all changelogs will be returned.

    Args:
        config (PumConfig): The configuration object.
        dir (str | Path): The directory where the changelogs are located.
        min_version (str | None): The version to start from (inclusive).
        max_version (str | None): The version to end at (inclusive).

    Returns:
        str | None: The last version of the changelogs. If no changelogs are found, None is returned.
    """
    changelogs = list_changelogs(config, dir, min_version, max_version)
    if not changelogs:
        return None
    if min_version:
        changelogs = [c for c in changelogs if c.version >= parse_version(min_version)]
    if max_version:
        changelogs = [c for c in changelogs if c.version <= parse_version(max_version)]
    if not changelogs:
        return None
    return changelogs[-1].version

list_changelogs

list_changelogs(config: PumConfig, dir: str | Path = '.', min_version: str | None = None, max_version: str | None = None) -> list

Return a list of changelogs. The changelogs are sorted by version. If after_current_version is True, only the changelogs that are after the current version will be returned. If after_current_version is False, all changelogs will be returned.

Parameters:

Name Type Description Default
config PumConfig

The configuration object.

required
dir str | Path

The directory where the changelogs are located.

'.'
min_version str | None

The version to start from (inclusive).

None
max_version str | None

The version to end at (inclusive).

None

Returns:

Name Type Description
list list

A list of changelogs. Each changelog is represented by a Changelog object.

Source code in pum/changelog_utils.py
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
def list_changelogs(
    config: PumConfig,
    dir: str | Path = ".",
    min_version: str | None = None,
    max_version: str | None = None,
) -> list:
    """
    Return a list of changelogs.
    The changelogs are sorted by version.
    If after_current_version is True, only the changelogs that are after the current version will be returned.
    If after_current_version is False, all changelogs will be returned.

    Args:
        config (PumConfig): The configuration object.
        dir (str | Path): The directory where the changelogs are located.
        min_version (str | None): The version to start from (inclusive).
        max_version (str | None): The version to end at (inclusive).

    Returns:
        list: A list of changelogs. Each changelog is represented by a Changelog object.
    """
    path = Path(dir)
    if not path.is_dir():
        raise PumException(f"Module directory `{path}` does not exist.")
    path = path / config.changelogs_directory
    if not path.is_dir():
        raise PumException(f"Changelogs directory `{path}` does not exist.")

    changelogs = [Changelog(path / d) for d in listdir(path) if isdir(join(path, d))]

    if min_version:
        changelogs = [c for c in changelogs if c.version >= parse_version(min_version)]
    if max_version:
        changelogs = [c for c in changelogs if c.version <= parse_version(max_version)]

    changelogs.sort(key=lambda c: c.version)
    return changelogs