forked from aschein/prgpmf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
111 lines (88 loc) · 3.02 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
import os
import sys
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import numpy as np
from path import Path
# if sys.platform == 'darwin':
# os.environ['CC'] = 'gcc-8'
# os.environ['CXX'] = 'g++-8'
# include_gsl_dir = '/usr/local/include/'
# lib_gsl_dir = '/usr/local/lib/'
# EXT_MODULES = [Extension(name=str(x.relpath()).replace('/', '.').split('.pyx')[0],
# sources=[str(x.relpath())],
# include_dirs=[np.get_include(),
# include_gsl_dir,
# '.'],
# library_dirs=[lib_gsl_dir],
# libraries=['gsl'],
# extra_compile_args=['-fopenmp'],
# extra_link_args=['-fopenmp'])
# for x in Path('.').walkfiles('*.pyx')]
# setup(name='apf',
# version='1.0',
# description='Allocative Poisson Factorization (APF) framework and examples.',
# author='Aaron Joseph Steriade Schein',
# # packages=['base', 'models', 'tests', 'foo'],
# cmdclass={"build_ext": build_ext},
# ext_modules=cythonize(EXT_MODULES,
# compiler_directives={'language_level':'3'})) # fails if set to 3
# if sys.platform == 'darwin':
# os.environ['CC'] = '/anaconda3/bin/gcc'
# os.environ['CXX'] = '/anaconda3/bin/g++'
include_gsl_dir = '/usr/local/include/'
lib_gsl_dir = '/usr/local/lib/'
def get_pkgs_and_exts(dir='.'):
"""
src/
Makefile
setup.py
__init__.py
base.pyx
first_pkg/
__init__.py
core.pyx
things/
__init__.py
foo.pyx
foo.pxd
second_pkg/
__init__.py
core.pyx
get_pkgs_and_exts()
>>> [...], [first_pkg, first_pkg.things, second_pkg]
Inspired by:
https://github.com/cython/cython/wiki/PackageHierarchy
"""
pkgs = set()
exts = list()
for ext_path in Path(dir).walkfiles('*.pyx'):
ext_name = ext_path.namebase
subdirs = ext_path.splitall()[1:-1]
if subdirs:
pkg = '.'.join(subdirs)
pkgs.add(pkg)
ext_name = pkg + '.' + ext_name
exts.append(make_extension(ext_name, ext_path))
return list(pkgs), exts
def make_extension(ext_name, ext_path=None):
if ext_path is None:
ext_path = Path.joinpath(*ext_name.split('.')) + '.pyx'
assert Path(ext_path).isfile()
return Extension(name=ext_name,
sources=[ext_path],
include_dirs=[np.get_include(),
include_gsl_dir],
library_dirs=[lib_gsl_dir],
libraries=['gsl'],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'])
pkgs, exts = get_pkgs_and_exts()
setup(name='apf',
version='1.0',
description='Allocative Poisson Factorization (APF) framework and examples.',
author='Aaron Joseph Steriade Schein',
packages=pkgs,
ext_modules=cythonize(exts))