Skip to content

Commit c6ddc6e

Browse files
committed
addon manager packaging
1 parent 1de5d39 commit c6ddc6e

9 files changed

+219
-1
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
/venv2
44
/dist
55
/build
6-
/seeq_mps.egg-info
6+
/seeq_mps.egg-info
7+
/.vscode
8+
.pyc

Diff for: additional_content/mpsworkflowexample.png

420 KB
Loading

Diff for: addon.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"identifier": "com.seeq.addon.mps",
3+
"name": "Multivariate Pattern Search",
4+
"description": "Finds and measures similar events defined across multiple variables",
5+
"version": "Input version here",
6+
"license": "Apache-2.0 license",
7+
"icon": "fa fa-th",
8+
"previews": [
9+
"additional_content/mpsworkflowexample.png"
10+
],
11+
"elements": [
12+
{
13+
"name": "Multivariate Pattern Search",
14+
"description": "Finds and measures similar events defined across multiple variables",
15+
"identifier": "com.seeq.addon.mps.mps",
16+
"type": "AddOnTool",
17+
"path": "data-lab-functions",
18+
"notebook_file_path": "multivariate_pattern_search_ui.ipynb",
19+
"extensions": ["ipyvuetify", "widgetsnbextension","ipyvue"],
20+
"configuration_schema": {
21+
"type": "object",
22+
"properties": {
23+
"display": {
24+
"type": "object",
25+
"properties": {
26+
"icon": {
27+
"type": "string",
28+
"default": "fa fa-leaf"
29+
},
30+
"linkType": {
31+
"enum": ["window", "tab", "none"],
32+
"default": "window"
33+
},
34+
"sortKey": {
35+
"type": "string",
36+
"default": "m"
37+
},
38+
"windowDetails": {
39+
"type": "string",
40+
"default": "toolbar=0,location=0,scrollbars=1,statusbar=0,menubar=0,resizable=1,height=900,width=600"
41+
},
42+
"reuseWindow": {
43+
"type": "boolean",
44+
"default": true
45+
},
46+
"includeWorkbookParameters": {
47+
"type": "boolean",
48+
"default": true
49+
}
50+
},
51+
"required": [
52+
"icon",
53+
"linkType",
54+
"sortKey",
55+
"windowDetails",
56+
"reuseWindow",
57+
"includeWorkbookParameters"
58+
]
59+
}
60+
},
61+
"required": ["display"]
62+
}
63+
}
64+
]
65+
}

Diff for: build.py

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import sys
2+
import os
3+
import json
4+
import zipfile
5+
import pathlib
6+
import shutil
7+
import argparse
8+
import subprocess
9+
from pathlib import Path
10+
from artifactory import ArtifactoryPath
11+
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument(
14+
'-d', '--distribute',
15+
help='Upload the built files to their distribution channels.',
16+
action='store_true'
17+
)
18+
parser.add_argument(
19+
'-c', '--compile',
20+
help='Produce a compiled version of the code in addition to the source version',
21+
action='store_true'
22+
)
23+
parser.add_argument(
24+
'-a', '--addon',
25+
help='Produce a zipped version for installation through the addon manager.',
26+
action='store_true'
27+
)
28+
args = parser.parse_args()
29+
30+
# build the distribution
31+
distribution_relative_dir = 'dist'
32+
distribution_abs_dir = os.path.join(os.getcwd(), distribution_relative_dir)
33+
if os.path.isdir(distribution_abs_dir):
34+
shutil.rmtree(distribution_abs_dir)
35+
build_command = ['python3.8', 'setup.py', 'bdist_wheel',
36+
'-d', distribution_relative_dir,
37+
f'--python-tag=py{sys.version_info.major}{sys.version_info.minor}']
38+
subprocess.run(build_command, cwd=os.getcwd())
39+
source_wheel = max(
40+
[os.path.join(distribution_abs_dir, f) for f in os.listdir(distribution_abs_dir)],
41+
key=os.path.getctime
42+
)
43+
44+
source_wheel_name = os.path.split(source_wheel)[-1]
45+
version = source_wheel_name.split('-')[1]
46+
47+
compiled_wheel = None
48+
if args.compile:
49+
print('Creating pyc file')
50+
pyc_relative_dir = os.path.join(distribution_relative_dir, 'bin')
51+
pyc_abs_dir = os.path.join(distribution_abs_dir, 'bin')
52+
build_command = [sys.executable, 'setup.py', 'bdist_egg',
53+
'-d', pyc_relative_dir,
54+
'--exclude-source-files',
55+
'-m', '+c']
56+
build_result = subprocess.run(build_command, cwd=os.getcwd(), capture_output=True, text=True)
57+
wheel_command = ['wheel', 'convert', os.path.join(pyc_relative_dir, '*.egg'), '-d', pyc_relative_dir]
58+
wheel_result = subprocess.run(wheel_command, cwd=os.getcwd(), capture_output=True, text=True)
59+
60+
# move the pyc wheel file to the dist dir
61+
path = Path('.')
62+
wheel_file = list(path.glob('**/bin/*.whl'))[0]
63+
wheel_file.rename(Path(wheel_file.parent.parent, wheel_file.name))
64+
compiled_wheel = os.path.join(wheel_file.parent.parent, wheel_file.name)
65+
66+
# remove the bin dir
67+
shutil.rmtree(pyc_abs_dir)
68+
69+
addon_manager_artifacts = []
70+
if args.addon:
71+
name = 'mps'
72+
print(f'Creating {name}.addon')
73+
# Ensure output folder exists
74+
bin = os.path.join(os.getcwd(), 'bin')
75+
if not os.path.exists(bin):
76+
os.makedirs(bin)
77+
78+
with open('addon.json') as json_file:
79+
parsed_json = json.load(json_file)
80+
parsed_json['version'] = version
81+
82+
addon = os.path.join(bin, f'{name}.addon')
83+
addon_meta = os.path.join(bin, f'{name}.addonmeta')
84+
85+
# Build addon
86+
with zipfile.ZipFile(addon, 'w') as z:
87+
z.write(source_wheel, arcname=os.path.join('data-lab-functions', source_wheel_name))
88+
z.writestr('data-lab-functions/requirements.txt', f"./{source_wheel_name}")
89+
with z.open("addon.json", "w") as c:
90+
c.write(json.dumps(parsed_json, indent=2).encode("utf-8"))
91+
directory = pathlib.Path("./seeq/addons/mps/deployment_notebook/")
92+
for file in directory.rglob('*ipynb'):
93+
z.write(file, arcname=os.path.join('data-lab-functions', file.name))
94+
directory = pathlib.Path("./additional_content/")
95+
for file in directory.iterdir():
96+
z.write(file)
97+
addon_manager_artifacts.append(addon)
98+
# Build addonmeta
99+
print(f'Creating {name}.addonmeta')
100+
with zipfile.ZipFile(addon_meta, 'w') as z:
101+
with z.open("addon.json", "w") as c:
102+
c.write(json.dumps(parsed_json, indent=2).encode("utf-8"))
103+
directory = pathlib.Path("./additional_content/")
104+
for file in directory.iterdir():
105+
z.write(file)
106+
addon_manager_artifacts.append(addon_meta)
107+
108+
print('Successfully created.')
109+
110+
if args.distribute:
111+
112+
# THIS BLOCK OF CODE IS NO MORE IN USE BUT COULD LATER BE USED IN FUTURE PURPOSES
113+
# if compiled_wheel is not None:
114+
# print(f'Distributing compiled wheel {compiled_wheel} to pipy.seeq.com')
115+
# command_distribute_compiled = \
116+
# ['twine', 'upload',
117+
# '--repository-url', 'https://pypi.seeq.com',
118+
# '-u', username,
119+
# '-p', password,
120+
# compiled_wheel]
121+
# result = subprocess.run(' '.join(command_distribute_compiled))
122+
# if result.stderr:
123+
# print(f'There was an error uploading the compiled version: {result.stderr}')
124+
#
125+
# print(f'Distributing source wheel {source_wheel} to pypi.seeq.com:8081')
126+
# command_distribute_source = \
127+
# ['twine', 'upload',
128+
# '--repository-url', 'https://pypi.seeq.com:8081',
129+
# '-u', username,
130+
# '-p', password,
131+
# source_wheel]
132+
# result = subprocess.run(' '.join(command_distribute_source))
133+
# if result.stderr:
134+
# print(f'There was an error uploading the source version: {result.stderr}')
135+
136+
if addon_manager_artifacts:
137+
print(f'Distributing addon manager artifacts to seeq.jfrog.io')
138+
api_key = os.getenv('JFROG_API_KEY')
139+
for artifact in addon_manager_artifacts:
140+
_, file = os.path.split(artifact)
141+
path = ArtifactoryPath(f"https://seeq.jfrog.io/artifactory/seeq-add-ons-prod-local/mps/{file}",
142+
apikey=api_key)
143+
try:
144+
path.deploy_file(artifact)
145+
properties = path.properties
146+
# Add identifier property
147+
properties["identifier"] = "com.seeq.addon.mps"
148+
path.properties = properties
149+
except Exception as e:
150+
print(e)

Diff for: requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ wheel~=0.38.1
1515
packaging~=21.0
1616
pytz~=2021.3
1717
setuptools>=65.5.1
18+
dohq-artifactory==0.8.1

Diff for: tests/__pycache__/__init__.cpython-37.pyc

-128 Bytes
Binary file not shown.

Diff for: tests/__pycache__/__init__.cpython-38.pyc

-132 Bytes
Binary file not shown.

Diff for: tests/__pycache__/test_seeqmps.cpython-37-PYTEST.pyc

-3.99 KB
Binary file not shown.

Diff for: tests/__pycache__/test_seeqmps.cpython-38-PYTEST.pyc

-4.15 KB
Binary file not shown.

0 commit comments

Comments
 (0)