Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to Py37+ #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ created!

- Schnorr partial and pair functions removed (removed from underlying lib)
- Requirement for gmp removed (removed from underlying lib)
- Support for Python 2 (but patches welcome!)
- Support for Python 2
- Support for supplying your own secp256k1 context per PublicKey/PrivateKey

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pip install secp256k1

### Precompiled binary packages (wheels)

Precompiled binary wheels is available for Python 2.7, 3.3, 3.4, and 3.5 on Linux. To take advantage of those you need to use pip >= 8.1.0.
Precompiled binary wheels are available on Linux.

In case you don't want to use the binary packages you can prevent pip from
using them with the following command:
Expand Down
71 changes: 40 additions & 31 deletions _cffi_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from cffi import FFI, VerificationError

sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from setup_support import (has_system_lib, # noqa: E402
redirect,
workdir,
absolute)
from setup_support import has_system_lib # noqa: E402
from setup_support import absolute, redirect, workdir

Source = namedtuple('Source', ('h', 'include'))
Source = namedtuple("Source", ("h", "include"))


class Break(Exception):
Expand All @@ -21,12 +19,12 @@ class Break(Exception):
def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
ffi = FFI()
code = []
if 'INCLUDE_DIR' in os.environ:
kwargs['include_dirs'] = [absolute(os.environ['INCLUDE_DIR'])]
if 'LIB_DIR' in os.environ:
kwargs['library_dirs'] = [absolute(os.environ['LIB_DIR'])]
if "INCLUDE_DIR" in os.environ:
kwargs["include_dirs"] = [absolute(os.environ["INCLUDE_DIR"])]
if "LIB_DIR" in os.environ:
kwargs["library_dirs"] = [absolute(os.environ["LIB_DIR"])]
for source in sources:
with open(source.h, 'rt') as h:
with open(source.h, "rt") as h:
ffi.cdef(h.read())
code.append(source.include)
if bundled:
Expand All @@ -35,18 +33,30 @@ def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
return ffi


_base = [Source(absolute("_cffi_build/secp256k1.h"),
"#include <secp256k1.h>", )]
_base = [
Source(
absolute("_cffi_build/secp256k1.h"),
"#include <secp256k1.h>",
)
]

_modules = {
'ecdh': Source(absolute("_cffi_build/secp256k1_ecdh.h"),
"#include <secp256k1_ecdh.h>", ),
'recovery': Source(absolute("_cffi_build/secp256k1_recovery.h"),
"#include <secp256k1_recovery.h>", ),
'schnorrsig': Source(absolute("_cffi_build/secp256k1_schnorrsig.h"),
"#include <secp256k1_schnorrsig.h>", ),
'extrakeys': Source(absolute("_cffi_build/secp256k1_extrakeys.h"),
"#include <secp256k1_extrakeys.h>", ),
"ecdh": Source(
absolute("_cffi_build/secp256k1_ecdh.h"),
"#include <secp256k1_ecdh.h>",
),
"recovery": Source(
absolute("_cffi_build/secp256k1_recovery.h"),
"#include <secp256k1_recovery.h>",
),
"schnorrsig": Source(
absolute("_cffi_build/secp256k1_schnorrsig.h"),
"#include <secp256k1_schnorrsig.h>",
),
"extrakeys": Source(
absolute("_cffi_build/secp256k1_extrakeys.h"),
"#include <secp256k1_extrakeys.h>",
),
}


Expand All @@ -67,7 +77,7 @@ def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
_base + [item[1] for item in combination],
name="_testcompile",
bundled=False,
libraries=['secp256k1']
libraries=["secp256k1"],
)
with redirect(sys.stderr, os.devnull), workdir():
_test_ffi.compile()
Expand All @@ -77,26 +87,25 @@ def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
pass
except Break:
ffi = _mk_ffi(
_base + [i[1] for i in _available],
bundled=False,
libraries=['secp256k1']
_base + [i[1] for i in _available], bundled=False, libraries=["secp256k1"]
)
print("Using system libsecp256k1 with modules: {}".format(
", ".join(i[0] for i in _available))
print(
"Using system libsecp256k1 with modules: {}".format(
", ".join(i[0] for i in _available)
)
)
else:
# We didn't find any functioning combination of modules
# Normally this shouldn't happen but just in case we will fall back
# to the bundled library
print("Installed libsecp256k1 is unusable"
" falling back to bundled version.")
print("Installed libsecp256k1 is unusable" " falling back to bundled version.")

if ffi is None:
# Library is not installed - use bundled one
print("Using bundled libsecp256k1")

# We usually build all the experimental bits, since they're useful.
if not os.environ.get('SECP_BUNDLED_NO_EXPERIMENTAL'):
ffi = _mk_ffi(_base + list(_modules.values()), libraries=['secp256k1'])
if not os.environ.get("SECP_BUNDLED_NO_EXPERIMENTAL"):
ffi = _mk_ffi(_base + list(_modules.values()), libraries=["secp256k1"])
else:
ffi = _mk_ffi(_base + [_modules['recovery']], libraries=['secp256k1'])
ffi = _mk_ffi(_base + [_modules["recovery"]], libraries=["secp256k1"])
Loading