forked from xianqiangsun/openmm_orion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
220 lines (163 loc) · 5.37 KB
/
tasks.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# (C) 2019 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.
import os
import copy
import shutil
from invoke import task, run
from json import loads, dump
from glob import iglob
from importlib.machinery import SourceFileLoader
import importlib
import MDOrion
PACKAGE_DIR = os.path.dirname(os.path.dirname(MDOrion.__file__))
FLOES_DIR = os.path.join(PACKAGE_DIR, "floes")
@task
def flake8(ctx):
run("flake8 MDOrion")
@task
def test_cubes(ctx):
"""
run cube tests
"""
clean(ctx)
run("py.test -s -v -m 'local'")
@task
def test_floes(ctx, test="all"):
"""
run tests
"""
clean(ctx)
if test == "all":
run("py.test -s -v ./tests ")
else:
run("""py.test -s -v -m "{}" ./tests """.format(test))
@task
def test_orion(ctx, profile="", test="orion"):
"""
run tests
"""
clean(ctx)
if profile is "":
if "ORION_PROFILE" in os.environ:
profile = os.getenv("ORION_PROFILE")
else:
profile = 'default'
print("Using Orion Profile: {}".format(profile))
if test == "all":
run("ORION_PROFILE={} py.test -s -v --orion ./tests".format(profile))
else:
run("""ORION_PROFILE={} py.test -s -v --orion --no-cleanup -m "{}" ./tests""".format(profile, test))
@task
def version(ctx):
print(MDOrion.__version__)
@task
def setversion(ctx, new_version):
"""
Set the package version
"""
# clean(ctx)
fn = os.path.join("./MDOrion", "__init__.py")
with open(fn, "r") as f:
lines = f.readlines()
lines = ["__version__ = '{}'\n".format(new_version) if '__version__' in line else line for line in lines]
with open(fn, "w") as f:
f.writelines(lines)
spec = loads(open('manifest.json', 'r').read())
importlib.reload(MDOrion)
spec['version'] = MDOrion.__version__
dump(spec, open('manifest.json', 'w'), sort_keys=True, indent=4)
@task
def release(ctx):
"""
Create a package for the distribution. All the floes where
the release variable is set to True are included in the package
"""
# clean(ctx)
# Un-wanted Package list
pkg_un = ['OpenEye-Artemis', 'OpenEye-floe-pkg-tools']
with open(os.path.join(PACKAGE_DIR, "requirements_dev.txt"), "r") as f:
requirements_lines = f.readlines()
original_requirements = copy.deepcopy(requirements_lines)
for idx in range(0, len(requirements_lines)):
for pkg in pkg_un:
if pkg in requirements_lines[idx]:
requirements_lines[idx] = "# " + requirements_lines[idx]
with open("requirements_dev.txt", "w") as f:
f.writelines(requirements_lines)
run("python setup.py sdist")
with open("requirements_dev.txt", "w") as f:
f.writelines(original_requirements)
@task
def docs(ctx):
clean_docs(ctx)
curdir = os.getcwd()
run('cube_doc MDOrion docs/source')
run('floe_doc "MDOrion Floes" floes docs/source')
os.chdir('docs')
run("make html")
os.chdir(curdir)
# @task
# def make_package_docs(ctx):
# docs(ctx)
# run("make_package_docs docs/build/html/cubes")
@task
def clean(ctx):
"""
Clean up doc and package builds
"""
clean_pyc(ctx)
clean_docs(ctx)
clean_pycache(ctx)
shutil.rmtree("dist", ignore_errors=True)
shutil.rmtree("build", ignore_errors=True)
egg_path = "{}.egg-info".format("OpenEye_MD_Floes".replace("-", "_"))
if os.path.isfile(egg_path):
os.remove(egg_path)
elif os.path.isdir(egg_path):
shutil.rmtree(egg_path)
shutil.rmtree(".pytest_cache", ignore_errors=True)
@task
def clean_pyc(ctx):
"""
cleans out .pyc files
"""
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".pyc"):
filename = os.path.join(root, file)
if os.path.exists(filename):
os.unlink(filename)
@task
def clean_pycache(ctx):
"""
cleans out __pycache__ dirs
"""
for dirpath, dirs, files in os.walk(os.getcwd()):
for dir in dirs:
if dir == '__pycache__':
del_dir = os.path.join(dirpath, dir)
shutil.rmtree(del_dir)
@task
def clean_docs(ctx):
if os.path.isdir("docs/build"):
shutil.rmtree("docs/build")
if os.path.isdir("docs/build/doctrees"):
shutil.rmtree("docs/build/doctrees")
if os.path.isdir("docs/source/cubes"):
shutil.rmtree("docs/source/cubes")
if os.path.isdir("docs/source/floes"):
shutil.rmtree("docs/source/floes")