forked from fplll/fpylll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·154 lines (118 loc) · 4.77 KB
/
setup.py
File metadata and controls
executable file
·154 lines (118 loc) · 4.77 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
if "READTHEDOCS" in os.environ:
# When building with readthedocs, install the dependencies too.
# See https://github.com/rtfd/readthedocs.org/issues/2776
for reqs in ["requirements.txt", "suggestions.txt"]:
if os.path.isfile(reqs):
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", reqs])
try:
from itertools import ifilter as filter
except ImportError:
pass # python 3
from os import path
from ast import parse
from distutils.core import setup
from distutils.extension import Extension
import Cython.Build
from copy import copy
# CONFIG VARIABLES
cythonize_dir = "build"
include_dirs = [os.path.join(sys.prefix, "include")]
library_dirs = [os.path.join(sys.exec_prefix, "lib")]
fplll = {"include_dirs": include_dirs,
"library_dirs": library_dirs,
"language": "c++",
"libraries": ["gmp", "mpfr", "fplll"],
"extra_compile_args": ["-std=c++11"],
"extra_link_args": ["-std=c++11"]}
other = {"include_dirs": include_dirs,
"library_dirs": library_dirs,
"libraries": ["gmp"]}
if "READTHEDOCS" in os.environ:
# ReadTheDocs uses fplll from Conda, which was built with the old
# C++ ABI.
fplll["extra_compile_args"].append("-D_GLIBCXX_USE_CXX11_ABI=0")
config_pxi = []
# 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("fpylll.gmp.pylong", ["src/fpylll/gmp/pylong.pyx"], **other),
Extension("fpylll.fplll.integer_matrix", ["src/fpylll/fplll/integer_matrix.pyx"], **fplll),
Extension("fpylll.fplll.gso", ["src/fpylll/fplll/gso.pyx"], **fplll),
Extension("fpylll.fplll.lll", ["src/fpylll/fplll/lll.pyx"], **fplll),
Extension("fpylll.fplll.wrapper", ["src/fpylll/fplll/wrapper.pyx"], **fplll),
Extension("fpylll.fplll.bkz_param", ["src/fpylll/fplll/bkz_param.pyx"], **fplll),
Extension("fpylll.fplll.bkz", ["src/fpylll/fplll/bkz.pyx"], **fplll),
Extension("fpylll.fplll.enumeration", ["src/fpylll/fplll/enumeration.pyx"], **fplll),
Extension("fpylll.fplll.svpcvp", ["src/fpylll/fplll/svpcvp.pyx"], **fplll),
Extension("fpylll.fplll.pruner", ["src/fpylll/fplll/pruner.pyx"], **fplll),
Extension("fpylll.fplll.sieve_gauss", ["src/fpylll/fplll/sieve_gauss.pyx"], **fplll),
Extension("fpylll.util", ["src/fpylll/util.pyx"], **fplll),
Extension("fpylll.io", ["src/fpylll/io.pyx"], **fplll),
Extension("fpylll.config", ["src/fpylll/config.pyx"], **fplll),
]
if have_numpy:
extensions.append(Extension("fpylll.numpy", ["src/fpylll/numpy.pyx"], **numpy_args))
# VERSION
with open(path.join('src', 'fpylll', '__init__.py')) as f:
__version__ = parse(next(filter(lambda line: line.startswith('__version__'), f))).body[0].value.s
# FIRE
setup(
name="fpylll",
description="A Python interface for https://github.com/fplll/fplll",
author=u"Martin R. Albrecht",
author_email="fplll-devel@googlegroups.com",
url="https://github.com/fplll/fpylll",
version=__version__,
ext_modules=Cython.Build.cythonize(extensions,
include_path=["src"],
build_dir=cythonize_dir,
compiler_directives={'binding': True, "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(),
)