Skip to content

Version

This part of the project documentation focuses on an information-oriented approach. Use it as a reference for the technical implementation of the pact_methodology project code.

Version

Represents a version of a product footprint.

Attributes:

Name Type Description
version int

The version number, which must be an integer in the range 0 to 2^31-1.

Raises:

Type Description
ValueError

If the version number is not an integer or is out of range.

Source code in pact_methodology/product_footprint/version.py
 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
class Version:
    """
    Represents a version of a product footprint.

    Attributes:
        version (int): The version number, which must be an integer in the range 0 to 2^31-1.

    Raises:
        ValueError: If the version number is not an integer or is out of range.
    """

    def __init__(self, version: int) -> None:
        """
        Initializes a new Version object.

        Args:
            version (int): The version number.

        Raises:
            ValueError: If the version number is not an integer or is out of range.
        """
        if not isinstance(version, int):
            raise ValueError("Version must be an integer")
        if version < 0 or version > 2**31 - 1:
            raise ValueError("Version must be in the range of 0 to 2^31-1")
        self.version = version

    def __eq__(self, other: object) -> bool:
        """
        Compares two Version objects for equality.

        Args:
            other (object): The object to compare with.

        Returns:
            bool: True if the objects are equal, False otherwise.
        """
        if not isinstance(other, Version):
            return False
        return self.version == other.version

    def __repr__(self) -> str:
        """
        Returns a string representation of the Version object.

        Returns:
            str: A string representation of the Version object.
        """
        return f"Version({self.version})"

    @classmethod
    def get_latest_version(cls, *versions: "Version") -> "Version":
        """
        Returns the latest version from a list of versions.

        Args:
            *versions (Version): The versions to compare.

        Returns:
            Version: The latest version.

        Raises:
            ValueError: If any of the arguments are not instances of Version.
        """
        if not all(isinstance(version, cls) for version in versions):
            raise ValueError("All arguments must be instances of Version")
        return max(versions, key=lambda version: version.version)

__eq__(other)

Compares two Version objects for equality.

Parameters:

Name Type Description Default
other object

The object to compare with.

required

Returns:

Name Type Description
bool bool

True if the objects are equal, False otherwise.

Source code in pact_methodology/product_footprint/version.py
28
29
30
31
32
33
34
35
36
37
38
39
40
def __eq__(self, other: object) -> bool:
    """
    Compares two Version objects for equality.

    Args:
        other (object): The object to compare with.

    Returns:
        bool: True if the objects are equal, False otherwise.
    """
    if not isinstance(other, Version):
        return False
    return self.version == other.version

__init__(version)

Initializes a new Version object.

Parameters:

Name Type Description Default
version int

The version number.

required

Raises:

Type Description
ValueError

If the version number is not an integer or is out of range.

Source code in pact_methodology/product_footprint/version.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def __init__(self, version: int) -> None:
    """
    Initializes a new Version object.

    Args:
        version (int): The version number.

    Raises:
        ValueError: If the version number is not an integer or is out of range.
    """
    if not isinstance(version, int):
        raise ValueError("Version must be an integer")
    if version < 0 or version > 2**31 - 1:
        raise ValueError("Version must be in the range of 0 to 2^31-1")
    self.version = version

__repr__()

Returns a string representation of the Version object.

Returns:

Name Type Description
str str

A string representation of the Version object.

Source code in pact_methodology/product_footprint/version.py
42
43
44
45
46
47
48
49
def __repr__(self) -> str:
    """
    Returns a string representation of the Version object.

    Returns:
        str: A string representation of the Version object.
    """
    return f"Version({self.version})"

get_latest_version(*versions) classmethod

Returns the latest version from a list of versions.

Parameters:

Name Type Description Default
*versions Version

The versions to compare.

()

Returns:

Name Type Description
Version Version

The latest version.

Raises:

Type Description
ValueError

If any of the arguments are not instances of Version.

Source code in pact_methodology/product_footprint/version.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@classmethod
def get_latest_version(cls, *versions: "Version") -> "Version":
    """
    Returns the latest version from a list of versions.

    Args:
        *versions (Version): The versions to compare.

    Returns:
        Version: The latest version.

    Raises:
        ValueError: If any of the arguments are not instances of Version.
    """
    if not all(isinstance(version, cls) for version in versions):
        raise ValueError("All arguments must be instances of Version")
    return max(versions, key=lambda version: version.version)