|
10 | 10 | from .models.DurableEntityContext import DurableEntityContext
|
11 | 11 | from .models.RetryOptions import RetryOptions
|
12 | 12 | from .models.TokenSource import ManagedIdentityTokenSource
|
| 13 | +import json |
| 14 | +from pathlib import Path |
| 15 | +import sys |
| 16 | + |
| 17 | + |
| 18 | +def validate_extension_bundles(): |
| 19 | + """Throw an exception if host.json contains bundle-range V1. |
| 20 | +
|
| 21 | + Raises |
| 22 | + ------ |
| 23 | + Exception: Exception prompting the user to update to bundles V2 |
| 24 | + """ |
| 25 | + # No need to validate if we're running tests |
| 26 | + if "pytest" in sys.modules: |
| 27 | + return |
| 28 | + |
| 29 | + host_path = "host.json" |
| 30 | + bundles_key = "extensionBundle" |
| 31 | + version_key = "version" |
| 32 | + host_file = Path(host_path) |
| 33 | + |
| 34 | + if not host_file.exists(): |
| 35 | + # If it doesn't exist, we ignore it |
| 36 | + return |
| 37 | + |
| 38 | + with open(host_path) as f: |
| 39 | + host_settings = json.loads(f.read()) |
| 40 | + try: |
| 41 | + version_range = host_settings[bundles_key][version_key] |
| 42 | + except Exception: |
| 43 | + # If bundle info is not available, we ignore it. |
| 44 | + # For example: it's possible the user is using a manual extension install |
| 45 | + return |
| 46 | + # We do a best-effort attempt to detect bundles V1 |
| 47 | + # This is the string hard-coded into the bundles V1 template in VSCode |
| 48 | + if version_range == "[1.*, 2.0.0)": |
| 49 | + message = "Durable Functions for Python does not support Bundles V1."\ |
| 50 | + " Please update to Bundles V2 in your `host.json`."\ |
| 51 | + " You can set extensionBundles version to be: [2.*, 3.0.0)" |
| 52 | + raise Exception(message) |
| 53 | + |
| 54 | + |
| 55 | +# Validate that users are not in extension bundles V1 |
| 56 | +validate_extension_bundles() |
13 | 57 |
|
14 | 58 | __all__ = [
|
15 | 59 | 'Orchestrator',
|
|
0 commit comments