forked from fplll/fpylll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·132 lines (103 loc) · 3.95 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
from distutils.extension import Extension
import Cython.Build
import os
import subprocess
import sys
from copy import copy
# CONFIG VARIABLES
cythonize_dir = "build"
fplll = {"include_dirs": [],
"library_dirs": [],
"language": "c++",
"libraries": ["gmp", "mpfr", "fplll"],
"extra_compile_args": ["-std=c++11"],
"extra_link_args": ["-std=c++11"]}
other = {"include_dirs": [],
"library_dirs": [],
"libraries": ["gmp"]}
config_pxi = []
# VIRTUALENVS
if "VIRTUAL_ENV" in os.environ:
prefix = os.environ["VIRTUAL_ENV"]
fplll["include_dirs"] = [os.path.join(prefix, "include")]
fplll["library_dirs"] = [os.path.join(prefix, "lib")]
other["include_dirs"] = [os.path.join(prefix, "include")]
other["library_dirs"] = [os.path.join(prefix, "lib")]
# QD
have_qd = False
try:
libs = subprocess.check_output(["pkg-config", "fplll", "--libs"])
if b"-lqd" in libs:
have_qd = True
except subprocess.CalledProcessError:
pass
if have_qd:
fplll["libraries"].append("qd")
config_pxi.append("DEF HAVE_QD=True")
else:
config_pxi.append("DEF HAVE_QD=False")
# NUMPY
try:
import numpy
have_numpy = True
except ImportError:
have_numpy = False
if have_numpy:
config_pxi.append("DEF HAVE_NUMPY=True")
numpy_args = copy(fplll)
numpy_args["include_dirs"].append(numpy.get_include())
else:
config_pxi.append("DEF HAVE_NUMPY=False")
# Ideally this would check the fplll headers explicitly for the
# the FPLLL_WITH_LONG_DOUBLE define, but for now it suffices to
# say that long double support is disabled on Cygwin
have_long_double = not sys.platform.startswith('cygwin')
config_pxi.append("DEF HAVE_LONG_DOUBLE={0}".format(have_long_double))
# CONFIG.PXI
config_pxi_path = os.path.join(".", "src", "fpylll", "config.pxi")
config_pxi = "\n".join(config_pxi) + "\n"
try:
cur_config_pxi = open(config_pxi_path, "r").read()
except IOError:
cur_config_pxi = ""
if cur_config_pxi != config_pxi: # check if we need to write
with open(config_pxi_path, "w") as fw:
fw.write(config_pxi)
# EXTENSIONS
extensions = [
Extension("gmp.pylong", ["src/fpylll/gmp/pylong.pyx"], **other),
Extension("fplll.integer_matrix", ["src/fpylll/fplll/integer_matrix.pyx"], **fplll),
Extension("fplll.gso", ["src/fpylll/fplll/gso.pyx"], **fplll),
Extension("fplll.lll", ["src/fpylll/fplll/lll.pyx"], **fplll),
Extension("fplll.wrapper", ["src/fpylll/fplll/wrapper.pyx"], **fplll),
Extension("fplll.bkz_param", ["src/fpylll/fplll/bkz_param.pyx"], **fplll),
Extension("fplll.bkz", ["src/fpylll/fplll/bkz.pyx"], **fplll),
Extension("fplll.enumeration", ["src/fpylll/fplll/enumeration.pyx"], **fplll),
Extension("fplll.svpcvp", ["src/fpylll/fplll/svpcvp.pyx"], **fplll),
Extension("fplll.pruner", ["src/fpylll/fplll/pruner.pyx"], **fplll),
Extension("util", ["src/fpylll/util.pyx"], **fplll),
Extension("io", ["src/fpylll/io.pyx"], **fplll),
Extension("config", ["src/fpylll/config.pyx"], **fplll),
]
if have_numpy:
extensions.append(Extension("numpy", ["src/fpylll/numpy.pyx"], **numpy_args))
setup(
name="fpylll",
description="A Python interface for https://github.com/fplll/fplll",
author=u"Martin R. Albrecht",
author_email="[email protected]",
url="https://github.com/fplll/fpylll",
version='0.2.3dev',
ext_package='fpylll',
ext_modules=Cython.Build.cythonize(extensions,
include_path=["src"] + sys.path,
build_dir=cythonize_dir,
compiler_directives={'embedsignature': True}),
package_dir={"": "src"},
packages=["fpylll", "fpylll.gmp", "fpylll.fplll", "fpylll.algorithms", "fpylll.tools"],
license='GNU General Public License, version 2 or later',
long_description=open('README.rst').read(),
)