-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
148 lines (130 loc) · 4.43 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
# -*- coding:utf-8 -*-
import os
import sys
from subprocess import call, PIPE
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.command.build_clib import build_clib
try:
from importlib import machinery
lib_suffix = machinery.all_suffixes()[-1]
install_requires = []
except ImportError:
import imp
lib_suffix = imp.get_suffixes()[0][0]
install_requires = ['future']
class build_ctypes(build_ext):
EXT = ".dll" if sys.platform.startswith("win") else lib_suffix
def __init__(self, *args, **kw):
build_clib_options = []
for long_, short, comment in build_clib.user_options:
build_clib_options.extend([long_, short])
call(
[sys.executable, 'setup.py', 'build_clib'] +
[arg for arg in sys.argv if arg.lstrip("-") in build_clib_options],
stdout=PIPE
)
build_ext.__init__(self, *args, **kw)
def build_extension(self, ext):
return super().build_extension(ext)
def get_export_symbols(self, ext):
return ext.export_symbols
def get_ext_filename(self, ext_name):
return ext_name + build_ctypes.EXT
if "static" in sys.argv:
sys.argv.pop(sys.argv.index("static"))
# configure compilation
extra_compile_args = ["-Ofast"]
include_dirs = [os.path.abspath('./src')]
libraries = []
if sys.platform.startswith("win"):
# configuration using mingw compiler from Msys 2.x installed in C:/
extra_link_args = [
"-l:libpython%s.%s.a" % sys.version_info[:2],
"-l:libgmp.a",
"-static"
]
library_dirs = [r'C:\Msys\usr\lib']
else:
extra_link_args = ["-l:libgmp.so"]
library_dirs = []
else:
# configure compilation
extra_compile_args = ['-Ofast']
include_dirs = [os.path.abspath('./src')]
libraries = ['gmp']
extra_link_args = []
library_dirs = []
# configure libraries
libraries = [
(
"ecdsa", {
"sources": ["src/ecdsa.c"],
"extra_compile_args": extra_compile_args,
"extra_link_args": extra_link_args,
"include_dirs": include_dirs,
"library_dirs": library_dirs,
"libraries": libraries,
}
),
(
"schnorr", {
"sources": ["src/schnorr.c", "src/sha256.c"],
"extra_compile_args": extra_compile_args,
"extra_link_args": extra_link_args,
"include_dirs": include_dirs,
"library_dirs": library_dirs,
"libraries": libraries,
}
)
]
lib_ecdsa, lib_schnorr = libraries
cmd_class = {
"build_ctypes": build_ctypes,
"build_ext": build_ctypes
}
ext_modules = [
Extension('cSecp256k1._ecdsa', **lib_ecdsa[-1]),
Extension('cSecp256k1._schnorr', **lib_schnorr[-1])
]
with open("VERSION") as f1, open("README.md") as f2:
VERSION = f1.read().strip()
LONG_DESCRIPTION = f2.read()
kw = {
"version": VERSION,
"name": "cSecp256k1",
"keywords": ["ctypes", "curve", "bitcoin"],
"author": "Toons",
"author_email": "[email protected]",
"maintainer": "Toons",
"maintainer_email": "[email protected]",
"url": "https://github.com/Moustikitos/fast-curve",
"download_url":
"https://github.com/Moustikitos/fast-curve/archive/master.zip",
"include_package_data": True,
"description": "Fast python implementation for bitcoin curve",
"long_description": LONG_DESCRIPTION,
"long_description_content_type": "text/markdown",
"packages": ["cSecp256k1"],
"install_requires": install_requires,
"tests_require": ["pytest", "pytest-benchmark"],
"libraries": libraries,
"ext_modules": ext_modules,
"cmdclass": cmd_class,
"license": "Copyright 2021, MIT licence",
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
],
}
setup(**kw)