Skip to content

Commit 7f864ef

Browse files
authored
Migrate prefect-azure to prefect repository (#12787)
1 parent 9c0a7b3 commit 7f864ef

26 files changed

+7996
-3
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Integrations Packages Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "src/integrations/*/**"
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- "src/integrations/*/**"
12+
13+
jobs:
14+
prepare-matrix:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.set-matrix.outputs.matrix }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
fetch-depth: 0
23+
- name: Set up Python
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: "3.9"
27+
- name: Generate matrix
28+
id: set-matrix
29+
run: |
30+
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
31+
COMMIT_RANGE="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
32+
else
33+
COMMIT_RANGE="${{ github.event.before }}..${{ github.event.after }}"
34+
fi
35+
python scripts/generate_integration_package_tests_matrix.py "$COMMIT_RANGE" > matrix.json
36+
cat matrix.json
37+
echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
38+
39+
run-tests:
40+
name: Run Tests for ${{ matrix.package }} on Python ${{ matrix.python-version }}
41+
needs: prepare-matrix
42+
runs-on: ubuntu-latest
43+
strategy:
44+
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
45+
fail-fast: false
46+
steps:
47+
- name: Display current test matrix
48+
run: echo '${{ toJSON(matrix) }}'
49+
50+
- uses: actions/checkout@v4
51+
with:
52+
persist-credentials: false
53+
54+
- name: Set up Python ${{ matrix.python-version }}
55+
uses: actions/setup-python@v5
56+
id: setup_python
57+
with:
58+
python-version: ${{ matrix.python-version }}
59+
60+
- name: UV Cache
61+
# Manually cache the uv cache directory
62+
# until setup-python supports it:
63+
# https://github.com/actions/setup-python/issues/822
64+
uses: actions/cache@v4
65+
id: cache-uv
66+
with:
67+
path: ~/.cache/uv
68+
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles(format('src/integrations/{0}/pyproject.toml', matrix.package)) }}
69+
70+
- name: Install dependencies
71+
working-directory: src/integrations/${{ matrix.package }}
72+
run: |
73+
python -m pip install -U uv
74+
uv pip install --upgrade --system -e .[dev]
75+
76+
- name: Run tests
77+
env:
78+
PREFECT_API_DATABASE_CONNECTION_URL: "sqlite+aiosqlite:///./orion-tests.db"
79+
working-directory: src/integrations/${{ matrix.package }}
80+
run: >
81+
pytest tests
82+
--numprocesses auto
83+
--maxprocesses 6
84+
--dist loadscope

.github/workflows/python-tests.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
pull_request:
1010
paths:
1111
- .github/workflows/python-tests.yaml
12-
- "**/*.py"
12+
- "src/prefect/**/*.py"
13+
- "tests/**/*.py"
1314
- requirements.txt
1415
- requirements-client.txt
1516
- requirements-dev.txt
@@ -20,7 +21,8 @@ on:
2021
- main
2122
paths:
2223
- .github/workflows/python-tests.yaml
23-
- "**/*.py"
24+
- "src/prefect/**/*.py"
25+
- "tests/**/*.py"
2426
- requirements.txt
2527
- requirements-client.txt
2628
- requirements-dev.txt

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,7 @@ prefect.yaml
7171
!src/prefect/deployments/recipes/*/**
7272

7373
# For development doc server if link
74-
libcairo.2.dylib
74+
libcairo.2.dylib
75+
76+
# setuptools-scm generated files
77+
src/integrations/*/**/_version.py
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
import subprocess
3+
import sys
4+
from typing import Dict, List, Set
5+
6+
PYTHON_VERSIONS = [
7+
"3.8",
8+
"3.9",
9+
"3.10",
10+
"3.11",
11+
"3.12",
12+
]
13+
14+
15+
def get_changed_packages(commit_range: str) -> List[str]:
16+
# Get the list of changed files in the specified commit range
17+
result = subprocess.run(
18+
["git", "diff", "--name-only", commit_range],
19+
capture_output=True,
20+
text=True,
21+
check=True,
22+
)
23+
changed_files = result.stdout.split()
24+
# Filter for src/integrations directories
25+
packages: Set[str] = set()
26+
for file in changed_files:
27+
parts = file.split("/")
28+
if len(parts) > 1 and parts[0] == "src" and parts[1] == "integrations":
29+
packages.add(parts[2])
30+
return list(packages)
31+
32+
33+
def generate_matrix(packages: List[str], python_versions: List[str]) -> Dict:
34+
matrix = {"include": []}
35+
for package in packages:
36+
for version in python_versions:
37+
matrix["include"].append({"package": package, "python-version": version})
38+
return matrix
39+
40+
41+
if __name__ == "__main__":
42+
# Get the range of commits to check, or use a default range
43+
commit_range = sys.argv[1] if len(sys.argv) > 1 else "HEAD~1..HEAD"
44+
packages = get_changed_packages(commit_range=commit_range)
45+
matrix = generate_matrix(packages, PYTHON_VERSIONS)
46+
print(json.dumps(matrix))
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# prefect-azure
2+
3+
<p align="center">
4+
<a href="https://pypi.python.org/pypi/prefect-azure/" alt="PyPI version">
5+
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-azure?color=26272B&labelColor=090422"></a>
6+
<a href="https://pepy.tech/badge/prefect-azure/" alt="Downloads">
7+
<img src="https://img.shields.io/pypi/dm/prefect-azure?color=26272B&labelColor=090422" /></a>
8+
</p>
9+
10+
`prefect-azure` is a collection of Prefect integrations for orchestration workflows with Azure.
11+
12+
## Getting Started
13+
14+
### Installation
15+
16+
Install `prefect-azure` with `pip`
17+
18+
```bash
19+
pip install prefect-azure
20+
```
21+
22+
To use Blob Storage:
23+
```bash
24+
pip install "prefect-azure[blob_storage]"
25+
```
26+
27+
To use Cosmos DB:
28+
```bash
29+
pip install "prefect-azure[cosmos_db]"
30+
```
31+
32+
To use ML Datastore:
33+
```bash
34+
pip install "prefect-azure[ml_datastore]"
35+
```
36+
37+
## Examples
38+
39+
### Download a blob
40+
41+
```python
42+
from prefect import flow
43+
44+
from prefect_azure import AzureBlobStorageCredentials
45+
from prefect_azure.blob_storage import blob_storage_download
46+
47+
@flow
48+
def example_blob_storage_download_flow():
49+
connection_string = "connection_string"
50+
blob_storage_credentials = AzureBlobStorageCredentials(
51+
connection_string=connection_string,
52+
)
53+
data = blob_storage_download(
54+
blob="prefect.txt",
55+
container="prefect",
56+
azure_credentials=blob_storage_credentials,
57+
)
58+
return data
59+
60+
example_blob_storage_download_flow()
61+
```
62+
63+
Use `with_options` to customize options on any existing task or flow:
64+
```python
65+
custom_blob_storage_download_flow = example_blob_storage_download_flow.with_options(
66+
name="My custom task name",
67+
retries=2,
68+
retry_delay_seconds=10,
69+
)
70+
```
71+
72+
### Run a command on an Azure container instance
73+
74+
```python
75+
from prefect import flow
76+
from prefect_azure import AzureContainerInstanceCredentials
77+
from prefect_azure.container_instance import AzureContainerInstanceJob
78+
79+
80+
@flow
81+
def container_instance_job_flow():
82+
aci_credentials = AzureContainerInstanceCredentials.load("MY_BLOCK_NAME")
83+
container_instance_job = AzureContainerInstanceJob(
84+
aci_credentials=aci_credentials,
85+
resource_group_name="azure_resource_group.example.name",
86+
subscription_id="<MY_AZURE_SUBSCRIPTION_ID>",
87+
command=["echo", "hello world"],
88+
)
89+
return container_instance_job.run()
90+
```
91+
92+
### Use Azure Container Instance as infrastructure
93+
94+
If we have `a_flow_module.py`:
95+
96+
```python
97+
from prefect import flow, get_run_logger
98+
99+
@flow
100+
def log_hello_flow(name="Marvin"):
101+
logger = get_run_logger()
102+
logger.info(f"{name} said hello!")
103+
104+
if __name__ == "__main__":
105+
log_hello_flow()
106+
```
107+
108+
We can run that flow using an Azure Container Instance, but first create the infrastructure block:
109+
110+
```python
111+
from prefect_azure import AzureContainerInstanceCredentials
112+
from prefect_azure.container_instance import AzureContainerInstanceJob
113+
114+
container_instance_job = AzureContainerInstanceJob(
115+
aci_credentials=AzureContainerInstanceCredentials.load("MY_BLOCK_NAME"),
116+
resource_group_name="azure_resource_group.example.name",
117+
subscription_id="<MY_AZURE_SUBSCRIPTION_ID>",
118+
)
119+
container_instance_job.save("aci-dev")
120+
```
121+
122+
Then, create the deployment either on the UI or through the CLI:
123+
```bash
124+
prefect deployment build a_flow_module.py:log_hello_flow --name aci-dev -ib container-instance-job/aci-dev
125+
```
126+
127+
Visit [Prefect Deployments](https://docs.prefect.io/tutorials/deployments/) for more information about deployments.
128+
129+
## Azure Container Instance Worker
130+
The Azure Container Instance worker is an excellent way to run
131+
your workflows on Azure.
132+
133+
To get started, create an Azure Container Instances typed work pool:
134+
```
135+
prefect work-pool create -t azure-container-instance my-aci-work-pool
136+
```
137+
138+
Then, run a worker that pulls jobs from the work pool:
139+
```
140+
prefect worker start -n my-aci-worker -p my-aci-work-pool
141+
```
142+
143+
The worker should automatically read the work pool's type and start an
144+
Azure Container Instance worker.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from .credentials import ( # noqa
2+
AzureBlobStorageCredentials,
3+
AzureCosmosDbCredentials,
4+
AzureMlCredentials,
5+
AzureContainerInstanceCredentials,
6+
)
7+
from .workers.container_instance import AzureContainerWorker # noqa
8+
from .container_instance import AzureContainerInstanceJob # noqa
9+
from .blob_storage import AzureBlobStorageContainer # noqa
10+
11+
__all__ = [
12+
"AzureBlobStorageCredentials",
13+
"AzureCosmosDbCredentials",
14+
"AzureMlCredentials",
15+
"AzureContainerInstanceCredentials",
16+
"AzureContainerInstanceJob",
17+
"AzureContainerWorker",
18+
"AzureBlobStorageContainer",
19+
]
20+
21+
try:
22+
from ._version import version as __version__
23+
except ImportError:
24+
__version__ = "unknown"

0 commit comments

Comments
 (0)