-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathsetup.py
executable file
·153 lines (131 loc) · 4.33 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
# -*- coding: utf-8 -*-
####
#
# Copyright (C) 2018-2021 Team G6K
#
# This file is part of G6K. G6K is free software:
# you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation,
# either version 2 of the License, or (at your option) any later version.
#
# G6K is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with G6K. If not, see <http://www.gnu.org/licenses/>.
#
####
try:
from setuptools import setup
from setuptools.extension import Extension
from setuptools.command import build_ext as build_module
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from distutils.command import build_ext as build_module
from Cython.Build import cythonize
import subprocess
import numpy
import sys
import os
from ast import parse
#
# `setup,py` consumes files output by `configure` so we insist on running it first.
#
if "CONDA_PREFIX" in os.environ:
prefix = os.environ["CONDA_PREFIX"]
elif "VIRTUAL_ENV" in os.environ:
prefix = os.environ["VIRTUAL_ENV"]
elif "LD_LIBRARY_PATH" in os.environ and os.environ["LD_LIBRARY_PATH"].endswith("/lib"):
prefix = os.environ["LD_LIBRARY_PATH"][:-4]
else:
prefix = None
if not os.path.exists("configure"):
subprocess.check_call(["autoreconf", "-i"])
if not os.path.exists("Makefile"):
if prefix:
subprocess.check_call(["./configure", f"--prefix={prefix}"])
else:
subprocess.check_call("./configure")
#
# But we only run `make` as part of `build_ext`
#
class build_ext(build_module.build_ext):
def run(self):
for arg in sys.argv:
if arg.startswith("-j"):
subprocess.check_call(["make", arg])
break
else:
subprocess.check_call("make")
build_module.build_ext.run(self)
def read_from(filename, field, sep):
data = [line for line in open(filename).readlines() if line.startswith(field)][0]
data = "=".join(data.split(sep)[1:])
data = data.strip()
data = [d for d in data.split(" ") if d]
return data
# Version
with open(os.path.join("g6k", "__init__.py")) as f:
__version__ = (
parse(next(filter(lambda line: line.startswith("__version__"), f))).body[0].value.s
)
extra_compile_args = ["-std=c++11"]
# extra_compile_args += ["-DCYTHON_TRACE=1"]
# there's so many warnings generated here, we need to filter out -Werror
extra_compile_args += [opt for opt in read_from("g6k.pc", "Cflags", ": ") if opt != "-Werror"]
if prefix:
extra_compile_args += [f"-L{prefix}/lib"]
kwds = {
"language": "c++",
"extra_compile_args": extra_compile_args,
# TODO: we should just install the shared lib and link against that
"extra_link_args": [
("kernel/.libs/%s" % fn).replace(".cpp", ".o")
for fn in read_from("kernel/Makefile.am", "libg6k_la_SOURCES", "=")
],
"libraries": ["gmp", "pthread"],
"include_dirs": [numpy.get_include()],
}
if prefix:
kwds["library_dirs"] = [f"{prefix}/lib"]
extensions = [
Extension("g6k.siever", ["g6k/siever.pyx"], **kwds),
Extension("g6k.siever_params", ["g6k/siever_params.pyx"], **kwds),
]
setup(
name="g6k",
description="General Sieve Kernel",
version=__version__,
url="https://github.com/fplll/g6k",
ext_modules=cythonize(
extensions,
compiler_directives={"binding": True, "embedsignature": True, "language_level": 2},
),
packages=["g6k", "g6k.algorithms", "g6k.utils"],
package_data={"": ["spherical_coding/*.def"]},
cmdclass={
"build_ext": build_ext,
},
author="G6K team",
author_email="[email protected]",
scripts=[
"bkz.py",
"full_sieve.py",
"hkz.py",
"hkz_maybe.py",
"lwe_challenge.py",
"plain_sieve.py",
"svp_challenge.py",
"svp_exact.py",
"svp_exact_find_norm.py",
],
classifiers=[
"Programming Language :: C++",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
],
)