-
Notifications
You must be signed in to change notification settings - Fork 69
/
setup.py
120 lines (110 loc) · 3.31 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
import glob
import logging
import os
import platform
import sys
from pathlib import Path
import numpy as np
import tomli
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from setuptools import Extension, find_packages, setup
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 platform.system() == "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
else:
return
if sys.platform.startswith("win"):
compile_args = ["/O2", "/openmp"]
link_args = []
else:
use_openmp = True
compile_args = [
"-Wno-unused-function",
"-Wno-maybe-uninitialized",
"-O3",
"-ffast-math",
]
link_args = []
if sys.platform.startswith("darwin"):
gcc = extract_gcc_binaries()
if gcc is not None:
logging.info(f"gcc on macOS: {gcc}")
os.environ["CC"] = gcc
os.environ["CXX"] = gcc
else:
use_openmp = False
logging.warning(
"No GCC available. Install gcc from Homebrew: brew install gcc."
)
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(
"libreco.algorithms._bpr",
[os.path.join("libreco", "algorithms", "_bpr.pyx")],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
"libreco.algorithms._als",
[os.path.join("libreco", "algorithms", "_als.pyx")],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
Extension(
"libreco.utils._similarities",
[os.path.join("libreco", "utils", "_similarities.pyx")],
include_dirs=[np.get_include()],
language="c++",
extra_compile_args=compile_args,
extra_link_args=link_args,
),
]
# copy metadata from pyproject.toml
readme = (Path(__file__).parent / "README.md").read_text()
toml_str = (Path(__file__).parent / "pyproject.toml").read_text()
metadata = tomli.loads(toml_str)["project"]
setup(
name=metadata["name"],
version=metadata["version"],
description=metadata["description"],
author=metadata["authors"][0]["name"],
author_email=metadata["authors"][0]["email"],
license=metadata["license"]["text"],
url=metadata["urls"]["repository"],
long_description=readme,
long_description_content_type="text/markdown",
classifiers=metadata["classifiers"],
keywords=metadata["keywords"],
packages=find_packages(
where=".",
include=["libreco*", "libserving*"],
exclude=["test*", "examples"],
),
include_package_data=True,
ext_modules=cythonize(extensions),
cmdclass={"build_ext": build_ext},
)