Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependency install checks for Cython #548

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Currently, we are supporting Python 3. There are several ways to install Cornac:

- **From the GitHub source (for latest updates):**
```bash
pip3 install Cython numpy scipy
pip3 install git+https://github.com/PreferredAI/cornac.git
```

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
61 changes: 30 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
import glob
from setuptools import Extension, setup, find_packages

import numpy as np

try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy as np
import scipy
except ImportError:
USE_CYTHON = False
else:
USE_CYTHON = True
exit(
"We need some dependencies to build Cornac.\n"
+ "Run: pip3 install Cython numpy scipy"
)


with open("README.md", "r") as fh:
Expand Down Expand Up @@ -107,13 +108,12 @@ def extract_gcc_binaries():
compile_args.append("-std=c++11")
link_args.append("-std=c++11")

ext = ".pyx" if USE_CYTHON else ".cpp"

extensions = [
Extension(
name="cornac.models.c2pf.c2pf",
sources=[
"cornac/models/c2pf/cython/c2pf" + ext,
"cornac/models/c2pf/cython/c2pf.pyx",
"cornac/models/c2pf/cpp/cpp_c2pf.cpp",
],
include_dirs=[
Expand All @@ -125,29 +125,29 @@ def extract_gcc_binaries():
),
Extension(
name="cornac.models.nmf.recom_nmf",
sources=["cornac/models/nmf/recom_nmf" + ext],
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" + ext],
sources=["cornac/models/pmf/cython/pmf.pyx"],
language="c++",
),
Extension(
name="cornac.models.mcf.mcf",
sources=["cornac/models/mcf/cython/mcf" + ext],
sources=["cornac/models/mcf/cython/mcf.pyx"],
language="c++",
),
Extension(
name="cornac.models.sorec.sorec",
sources=["cornac/models/sorec/cython/sorec" + ext],
sources=["cornac/models/sorec/cython/sorec.pyx"],
language="c++",
),
Extension(
"cornac.models.hpf.hpf",
sources=[
"cornac/models/hpf/cython/hpf" + ext,
"cornac/models/hpf/cython/hpf.pyx",
"cornac/models/hpf/cpp/cpp_hpf.cpp",
],
include_dirs=[
Expand All @@ -159,112 +159,112 @@ def extract_gcc_binaries():
),
Extension(
name="cornac.models.mf.backend_cpu",
sources=["cornac/models/mf/backend_cpu" + ext],
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" + ext],
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" + ext],
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" + ext],
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" + ext],
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" + ext],
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" + ext],
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" + ext],
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" + ext],
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.comparer.recom_comparer_sub",
sources=["cornac/models/comparer/recom_comparer_sub" + ext],
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" + ext],
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" + ext],
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" + ext],
sources=["cornac/utils/fast_dict.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Extension(
name="cornac.utils.fast_dot",
sources=["cornac/utils/fast_dot" + ext],
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" + ext],
sources=["cornac/utils/fast_sparse_funcs.pyx"],
include_dirs=[np.get_include()],
language="c++",
),
Expand All @@ -274,7 +274,7 @@ def extract_gcc_binaries():
extensions += [
Extension(
name="cornac.models.fm.recom_fm",
sources=["cornac/models/fm/recom_fm" + ext],
sources=["cornac/models/fm/recom_fm.pyx"],
include_dirs=[
np.get_include(),
"cornac/models/fm/libfm/util",
Expand All @@ -290,9 +290,8 @@ def extract_gcc_binaries():
cmdclass = {}

# cythonize c++ modules
if USE_CYTHON:
extensions = cythonize(extensions)
cmdclass.update({"build_ext": build_ext})
extensions = cythonize(extensions)
cmdclass.update({"build_ext": build_ext})

setup(
name="cornac",
Expand Down
Loading