Skip to content

Bitbucket

zenml.integrations.bitbucket

Initialization of the bitbucket ZenML integration.

Attributes

BITBUCKET = 'bitbucket' module-attribute

BITBUCKET_EVENT_FLAVOR = 'bitbucket' module-attribute

Classes

BasePluginFlavor

Bases: ABC

Base Class for all PluginFlavors.

Functions
get_flavor_response_model(hydrate: bool) -> BasePluginFlavorResponse[Any, Any, Any] abstractmethod classmethod

Convert the Flavor into a Response Model.

Parameters:

Name Type Description Default
hydrate bool

Whether the model should be hydrated.

required
Source code in src/zenml/plugins/base_plugin_flavor.py
79
80
81
82
83
84
85
86
87
88
@classmethod
@abstractmethod
def get_flavor_response_model(
    cls, hydrate: bool
) -> BasePluginFlavorResponse[Any, Any, Any]:
    """Convert the Flavor into a Response Model.

    Args:
        hydrate: Whether the model should be hydrated.
    """

BitbucketIntegration

Bases: Integration

Definition of bitbucket integration for ZenML.

Functions
plugin_flavors() -> List[Type[BasePluginFlavor]] classmethod

Declare the event flavors for the bitbucket integration.

Returns:

Type Description
List[Type[BasePluginFlavor]]

List of stack component flavors for this integration.

Source code in src/zenml/integrations/bitbucket/__init__.py
30
31
32
33
34
35
36
37
38
39
@classmethod
def plugin_flavors(cls) -> List[Type[BasePluginFlavor]]:
    """Declare the event flavors for the bitbucket integration.

    Returns:
        List of stack component flavors for this integration.
    """
    from zenml.integrations.bitbucket.plugins import BitbucketWebhookEventSourceFlavor

    return [BitbucketWebhookEventSourceFlavor]

Integration

Base class for integration in ZenML.

Functions
activate() -> None classmethod

Abstract method to activate the integration.

Source code in src/zenml/integrations/integration.py
140
141
142
@classmethod
def activate(cls) -> None:
    """Abstract method to activate the integration."""
check_installation() -> bool classmethod

Method to check whether the required packages are installed.

Returns:

Type Description
bool

True if all required packages are installed, False otherwise.

Source code in src/zenml/integrations/integration.py
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
@classmethod
def check_installation(cls) -> bool:
    """Method to check whether the required packages are installed.

    Returns:
        True if all required packages are installed, False otherwise.
    """
    for requirement in cls.get_requirements():
        parsed_requirement = Requirement(requirement)

        if not requirement_installed(parsed_requirement):
            logger.debug(
                "Requirement '%s' for integration '%s' is not installed "
                "or installed with the wrong version.",
                requirement,
                cls.NAME,
            )
            return False

        dependencies = get_dependencies(parsed_requirement)

        for dependency in dependencies:
            if not requirement_installed(dependency):
                logger.debug(
                    "Requirement '%s' for integration '%s' is not "
                    "installed or installed with the wrong version.",
                    dependency,
                    cls.NAME,
                )
                return False

    logger.debug(
        f"Integration '{cls.NAME}' is installed correctly with "
        f"requirements {cls.get_requirements()}."
    )
    return True
flavors() -> List[Type[Flavor]] classmethod

Abstract method to declare new stack component flavors.

Returns:

Type Description
List[Type[Flavor]]

A list of new stack component flavors.

Source code in src/zenml/integrations/integration.py
144
145
146
147
148
149
150
151
@classmethod
def flavors(cls) -> List[Type[Flavor]]:
    """Abstract method to declare new stack component flavors.

    Returns:
        A list of new stack component flavors.
    """
    return []
get_requirements(target_os: Optional[str] = None, python_version: Optional[str] = None) -> List[str] classmethod

Method to get the requirements for the integration.

Parameters:

Name Type Description Default
target_os Optional[str]

The target operating system to get the requirements for.

None
python_version Optional[str]

The Python version to use for the requirements.

None

Returns:

Type Description
List[str]

A list of requirements.

Source code in src/zenml/integrations/integration.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@classmethod
def get_requirements(
    cls,
    target_os: Optional[str] = None,
    python_version: Optional[str] = None,
) -> List[str]:
    """Method to get the requirements for the integration.

    Args:
        target_os: The target operating system to get the requirements for.
        python_version: The Python version to use for the requirements.

    Returns:
        A list of requirements.
    """
    return cls.REQUIREMENTS
get_uninstall_requirements(target_os: Optional[str] = None) -> List[str] classmethod

Method to get the uninstall requirements for the integration.

Parameters:

Name Type Description Default
target_os Optional[str]

The target operating system to get the requirements for.

None

Returns:

Type Description
List[str]

A list of requirements.

Source code in src/zenml/integrations/integration.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@classmethod
def get_uninstall_requirements(
    cls, target_os: Optional[str] = None
) -> List[str]:
    """Method to get the uninstall requirements for the integration.

    Args:
        target_os: The target operating system to get the requirements for.

    Returns:
        A list of requirements.
    """
    ret = []
    for each in cls.get_requirements(target_os=target_os):
        is_ignored = False
        for ignored in cls.REQUIREMENTS_IGNORED_ON_UNINSTALL:
            if each.startswith(ignored):
                is_ignored = True
                break
        if not is_ignored:
            ret.append(each)
    return ret
plugin_flavors() -> List[Type[BasePluginFlavor]] classmethod

Abstract method to declare new plugin flavors.

Returns:

Type Description
List[Type[BasePluginFlavor]]

A list of new plugin flavors.

Source code in src/zenml/integrations/integration.py
153
154
155
156
157
158
159
160
@classmethod
def plugin_flavors(cls) -> List[Type["BasePluginFlavor"]]:
    """Abstract method to declare new plugin flavors.

    Returns:
        A list of new plugin flavors.
    """
    return []

Modules

plugins

Bitbucket event flavors.

Classes
BitbucketWebhookEventSourceFlavor

Bases: BaseWebhookEventSourceFlavor

Enables users to configure Bitbucket event sources.

Modules
bitbucket_webhook_event_source_flavor

Bitbucket webhook event source flavor.

Classes
BitbucketWebhookEventSourceFlavor

Bases: BaseWebhookEventSourceFlavor

Enables users to configure Bitbucket event sources.

event_sources
Modules
bitbucket_webhook_event_source

Implementation of the Bitbucket webhook event source.

Classes
BitbucketEvent

Bases: BaseEvent

Bitbucket Event.

Attributes
branch: Optional[str] property

The branch the event happened on.

Returns:

Type Description
Optional[str]

The branch name.

event_type: Union[BitbucketEventType, str] property

The type of Bitbucket event.

Returns:

Type Description
Union[BitbucketEventType, str]

The type of the event.

BitbucketEventType

Bases: StrEnum

Collection of all possible Bitbucket Events.

BitbucketWebhookEventFilterConfiguration

Bases: WebhookEventFilterConfig

Configuration for Bitbucket event filters.

Functions
event_matches_filter(event: BaseEvent) -> bool

Checks the filter against the inbound event.

Parameters:

Name Type Description Default
event BaseEvent

The incoming event

required

Returns:

Type Description
bool

Whether the event matches the filter

Source code in src/zenml/integrations/bitbucket/plugins/event_sources/bitbucket_webhook_event_source.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def event_matches_filter(self, event: BaseEvent) -> bool:
    """Checks the filter against the inbound event.

    Args:
        event: The incoming event

    Returns:
        Whether the event matches the filter
    """
    if not isinstance(event, BitbucketEvent):
        return False
    if self.event_type and event.event_type != self.event_type:
        # Mismatch for the action
        return False
    if self.repo and event.repository.full_name != self.repo:
        # Mismatch for the repository
        return False
    if self.branch and event.branch != self.branch:
        # Mismatch for the branch
        return False
    return True
BitbucketWebhookEventSourceConfiguration

Bases: WebhookEventSourceConfig

Configuration for Bitbucket source filters.

BitbucketWebhookEventSourceHandler(event_hub: Optional[BaseEventHub] = None)

Bases: BaseWebhookEventSourceHandler

Handler for all Bitbucket events.

Source code in src/zenml/event_sources/base_event_source.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def __init__(self, event_hub: Optional[BaseEventHub] = None) -> None:
    """Event source handler initialization.

    Args:
        event_hub: Optional event hub to use to initialize the event source
            handler. If not set during initialization, it may be set
            at a later time by calling `set_event_hub`. An event hub must
            be configured before the event handler needs to dispatch events.
    """
    super().__init__()
    if event_hub is None:
        from zenml.event_hub.event_hub import (
            event_hub as default_event_hub,
        )

        # TODO: for now, we use the default internal event hub. In
        # the future, this should be configurable.
        event_hub = default_event_hub

    self.set_event_hub(event_hub)
Attributes
config_class: Type[BitbucketWebhookEventSourceConfiguration] property

Returns the webhook event source configuration class.

Returns:

Type Description
Type[BitbucketWebhookEventSourceConfiguration]

The configuration.

filter_class: Type[BitbucketWebhookEventFilterConfiguration] property

Returns the webhook event filter configuration class.

Returns:

Type Description
Type[BitbucketWebhookEventFilterConfiguration]

The event filter configuration class.

flavor_class: Type[BaseWebhookEventSourceFlavor] property

Returns the flavor class of the plugin.

Returns:

Type Description
Type[BaseWebhookEventSourceFlavor]

The flavor class of the plugin.

Commit

Bases: BaseModel

Bitbucket Commit.

Push

Bases: BaseModel

Bitbucket Push.

PushChange

Bases: BaseModel

Bitbucket Push Change.

Repository

Bases: BaseModel

Bitbucket Repository.

User

Bases: BaseModel

Bitbucket User.

Functions