forked from rigdenlab/conkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
193 lines (164 loc) · 5.55 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
"""Python Interface for Residue-Residue Contact Predictions"""
import os
import sys
from distutils.command.build import build
from distutils.util import convert_path
from setuptools import setup, Extension
from Cython.Distutils import build_ext
import numpy as np
# ==============================================================
# Setup.py command extensions
# ==============================================================
# Credits to http://stackoverflow.com/a/33181352
class BuildCommand(build):
user_options = build.user_options + [
("script-python-path=", None, "Path to Python interpreter to be included in the scripts")
]
def initialize_options(self):
build.initialize_options(self)
self.script_python_path = None
def finalize_options(self):
build.finalize_options(self)
def run(self):
global script_python_path
script_python_path = self.script_python_path
build.run(self)
# ==============================================================
# Functions, functions, functions ...
# ==============================================================
def dependencies():
with open("requirements.txt", "r") as f_in:
deps = f_in.read().splitlines()
return deps
def extensions():
exts = ["conkit/core/ext/c_contactmap.pyx", "conkit/core/ext/c_sequencefile.pyx", "conkit/misc/ext/c_bandwidth.pyx"]
extensions = []
for ext in exts:
extensions.append(
Extension(
ext.replace('/', '.').rsplit('.', 1)[0],
[ext],
include_dirs=[np.get_include()],
))
return extensions
def readme():
with open("README.rst", "r") as f_in:
return f_in.read()
def scripts():
extension = ".bat" if sys.platform.startswith("win") else ""
header = "" if sys.platform.startswith("win") else "#!/bin/sh"
bin_dir = "bin"
command_dir = convert_path("conkit/command_line")
scripts = []
for file in os.listdir(command_dir):
if not file.startswith("_") and file.endswith(".py"):
# Make sure we have a workable name
f_name = os.path.basename(file).rsplit(".", 1)[0]
for c in [".", "_"]:
new_f_name = f_name.replace(c, "-")
# Write the content of the script
script = os.path.join(bin_dir, new_f_name + extension)
with open(script, "w") as f_out:
f_out.write(header + os.linesep)
# BATCH file
if sys.platform.startswith("win"):
string = "@{0} -m conkit.command_line.{1} %*"
# BASH file
else:
string = '{0} -m conkit.command_line.{1} "$@"'
f_out.write(string.format(PYTHON_EXE, f_name) + os.linesep)
os.chmod(script, 0o777)
scripts.append(script)
return scripts
def version():
# Credits to http://stackoverflow.com/a/24517154
main_ns = {}
ver_path = convert_path("conkit/version.py")
with open(ver_path) as f_in:
exec(f_in.read(), main_ns)
return main_ns["__version__"]
# ==============================================================
# Determine the Python executable
# ==============================================================
PYTHON_EXE = None
for arg in sys.argv:
if arg[0:20] == "--script-python-path" and len(arg) == 20:
option, value = arg, sys.argv[sys.argv.index(arg) + 1]
PYTHON_EXE = value
elif arg[0:20] == "--script-python-path" and arg[20] == "=":
option, value = arg[:20], arg[21:]
PYTHON_EXE = value
if not PYTHON_EXE:
PYTHON_EXE = sys.executable
# ==============================================================
# Define all the relevant options
# ==============================================================
AUTHOR = "Felix Simkovic"
AUTHOR_EMAIL = "[email protected]"
DESCRIPTION = __doc__.replace("\n", "")
DEPENDENCIES = dependencies()
EXT_MODULES = extensions()
LICENSE = "BSD License"
LONG_DESCRIPTION = readme()
PACKAGE_DIR = "conkit"
PACKAGE_NAME = "conkit"
PLATFORMS = ["POSIX", "Mac OS", "Windows", "Unix"]
SCRIPTS = scripts()
URL = "http://www.conkit.org/en/latest/"
VERSION = version()
PACKAGES = [
"conkit",
"conkit/applications",
"conkit/command_line",
"conkit/core",
"conkit/core/ext",
"conkit/io",
"conkit/misc",
"conkit/misc/ext",
"conkit/plot",
]
CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
TEST_REQUIREMENTS = [
"codecov",
"coverage",
"pytest",
"pytest-cov",
"pytest-pep8",
"pytest-helpers-namespace",
]
setup(
cmdclass={
'build': BuildCommand,
'build_ext': build_ext,
},
author=AUTHOR,
author_email=AUTHOR_EMAIL,
name=PACKAGE_NAME,
description=DESCRIPTION,
ext_modules=EXT_MODULES,
include_dirs=[np.get_include()],
long_description=LONG_DESCRIPTION,
license=LICENSE,
version=VERSION,
url=URL,
packages=PACKAGES,
package_dir={PACKAGE_NAME: PACKAGE_DIR},
scripts=SCRIPTS,
platforms=PLATFORMS,
classifiers=CLASSIFIERS,
install_requires=DEPENDENCIES,
tests_require=TEST_REQUIREMENTS,
setup_requires=['pytest-runner'],
include_package_data=True,
zip_safe=False,
)