From 3e5f883c50c92235e5152dbd58e589a90ee55748 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 27 Nov 2019 11:21:16 -0800 Subject: [PATCH 1/3] Strip out fastecdsa in setup.py, during doc build --- requirements-docs.txt | 2 +- setup.py | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/requirements-docs.txt b/requirements-docs.txt index ba1ee49e..3ef37020 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -1 +1 @@ -libp2p[doc] +.[doc] diff --git a/setup.py b/setup.py index 252252fe..e4d826ef 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os + from setuptools import find_packages, setup extras_require = { @@ -46,6 +48,26 @@ with open("./README.md") as readme: long_description = readme.read() +install_requires = [ + "pycryptodome>=3.9.2,<4.0.0", + "base58>=1.0.3,<2.0.0", + "pymultihash>=0.8.2", + "multiaddr>=0.0.8,<0.1.0", + "rpcudp>=3.0.0,<4.0.0", + "lru-dict>=1.1.6", + "protobuf>=3.10.0,<4.0.0", + "coincurve>=10.0.0,<11.0.0", + "pynacl==1.3.0", +] + + +# NOTE: Some dependencies break RTD builds. We can not install system dependencies on the +# RTD system so we have to exclude these dependencies when we are in an RTD environment. +readthedocs_is_building = os.environ.get("READTHEDOCS", False) +if not readthedocs_is_building: + install_requires.append("fastecdsa==1.7.4") + + setup( name="libp2p", # *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme @@ -57,18 +79,7 @@ setup( maintainer_email="snakecharmers@ethereum.org", url="https://github.com/libp2p/py-libp2p", include_package_data=True, - install_requires=[ - "pycryptodome>=3.9.2,<4.0.0", - "base58>=1.0.3,<2.0.0", - "pymultihash>=0.8.2", - "multiaddr>=0.0.8,<0.1.0", - "rpcudp>=3.0.0,<4.0.0", - "lru-dict>=1.1.6", - "protobuf>=3.10.0,<4.0.0", - "coincurve>=10.0.0,<11.0.0", - "fastecdsa==1.7.4", - "pynacl==1.3.0", - ], + install_requires=install_requires, python_requires=">=3.7,<4", extras_require=extras_require, py_modules=["libp2p"], From 27ecd4b0ed2b065683c89a6fa5cba73859326914 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 27 Nov 2019 12:25:11 -0800 Subject: [PATCH 2/3] Mock dependencies that are excluded in readthedocs It seems preferable to import just fastecdsa. But if you do that, then some kind of side-effect doesn't happen, which means that `sec1` is not available as an attribute on `fastecdsa.encoding`. So we specifically mock the sub-modules as well. --- docs/conf.py | 16 ++++++++++++++++ libp2p/crypto/key_exchange.py | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9038ad0a..ebff89ba 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -286,3 +286,19 @@ doctest_default_flags = (0 | doctest.IGNORE_EXCEPTION_DETAIL | doctest.NORMALIZE_WHITESPACE ) + +# -- Mocked dependencies ---------------------------------------- + +# Mock out dependencies that are unbuildable on readthedocs, as recommended here: +# https://docs.readthedocs.io/en/rel/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules + +import sys +from unittest.mock import MagicMock + +# Add new modules to mock here (it should be the same list as those excluded in setup.py) +MOCK_MODULES = [ + "fastecdsa", + "fastecdsa.encoding", + "fastecdsa.encoding.sec1", +] +sys.modules.update((mod_name, MagicMock()) for mod_name in MOCK_MODULES) diff --git a/libp2p/crypto/key_exchange.py b/libp2p/crypto/key_exchange.py index 17ec75ab..2af4030d 100644 --- a/libp2p/crypto/key_exchange.py +++ b/libp2p/crypto/key_exchange.py @@ -1,12 +1,14 @@ from typing import Callable, Tuple, cast -from fastecdsa.encoding.util import int_bytelen +from fastecdsa.encoding import util from libp2p.crypto.ecc import ECCPrivateKey, ECCPublicKey, create_new_key_pair from libp2p.crypto.keys import PublicKey SharedKeyGenerator = Callable[[bytes], bytes] +int_bytelen = util.int_bytelen + def create_ephemeral_key_pair(curve_type: str) -> Tuple[PublicKey, SharedKeyGenerator]: """Facilitates ECDH key exchange.""" From ce37082c44cb9e126094f391c622be5765b4726f Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 27 Nov 2019 14:16:55 -0800 Subject: [PATCH 3/3] Add release note for #318 Note that these commits are really just a bugfix, but from a release perspective, it's the first time that docs will be publicly available. --- newsfragments/318.doc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/318.doc.rst diff --git a/newsfragments/318.doc.rst b/newsfragments/318.doc.rst new file mode 100644 index 00000000..0e49888d --- /dev/null +++ b/newsfragments/318.doc.rst @@ -0,0 +1 @@ +Use Sphinx & autodoc to generate docs, now available on py-libp2p.readthedocs.io