-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.py
298 lines (243 loc) · 9.25 KB
/
setup.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import os
import sys
import platform
# import sire in mixed_api compatibility mode
try:
import sire as _sr
_sr.use_mixed_api()
except ImportError:
# a new version of sire is not installed
pass
# Allow setting on the command line because setting
# environment variables on Windows is painful!
if "BSS_SKIP_DEPENDENCIES=1" in sys.argv:
os.environ["BSS_SKIP_DEPENDENCIES"] = "1"
sys.argv.remove("BSS_SKIP_DEPENDENCIES=1")
if "BSS_CONDA_INSTALL=1" in sys.argv:
os.environ["BSS_CONDA_INSTALL"] = "1"
sys.argv.remove("BSS_CONDA_INSTALL=1")
if not os.getenv("BSS_CONDA_INSTALL"):
# Set the minimum allowed Sire version.
min_ver = "2023.0.0"
min_ver_int = int(min_ver.replace(".", ""))
# Make sure we're using the Sire python interpreter.
try:
import sire.legacy.Base
bin_dir = sire.legacy.Base.getBinDir()
lib_dir = sire.legacy.Base.getLibDir()
except ModuleNotFoundError:
raise ModuleNotFoundError(
"BioSimSpace currently requires the Sire Python interpreter: www.siremol.org"
)
# Check the Sire version.
if int(sire.legacy.__version__.replace(".", "")) < min_ver_int:
raise ImportError("BioSimSpace requires Sire version '%s' or above." % min_ver)
from setuptools import setup, find_packages
import versioneer
# A list of authors and their email addresses.
authors = (
"Lester Hedges <lester.hedges@gmail.com, "
"Christopher Woods <chryswoods@gmail.com>, "
"Antonia Mey <antonia.mey@gmail.com"
)
_installed_list = None
# Function to check if a conda dependency has been installed
def is_installed(dep: str, conda: str):
global _installed_list
if _installed_list is None:
p = subprocess.Popen([conda, "list", dep], stdout=subprocess.PIPE)
lines = str(p.stdout.read())
_installed_list = lines
return _installed_list.find(dep) != -1
# Function to clear the cache of installed packages
def clear_installed_list():
global _installed_list
_installed_list = None
# Run the setup.
try:
setup(
name="BioSimSpace",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
description="BioSimSpace: Making biomolecular simulation a breeze.",
author=authors,
url="https://github.com/michellab/BioSimSpace",
license="GPLv2",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
)
# Post setup configuration.
finally:
import os
if "install" in sys.argv and not (
os.getenv("BSS_CONDA_INSTALL") or os.getenv("BSS_SKIP_DEPENDENCIES")
):
import shlex
import subprocess
# Install Python dependencies and enable Jupyter widget extensions.
print("\nSetting up python environment...")
# Open files for stdout/stderr.
stdout = sys.stdout
stderr = sys.stderr
# Create a list of the conda dependencies.
conda_deps = [
"configargparse",
"pygtail",
"pyyaml",
"watchdog",
"pydot",
"networkx",
"nglview",
"ipywidgets<8",
"py3dmol",
"pypdb",
"rdkit",
"parmed",
"lomap2",
"mdtraj", # known not available on aarch64
"mdanalysis", # known not available on aarch64
"openff-toolkit", # known not available on aarch64
]
# Don't try to install things that are already installed...
to_install_deps = []
print("Checking for dependencies that are already installed...")
if sys.platform == "win32":
conda_exe = os.path.join(bin_dir, "Scripts", "mamba.exe")
real_conda_exe = os.path.join(bin_dir, "Scripts", "conda.exe")
if not os.path.exists(conda_exe):
conda_exe = real_conda_exe
else:
conda_exe = os.path.join(bin_dir, "mamba")
real_conda_exe = os.path.join(bin_dir, "conda")
if not os.path.exists(conda_exe):
# This could be in an environment
conda_exe = os.path.join(bin_dir, "..", "..", "..", "bin", "mamba")
real_conda_exe = os.path.join(bin_dir, "..", "..", "..", "bin", "conda")
if not os.path.exists(conda_exe):
if not os.path.exists(real_conda_exe):
real_conda_exe = os.path.join(bin_dir, "conda")
conda_exe = real_conda_exe
for dep in conda_deps:
if not is_installed(dep, conda=conda_exe):
to_install_deps.append(dep)
print(f"Need to install {dep}")
else:
print("Already installed %s" % dep)
clear_installed_list()
conda_deps = to_install_deps
# Need to not use posix rules on windows with shlex.split, or path separator is escaped
posix = sys.platform != "win32"
print("Adding conda-forge channel")
command = "%s config --system --prepend channels conda-forge" % real_conda_exe
print(command)
try:
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
)
except Exception as e:
print(f"Something went wrong ({e}). Continuing regardless...")
print("Disabling conda auto update")
command = "%s config --system --set auto_update_conda false" % real_conda_exe
print(command)
try:
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
)
except Exception as e:
print(f"Something went wrong ({e}). Continuing regardless...")
print("Installing conda dependencies: %s" % ", ".join(conda_deps))
command = "%s install -y -q %s" % (conda_exe, " ".join(conda_deps))
print(command)
all_installed_ok = True
try:
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
check=True,
)
except Exception:
all_installed_ok = False
if not all_installed_ok:
print("There were errors installing some of the dependencies.")
print(
"We will now try to install them one-by-one. This may take some time..."
)
failures = []
for dep in conda_deps:
if not is_installed(dep, conda=conda_exe):
print("Trying again to install '%s'" % dep)
command = "%s install -y -q %s" % (conda_exe, dep)
try:
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
check=True,
)
except Exception:
failures.append(dep)
if len(failures) == 0:
print("All dependencies installed successfully!")
else:
print(
"\n** Failed to install these dependencies: %s"
% ", ".join(failures)
)
print(
"** BioSimSpace will still install and run, but some functionality may not be available.\n"
)
else:
print("All dependencies install successfully first time!")
print("Activating notebook extension: nglview")
if sys.platform == "win32":
bin_dir = os.path.join(bin_dir, "Scripts")
command = (
"%s/jupyter-nbextension install nglview --py --sys-prefix --log-level=0"
% bin_dir
)
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
)
command = "%s/jupyter-nbextension enable nglview --py --sys-prefix" % bin_dir
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
)
print("Cleaning conda environment")
command = "%s clean --all --yes --quiet" % conda_exe
subprocess.run(
shlex.split(command, posix=posix),
shell=False,
stdout=stdout,
stderr=stderr,
)
# We can't install BioSimSpace here because it confuses the Sire old/new/mixed API
# try:
# import BioSimSpace
# except:
# print("\nPossible installation issues.")
# sys.exit()
print("\nDone!")
print(
"\nIf you have problems with Jupyter permissions, try removing '$HOME/.jupyter' or '$HOME/.local/share/jupyter'"
)
print("\nFor optional package support...")
print("AMBER: http://ambermd.org")
print("GROMACS: http://www.gromacs.org")
print("NAMD: http://www.ks.uiuc.edu/Research/namd")
print("FKCOMBU: https://pdbj.org/kcombu")