-
Notifications
You must be signed in to change notification settings - Fork 148
/
setup.py
377 lines (343 loc) · 12.1 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# Copyright 2018 The Cornac Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""
Release instruction:
- Check that tests run correctly with all CI tools.
- Change __version__ in setup.py, cornac/__init__.py, docs/source/conf.py.
- Commit and release a version on GitHub, Actions will be triggered to build and upload to PyPI.
- Update conda-forge feedstock with new version and SHA256 hash of the new .tar.gz archive on PyPI (optional), the conda-forge bot will detect a new version and create PR after a while.
- Check on https://anaconda.org/conda-forge/cornac that new version is available for all platforms.
"""
import os
import sys
import glob
import shutil
from setuptools import Extension, Command, setup, find_packages
INSTALL_REQUIRES = ["numpy<2.0.0", "scipy<=1.13.1", "tqdm", "powerlaw"]
try:
from Cython.Distutils import build_ext
import numpy as np
import scipy
except ImportError:
escape_dependency_version = lambda x: '"{}"'.format(x) if "<" in x or "=" in x or ">" in x else x
exit(
"We need some dependencies to build Cornac.\n"
+ "Run: pip3 install Cython {}".format(" ".join([escape_dependency_version(x) for x in INSTALL_REQUIRES]))
)
with open("README.md", "r") as fh:
long_description = fh.read()
USE_OPENMP = True
def extract_gcc_binaries():
"""Try to find GCC on OSX for OpenMP support."""
patterns = [
"/opt/local/bin/g++-mp-[0-9].[0-9]",
"/opt/local/bin/g++-mp-[0-9]",
"/usr/local/bin/g++-[0-9].[0-9]",
"/usr/local/bin/g++-[0-9]",
]
if sys.platform.startswith("darwin"):
gcc_binaries = []
for pattern in patterns:
gcc_binaries += glob.glob(pattern)
gcc_binaries.sort()
if gcc_binaries:
_, gcc = os.path.split(gcc_binaries[-1])
return gcc
else:
return None
else:
return None
if sys.platform.startswith("win"):
# compile args from
# https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx
compile_args = ["/O2", "/openmp"]
link_args = []
else:
gcc = extract_gcc_binaries()
if gcc is not None:
rpath = "/usr/local/opt/gcc/lib/gcc/" + gcc[-1] + "/"
link_args = ["-Wl,-rpath," + rpath]
else:
link_args = []
compile_args = [
"-Wno-unused-function",
"-Wno-maybe-uninitialized",
"-O3",
"-ffast-math",
]
if sys.platform.startswith("darwin"):
if gcc is not None:
os.environ["CC"] = gcc
os.environ["CXX"] = gcc
else:
if not os.path.exists("/usr/bin/g++"):
print(
"No GCC available. Install gcc from Homebrew using brew install gcc."
)
USE_OPENMP = False
# required arguments for default gcc of OSX
compile_args.extend(["-O2", "-stdlib=libc++", "-mmacosx-version-min=10.7"])
link_args.extend(["-O2", "-stdlib=libc++", "-mmacosx-version-min=10.7"])
if USE_OPENMP:
compile_args.append("-fopenmp")
link_args.append("-fopenmp")
compile_args.append("-std=c++11")
link_args.append("-std=c++11")
extensions = [
Extension(
name="cornac.models.c2pf.c2pf",
sources=[
"cornac/models/c2pf/cython/c2pf.pyx",
"cornac/models/c2pf/cpp/cpp_c2pf.cpp",
],
include_dirs=[
"cornac/models/c2pf/cpp/",
"cornac/utils/external/eigen/Eigen",
"cornac/utils/external/eigen/unsupported/Eigen/",
],
language="c++",
),
Extension(
name="cornac.models.nmf.recom_nmf",
sources=["cornac/models/nmf/recom_nmf.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Extension(
name="cornac.models.pmf.pmf",
sources=["cornac/models/pmf/cython/pmf.pyx"],
language="c++",
),
Extension(
name="cornac.models.mcf.mcf",
sources=["cornac/models/mcf/cython/mcf.pyx"],
language="c++",
),
Extension(
name="cornac.models.sorec.sorec",
sources=["cornac/models/sorec/cython/sorec.pyx"],
language="c++",
),
Extension(
"cornac.models.hpf.hpf",
sources=[
"cornac/models/hpf/cython/hpf.pyx",
"cornac/models/hpf/cpp/cpp_hpf.cpp",
],
include_dirs=[
"cornac/models/hpf/cpp/",
"cornac/utils/external/eigen/Eigen",
"cornac/utils/external/eigen/unsupported/Eigen/",
],
language="c++",
),
Extension(
name="cornac.models.mf.backend_cpu",
sources=["cornac/models/mf/backend_cpu.pyx"],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.baseline_only.recom_bo",
sources=["cornac/models/baseline_only/recom_bo.pyx"],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.efm.recom_efm",
sources=["cornac/models/efm/recom_efm.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Extension(
name="cornac.models.comparer.recom_comparer_obj",
sources=["cornac/models/comparer/recom_comparer_obj.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Extension(
name="cornac.models.bpr.recom_bpr",
sources=["cornac/models/bpr/recom_bpr.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.bpr.recom_wbpr",
sources=["cornac/models/bpr/recom_wbpr.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.sbpr.recom_sbpr",
sources=["cornac/models/sbpr/recom_sbpr.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.lrppm.recom_lrppm",
sources=["cornac/models/lrppm/recom_lrppm.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.mter.recom_mter",
sources=["cornac/models/mter/recom_mter.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.companion.recom_companion",
sources=["cornac/models/companion/recom_companion.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.comparer.recom_comparer_sub",
sources=["cornac/models/comparer/recom_comparer_sub.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.mmmf.recom_mmmf",
sources=["cornac/models/mmmf/recom_mmmf.pyx"],
include_dirs=[np.get_include(), "cornac/utils/external"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.models.knn.similarity",
sources=["cornac/models/knn/similarity.pyx"],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.utils.fast_dict",
sources=["cornac/utils/fast_dict.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Extension(
name="cornac.utils.fast_dot",
sources=["cornac/utils/fast_dot.pyx"],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
name="cornac.utils.fast_sparse_funcs",
sources=["cornac/utils/fast_sparse_funcs.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
]
if sys.platform.startswith("linux"): # Linux supported only
extensions += [
Extension(
name="cornac.models.fm.backend_libfm",
sources=["cornac/models/fm/backend_libfm.pyx"],
include_dirs=[
np.get_include(),
"cornac/models/fm/libfm/util/",
"cornac/models/fm/libfm/fm_core/",
"cornac/models/fm/libfm/libfm/src/",
],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
)
]
class CleanCommand(Command):
description = "Remove build artifacts from the source tree"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Remove .cpp and .so files for a clean build
if os.path.exists("build"):
shutil.rmtree("build")
for dirpath, dirnames, filenames in os.walk("cornac"):
for filename in filenames:
root, extension = os.path.splitext(filename)
if extension in [".so", ".pyd", ".dll", ".pyc"]:
os.unlink(os.path.join(dirpath, filename))
if extension in [".c", ".cpp"]:
pyx_file = str.replace(filename, extension, ".pyx")
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == "__pycache__":
shutil.rmtree(os.path.join(dirpath, dirname))
cmdclass = {
"clean": CleanCommand,
"build_ext": build_ext,
}
setup(
name="cornac",
version="2.3.0",
description="A Comparative Framework for Multimodal Recommender Systems",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://cornac.preferred.ai",
keywords=[
"recommender system",
"collaborative filtering",
"multimodal",
"preference learning",
"recommendation",
],
ext_modules=extensions,
install_requires=INSTALL_REQUIRES,
extras_require={"tests": ["pytest", "pytest-pep8", "pytest-xdist", "pytest-cov", "Flask"]},
cmdclass=cmdclass,
packages=find_packages(),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
],
)