-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
80 lines (67 loc) · 1.83 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
import os
import subprocess
import sys
from pathlib import Path
import numpy as np
import pyarrow as pa
from Cython.Build import cythonize
from setuptools import Extension, setup
def get_pg_info():
def run(x):
return subprocess.check_output(["pg_config", x]).decode().strip()
return {k: run("--" + k) for k in ("version", "includedir", "libdir")}
pa.create_library_symlinks()
include_dirs = ["include", "src", pa.get_include(), np.get_include()]
library_dirs = pa.get_library_dirs()
try:
pg_config = get_pg_info()
include_dirs.append(pg_config["includedir"])
library_dirs.append(pg_config["libdir"])
except Exception:
print("pg_config not found in PATH")
macros = [("_GLIBCXX_USE_CXX11_ABI", "0")]
if os.environ.get("CONDA_BUILD"):
macros = None
cflags = {
"win32": ["/std:c++latest"],
"darwin": ["-std=c++17", "-mmacosx-version-min=10.14"],
"linux": ["-std=c++17"],
}[sys.platform]
sources = [str(p) for p in Path("src/pgeon").glob("**/*.cc")]
extra_objects = [
[
"pgeon_cpp",
{
"sources": sources,
"include_dirs": include_dirs,
"language": "c++",
"macros": macros,
"cflags": cflags,
},
]
]
libraries = ["pgeon_cpp"] + pa.get_libraries()
if sys.platform == "win32":
libraries.extend(["libpq", "Ws2_32"])
else:
libraries.append("pq")
extensions = [
Extension(
name="pgeon._pgeon",
sources=["python/_pgeon.pyx"],
language="c++",
define_macros=macros,
include_dirs=include_dirs,
libraries=libraries,
library_dirs=library_dirs,
extra_compile_args=cflags,
)
]
setup(
name="pgeon",
ext_modules=cythonize(extensions),
libraries=extra_objects,
packages=["pgeon"],
package_dir={"pgeon": "python"},
include_package_data=False,
)