Skip to content

Commit

Permalink
Add dependency install checks for Cython (#548)
Browse files Browse the repository at this point in the history
* Added validation for numpy import

* changed var due to deprecation notice

* Added required dependency checks

* update readme

* exit with install message

---------

Co-authored-by: tqtg <tuantq.vnu@gmail.com>
  • Loading branch information
darrylong and tqtg committed Nov 27, 2023
1 parent 98ccb80 commit 2bdae6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
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

0 comments on commit 2bdae6d

Please sign in to comment.