Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

🎨 Improved templates.py structure #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions prefect/flows/deployments/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import importlib
import os
import pathlib
import sys

import __main__
from prefect.blocks.core import Block
Expand All @@ -22,7 +23,7 @@ def get_deployment(
infra_block: str = None,
storage_block: str = None,
version: int = 1,
tags: list[str] = [],
tags: list[str] = None,
) -> Deployment:
"""
Build and return a Prefect deployment.
Expand All @@ -39,7 +40,7 @@ def get_deployment(
infra_block (str, optional): Infrastructure block configured for the deployment. Defaults to None.
storage_block (str, optional): Storage block configured for the deployment. Defaults to None.
version (int, optional): Version of the deployment. Defaults to 1.
tags (list[str], optional): List of tags for the deployment. Defaults to [].
tags (list[str], optional): List of tags for the deployment. Defaults to None.

Returns:
Deployment: Prefect deployment that stores flow's metadata.
Expand All @@ -55,7 +56,17 @@ def get_deployment(

infrastructure = Block.load(infra_block)
storage = Block.load(storage_block)

"""
Saves the file name from which the deployment was created in a list under the parameter "tags".
The file name is necessary in the tags to automatically delete the deployment based on that information,
as Prefect does not store any information about the file from which the deployment originated.
Automatic deletion is performed using Azure Pipeline "Prefect automatic deployments", which fetches the script during execution
from the following repository. https://github.com/dyvenia/nesso-starter-project/blob/main/.github/scripts/prefect_deployments.py
Comment on lines +60 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from this script, all we know is this adds a filename tag for use by eg. CI/CD pipelines. There should be no reference to any particular pipeline, but it makes sense to say this feature is used by the prefect_deployments.py script.

"""
if tags is None:
tags = [f"{sys.argv[0]}"]
else:
tags.append(f"{sys.argv[0]}")
deployment = Deployment.build_from_flow(
flow=flow,
name=name,
Expand Down Expand Up @@ -83,7 +94,7 @@ def extract_and_load(
infra_block: str = None,
storage_block: str = None,
version: int = 1,
tags: list[str] = [],
tags: list[str] = None,
) -> None:
"""
Build and apply the Prefect deployment.
Expand All @@ -105,7 +116,7 @@ def extract_and_load(
storage_block (str, optional): Storage block configured for the deployment. Defaults to the value of the
`NESSO_PREFECT_DEFAULT_STORAGE_BLOCK` environment variable.
version (int, optional): Version of the deployment. Defaults to 1.
tags (list[str], optional): List of tags for the deployment. Defaults to [].
tags (list[str], optional): List of tags for the deployment. Defaults to None.

"""

Expand Down