shuffle-sdk 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shuffle_sdk-0.0.8/LICENSE +21 -0
- shuffle_sdk-0.0.8/PKG-INFO +82 -0
- shuffle_sdk-0.0.8/README.md +56 -0
- shuffle_sdk-0.0.8/setup.cfg +4 -0
- shuffle_sdk-0.0.8/setup.py +24 -0
- shuffle_sdk-0.0.8/shuffle_sdk/__init__.py +8 -0
- shuffle_sdk-0.0.8/shuffle_sdk/autocorrect_test.py +187 -0
- shuffle_sdk-0.0.8/shuffle_sdk/recurse_test.py +326 -0
- shuffle_sdk-0.0.8/shuffle_sdk/shuffle_sdk.py +4325 -0
- shuffle_sdk-0.0.8/shuffle_sdk.egg-info/PKG-INFO +82 -0
- shuffle_sdk-0.0.8/shuffle_sdk.egg-info/SOURCES.txt +12 -0
- shuffle_sdk-0.0.8/shuffle_sdk.egg-info/dependency_links.txt +1 -0
- shuffle_sdk-0.0.8/shuffle_sdk.egg-info/requires.txt +1 -0
- shuffle_sdk-0.0.8/shuffle_sdk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Frikkylikeme
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: shuffle_sdk
|
|
3
|
+
Version: 0.0.8
|
|
4
|
+
Summary: The SDK used for Shuffle
|
|
5
|
+
Home-page: https://github.com/shuffle/shuffle
|
|
6
|
+
Author: Fredrik Saito Odegaardstuen
|
|
7
|
+
Author-email: frikky@shuffler.io
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: license
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# Shuffle SDK
|
|
28
|
+
This is the SDK used for app development, testing and production of ALL apps in Shuffle. Works with manual runs, Docker, k8s, cloud serverless.
|
|
29
|
+
|
|
30
|
+
Released under [Python pip for usage outside of Shuffle](https://pypi.org/project/shuffle-sdk/)
|
|
31
|
+
|
|
32
|
+
Python apps: [https://github.com/shuffle/python-apps](https://github.com/shuffle/python-apps)
|
|
33
|
+
All apps: [https://shuffler.io/search](https://shuffler.io/search)
|
|
34
|
+
|
|
35
|
+
## Usage with Shuffle
|
|
36
|
+
Refer to the [Shuffle App Creation docs](https://shuffler.io/docs/app_creation)
|
|
37
|
+
|
|
38
|
+
## Build
|
|
39
|
+
`docker build . -t shuffle/shuffle:app_sdk`
|
|
40
|
+
|
|
41
|
+
## Download
|
|
42
|
+
```
|
|
43
|
+
pip install shuffle_sdk
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
```python
|
|
48
|
+
from shuffle_sdk import AppBase
|
|
49
|
+
|
|
50
|
+
class Example(AppBase):
|
|
51
|
+
def __init__(self):
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
def sample_function(self, paramname):
|
|
55
|
+
return f"Hello {paramname}"
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
Example.run()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Testing the SDK
|
|
62
|
+
```bash
|
|
63
|
+
python3 app.py --standalone --action=sample_function paramname=World
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Example with Liquid and the [Shuffle Tools app and the "repeat back to me" function](https://github.com/Shuffle/python-apps/blob/678187d1198f5e8fd2072e475dbbbf858728dde8/shuffle-tools/1.2.0/src/app.py#L235)
|
|
67
|
+
```bash
|
|
68
|
+
python3 app.py --standalone --action=repeat_back_to_me --call=lol
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
If successful, the output of the function will show in your CLI.
|
|
72
|
+
|
|
73
|
+
## Adding new [Liquid filters](https://shuffler.io/docs/liquid)
|
|
74
|
+
Add a function along these lines:
|
|
75
|
+
```
|
|
76
|
+
@shuffle_filters.register
|
|
77
|
+
def md5(a):
|
|
78
|
+
a = str(a)
|
|
79
|
+
return hashlib.md5(a.encode('utf-8')).hexdigest()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This can be used as `{{ "string" | md5 }}`, where `"string"` -> the `a` parameter of the function
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Shuffle SDK
|
|
2
|
+
This is the SDK used for app development, testing and production of ALL apps in Shuffle. Works with manual runs, Docker, k8s, cloud serverless.
|
|
3
|
+
|
|
4
|
+
Released under [Python pip for usage outside of Shuffle](https://pypi.org/project/shuffle-sdk/)
|
|
5
|
+
|
|
6
|
+
Python apps: [https://github.com/shuffle/python-apps](https://github.com/shuffle/python-apps)
|
|
7
|
+
All apps: [https://shuffler.io/search](https://shuffler.io/search)
|
|
8
|
+
|
|
9
|
+
## Usage with Shuffle
|
|
10
|
+
Refer to the [Shuffle App Creation docs](https://shuffler.io/docs/app_creation)
|
|
11
|
+
|
|
12
|
+
## Build
|
|
13
|
+
`docker build . -t shuffle/shuffle:app_sdk`
|
|
14
|
+
|
|
15
|
+
## Download
|
|
16
|
+
```
|
|
17
|
+
pip install shuffle_sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
```python
|
|
22
|
+
from shuffle_sdk import AppBase
|
|
23
|
+
|
|
24
|
+
class Example(AppBase):
|
|
25
|
+
def __init__(self):
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
def sample_function(self, paramname):
|
|
29
|
+
return f"Hello {paramname}"
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
Example.run()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Testing the SDK
|
|
36
|
+
```bash
|
|
37
|
+
python3 app.py --standalone --action=sample_function paramname=World
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Example with Liquid and the [Shuffle Tools app and the "repeat back to me" function](https://github.com/Shuffle/python-apps/blob/678187d1198f5e8fd2072e475dbbbf858728dde8/shuffle-tools/1.2.0/src/app.py#L235)
|
|
41
|
+
```bash
|
|
42
|
+
python3 app.py --standalone --action=repeat_back_to_me --call=lol
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If successful, the output of the function will show in your CLI.
|
|
46
|
+
|
|
47
|
+
## Adding new [Liquid filters](https://shuffler.io/docs/liquid)
|
|
48
|
+
Add a function along these lines:
|
|
49
|
+
```
|
|
50
|
+
@shuffle_filters.register
|
|
51
|
+
def md5(a):
|
|
52
|
+
a = str(a)
|
|
53
|
+
return hashlib.md5(a.encode('utf-8')).hexdigest()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This can be used as `{{ "string" | md5 }}`, where `"string"` -> the `a` parameter of the function
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='shuffle_sdk',
|
|
5
|
+
version='0.0.8',
|
|
6
|
+
description='The SDK used for Shuffle',
|
|
7
|
+
py_modules=["shuffle_sdk"],
|
|
8
|
+
license='MIT',
|
|
9
|
+
long_description=open('README.md').read(),
|
|
10
|
+
long_description_content_type='text/markdown',
|
|
11
|
+
author='Fredrik Saito Odegaardstuen',
|
|
12
|
+
author_email='frikky@shuffler.io',
|
|
13
|
+
url='https://github.com/shuffle/shuffle',
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
install_requires=[
|
|
16
|
+
'requests',
|
|
17
|
+
],
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Programming Language :: Python :: 3',
|
|
20
|
+
'License :: OSI Approved :: MIT License',
|
|
21
|
+
'Operating System :: OS Independent',
|
|
22
|
+
],
|
|
23
|
+
python_requires='>=3.7', # Specify Python version requirements
|
|
24
|
+
)
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
input_data = """{
|
|
5
|
+
"test4": $test,
|
|
6
|
+
"test5": ,
|
|
7
|
+
"test6": "what"
|
|
8
|
+
}
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
input_data = """{
|
|
12
|
+
"test0": {{ '' | default: [] }},
|
|
13
|
+
"test": {{ | default: [] }},
|
|
14
|
+
"test2": {{ $test.asd | default: [] }},
|
|
15
|
+
"test3": {{ {"key": "val} | default: [] }},
|
|
16
|
+
"test4": $test,
|
|
17
|
+
"test5": ,
|
|
18
|
+
"test6": "what"
|
|
19
|
+
}
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
liquiddata = "{{ $test.asd | some other stuff {{ $test.xyz | more stuff"
|
|
24
|
+
pattern = r'\{\{\s*\$[^|}]+\s*\|'
|
|
25
|
+
|
|
26
|
+
replaced_data = re.sub(pattern, "{{ '' |", liquiddata)
|
|
27
|
+
print(replaced_data)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def patternfix_string(liquiddata, patterns, regex_patterns, inputtype="liquid"):
|
|
31
|
+
if not inputtype or inputtype == "liquid":
|
|
32
|
+
if "{{" not in liquiddata or "}}" not in liquiddata:
|
|
33
|
+
return liquiddata
|
|
34
|
+
elif inputtype == "json":
|
|
35
|
+
liquiddata = liquiddata.strip()
|
|
36
|
+
|
|
37
|
+
# Validating if it looks like json or not
|
|
38
|
+
if liquiddata[0] == "{" and liquiddata[len(liquiddata)-1] == "}":
|
|
39
|
+
pass
|
|
40
|
+
else:
|
|
41
|
+
if liquiddata[0] == "[" and liquiddata[len(liquiddata)-1] == "]":
|
|
42
|
+
pass
|
|
43
|
+
else:
|
|
44
|
+
return liquiddata
|
|
45
|
+
|
|
46
|
+
# If it's already json, don't touch it
|
|
47
|
+
try:
|
|
48
|
+
json.loads(liquiddata)
|
|
49
|
+
return liquiddata
|
|
50
|
+
except Exception as e:
|
|
51
|
+
pass
|
|
52
|
+
else:
|
|
53
|
+
print("No replace handler for %s" % inputtype)
|
|
54
|
+
return liquiddata
|
|
55
|
+
|
|
56
|
+
skipkeys = [" "]
|
|
57
|
+
newoutput = liquiddata[:]
|
|
58
|
+
for pattern in patterns:
|
|
59
|
+
keylocations = []
|
|
60
|
+
parsedvalue = ""
|
|
61
|
+
record = False
|
|
62
|
+
index = -1
|
|
63
|
+
for key in liquiddata:
|
|
64
|
+
|
|
65
|
+
# Return instant if possible
|
|
66
|
+
if inputtype == "json":
|
|
67
|
+
try:
|
|
68
|
+
json.loads(newoutput)
|
|
69
|
+
return newoutput
|
|
70
|
+
except:
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
index += 1
|
|
74
|
+
if not key:
|
|
75
|
+
if record:
|
|
76
|
+
keylocations.append(index)
|
|
77
|
+
parsedvalue += key
|
|
78
|
+
|
|
79
|
+
continue
|
|
80
|
+
|
|
81
|
+
if key in skipkeys:
|
|
82
|
+
if record:
|
|
83
|
+
keylocations.append(index)
|
|
84
|
+
parsedvalue += key
|
|
85
|
+
|
|
86
|
+
continue
|
|
87
|
+
|
|
88
|
+
if key == pattern[0] and not record:
|
|
89
|
+
record = True
|
|
90
|
+
|
|
91
|
+
if key not in pattern:
|
|
92
|
+
keylocations = []
|
|
93
|
+
parsedvalue = ""
|
|
94
|
+
record = False
|
|
95
|
+
|
|
96
|
+
if record:
|
|
97
|
+
keylocations.append(index)
|
|
98
|
+
parsedvalue += key
|
|
99
|
+
|
|
100
|
+
if len(parsedvalue) == 0:
|
|
101
|
+
continue
|
|
102
|
+
|
|
103
|
+
evaluated_value = parsedvalue[:]
|
|
104
|
+
for skipkey in skipkeys:
|
|
105
|
+
evaluated_value = "".join(evaluated_value.split(skipkey))
|
|
106
|
+
|
|
107
|
+
if evaluated_value == pattern:
|
|
108
|
+
#print("Found matching: %s (%s)" % (parsedvalue, keylocations))
|
|
109
|
+
#print("Should replace with: %s" % patterns[pattern])
|
|
110
|
+
|
|
111
|
+
newoutput = newoutput.replace(parsedvalue, patterns[pattern], -1)
|
|
112
|
+
|
|
113
|
+
# Return instant if possible
|
|
114
|
+
if inputtype == "json":
|
|
115
|
+
try:
|
|
116
|
+
json.loads(newoutput)
|
|
117
|
+
return newoutput
|
|
118
|
+
except:
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
for pattern in regex_patterns:
|
|
123
|
+
newlines = []
|
|
124
|
+
for line in newoutput.split("\n"):
|
|
125
|
+
replaced_line = re.sub(pattern, regex_patterns[pattern], line)
|
|
126
|
+
newlines.append(replaced_line)
|
|
127
|
+
|
|
128
|
+
newoutput = "\n".join(newlines)
|
|
129
|
+
|
|
130
|
+
# Return instant if possible
|
|
131
|
+
if inputtype == "json":
|
|
132
|
+
try:
|
|
133
|
+
json.loads(newoutput)
|
|
134
|
+
return newoutput
|
|
135
|
+
except:
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
# Dont return json properly unless actually json
|
|
139
|
+
if inputtype == "json":
|
|
140
|
+
try:
|
|
141
|
+
json.loads(newoutput)
|
|
142
|
+
return newoutput
|
|
143
|
+
except:
|
|
144
|
+
# Returns original if json fixing didn't work
|
|
145
|
+
return liquiddata
|
|
146
|
+
|
|
147
|
+
return newoutput
|
|
148
|
+
|
|
149
|
+
print("Start:\n%s" % input_data)
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
newinput = patternfix_string(input_data,
|
|
153
|
+
{
|
|
154
|
+
"{{|": '{{ "" |',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
#r'\{\{\s*|': "{{ '' |",
|
|
158
|
+
r'\{\{\s*\$[^|}]+\s*\|': '{{ "" |',
|
|
159
|
+
}
|
|
160
|
+
,
|
|
161
|
+
inputtype="liquid"
|
|
162
|
+
)
|
|
163
|
+
except Exception as e:
|
|
164
|
+
print("[ERROR} Failed liquid parsing fix: %s" % e)
|
|
165
|
+
newinput = input_data
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
newinput = patternfix_string(newinput,
|
|
169
|
+
{
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
r'\"\s*\:\s*,': '\": "",',
|
|
173
|
+
r'\"\s*\:\s*\$[^,]+\w*\,': '\": "",',
|
|
174
|
+
}
|
|
175
|
+
,
|
|
176
|
+
inputtype="json"
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
json.loads(newinput)
|
|
181
|
+
print("It's json! Override.")
|
|
182
|
+
except Exception as e:
|
|
183
|
+
print("Bad json. DONT use the value at all: %s" % e)
|
|
184
|
+
except Exception as e:
|
|
185
|
+
print("[ERROR} Failed json parsing fix: %s" % e)
|
|
186
|
+
|
|
187
|
+
print("\nEnd:\n%s" % newinput)
|