forked from CAHLR/pyBKT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py.old
More file actions
155 lines (138 loc) · 6.29 KB
/
setup.py.old
File metadata and controls
155 lines (138 loc) · 6.29 KB
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
#########################################
# setup.py #
# Setup for PyBKT #
# #
# @author Anirudhan Badrinath #
# Last edited: 01 April 2021 #
#########################################
import os
from os.path import normpath as npath
import sys
from sysconfig import get_paths
from setuptools import setup, Extension
import platform
from distutils.command.build_ext import build_ext
sys.tracebacklimit = 0
def _mac_find_libomp():
"""
Return (include_dir, lib_dir) for Homebrew libomp.
Falls back to the default keg location if `brew` is not on PATH.
"""
default = "/opt/homebrew/opt/libomp"
if platform.system() != "Darwin":
return None, None
import subprocess, shutil
if shutil.which("brew"):
try:
prefix = subprocess.check_output(
["brew", "--prefix", "libomp"], text=True
).strip()
except subprocess.CalledProcessError:
prefix = default
else:
prefix = default
inc = os.path.join(prefix, "include")
lib = os.path.join(prefix, "lib")
return inc, lib
class CustomBuildExtCommand(build_ext):
"""build_ext command for use when numpy headers are needed."""
""" https://stackoverflow.com/questions/2379898/make-distutils-look-for-numpy-header-files-in-the-correct-place """
def run(self):
import numpy
self.include_dirs.append(numpy.get_include())
build_ext.run(self)
FILES = {'synthetic_data_helper.cpp': 'source-cpp/pyBKT/generate/',
'predict_onestep_states.cpp': 'source-cpp/pyBKT/fit/',
'E_step.cpp': 'source-cpp/pyBKT/fit/'}
INCLUDE_DIRS = sys.path + ['source-cpp/pyBKT/Eigen/', get_paths()['include']]
LIBRARY_DIRS = [os.environ['LD_LIBRARY_PATH']] if 'LD_LIBRARY_PATH' in os.environ \
else []
if platform.system() == 'Darwin':
ALL_COMPILE_ARGS = [
'-c', '-fPIC', '-w', '-O3',
'-stdlib=libc++', # C++ runtime
'-Xpreprocessor', '-fopenmp' # OpenMP on Apple clang
]
ALL_LINK_ARGS = ['-stdlib=libc++']
ALL_LIBRARIES = ['pthread', 'dl', 'util', 'm', 'omp']
inc, lib = _mac_find_libomp()
if inc and lib:
INCLUDE_DIRS.append(inc)
LIBRARY_DIRS.append(lib)
else:
ALL_COMPILE_ARGS = ['-c', '-fPIC', '-w', '-fopenmp', '-O2']
ALL_LINK_ARGS = ['-fopenmp']
ALL_LIBRARIES = ['pthread', 'dl', 'util', 'm']
def clean():
global LIBRARY_DIRS, ALL_LIBRARIES
LIBRARY_DIRS = [i for i in LIBRARY_DIRS if i != ""]
ALL_LIBRARIES = [i for i in ALL_LIBRARIES if i != ""]
with open('README.md', encoding='utf-8') as f:
long_description = f.read()
LIBRARY_DIRS += [sys.exec_prefix + '/lib']
clean()
try:
module1 = Extension('pyBKT/generate/synthetic_data_helper',
sources = [npath('source-cpp/pyBKT/generate/synthetic_data_helper.cpp')],
include_dirs = INCLUDE_DIRS,
extra_compile_args = ALL_COMPILE_ARGS,
library_dirs = LIBRARY_DIRS,
libraries = ALL_LIBRARIES,
extra_link_args = ALL_LINK_ARGS)
module2 = Extension('pyBKT/fit/E_step',
sources = [npath('source-cpp/pyBKT/fit/E_step.cpp')],
include_dirs = INCLUDE_DIRS,
extra_compile_args = ALL_COMPILE_ARGS,
library_dirs = LIBRARY_DIRS,
libraries = ALL_LIBRARIES,
extra_link_args = ALL_LINK_ARGS)
module3 = Extension('pyBKT/fit/predict_onestep_states',
sources = [npath('source-cpp/pyBKT/fit/predict_onestep_states.cpp')],
include_dirs = INCLUDE_DIRS,
extra_compile_args = ALL_COMPILE_ARGS,
library_dirs = LIBRARY_DIRS,
libraries = ALL_LIBRARIES,
extra_link_args = ALL_LINK_ARGS)
setup(
# same as before...
ext_modules = [module1, module2, module3],
cmdclass = {'build_ext': CustomBuildExtCommand},
)
except Exception as e:
print("ERROR: Failed to build the C++ extensions for pyBKT.")
print("Details:")
import traceback
traceback.print_exc()
if os.environ.get("PYBKT_ALLOW_PYTHON_FALLBACK", "0") == "1":
print("\n⚠️ Falling back to pure Python version (legacy, slower)...")
setup(
name="pyBKT",
version="1.4.1",
author="Zachary Pardos, Anirudhan Badrinath, Matthew Jade Johnson, Christian Garay",
author_email="zp@berkeley.edu, abadrinath@berkeley.edu, mattjj@csail.mit.edu, c.garay@berkeley.edu",
license = 'MIT',
description="PyBKT - Python Implentation of Bayesian Knowledge Tracing",
url="https://github.com/CAHLR/pyBKT",
download_url = 'https://github.com/CAHLR/pyBKT/archive/1.0.tar.gz',
keywords = ['BKT', 'Bayesian Knowledge Tracing', 'Bayesian Network', 'Hidden Markov Model', 'Intelligent Tutoring Systems', 'Adaptive Learning'],
classifiers=[
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
long_description = long_description,
long_description_content_type='text/markdown',
packages=['pyBKT', 'pyBKT.generate', 'pyBKT.fit', 'pyBKT.util', 'pyBKT.models'],
package_dir = { 'pyBKT': npath('source-py/pyBKT'),
'pyBKT.generate': npath('source-py/pyBKT/generate'),
'pyBKT.fit': npath('source-py/pyBKT/fit'),
'pyBKT.util': npath('source-py/pyBKT/util'),
'pyBKT.models': npath('source-py/pyBKT/models')},
install_requires = ["numpy", "scikit-learn", "pandas", "requests"],
)
else:
print("\n❌ Set PYBKT_ALLOW_PYTHON_FALLBACK=1 if you want to install the pure Python fallback.")
sys.exit(1)