Skip to content

Commit d8f2c06

Browse files
authored
Validate Bundles V2 usage in initialization script (#238)
1 parent 8409388 commit d8f2c06

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

azure/durable_functions/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@
1010
from .models.DurableEntityContext import DurableEntityContext
1111
from .models.RetryOptions import RetryOptions
1212
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()
1357

1458
__all__ = [
1559
'Orchestrator',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from setuptools import setup, find_packages
1010
from distutils.command import build
1111

12-
with open("README.md", "r") as fh:
12+
with open("README.md", "r", encoding="utf8") as fh:
1313
long_description = fh.read()
1414

1515
class BuildModule(build.build):

0 commit comments

Comments
 (0)