-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtools.py
42 lines (32 loc) · 1.07 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""This file is just a sample launcher code.
"""
try:
from inspect import getfullargspec as get_arg_spec
except ImportError:
from inspect import getargspec as get_arg_spec
import os
import sys
import types
class SubscriptionKeyError(Exception):
pass
def start_sample(func, subscription_key):
"""Start the function and show its doc on output."""
print("Sample:", func.__doc__, "\n")
func(subscription_key)
print("\n\n")
def execute_samples(module_globals, key_env_variable):
"""Execute samples based on a dict <name, function>"""
try:
subscription_key = key_env_variable
except KeyError:
raise SubscriptionKeyError(
"You need to either set the {} env variable.".format(key_env_variable)
)
for func in list(module_globals.values()):
if not isinstance(func, types.FunctionType):
continue
args = get_arg_spec(func).args
if "subscription_key" in args:
start_sample(func, subscription_key)