-
Notifications
You must be signed in to change notification settings - Fork 167
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
Fix LibP2P-Daemon installation in setup.py #186
Changes from 10 commits
9e50415
d410763
5a17d03
717e3ce
0aeeff1
09221e8
61d4d3e
94823de
047e780
f2b1c9a
15379f2
c62b30c
ad84501
2ce4fca
41588ec
ba131d4
eba3920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,6 @@ debian/files | |
|
||
# protobuf stuff | ||
hivemind/proto/*_pb2* | ||
|
||
# libp2p-daemon binary | ||
hivemind/hivemind_cli/p2pd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import urllib.request | ||
import tarfile | ||
import tempfile | ||
import json | ||
import hashlib | ||
|
||
from packaging import version | ||
from pkg_resources import parse_requirements | ||
|
@@ -14,13 +16,16 @@ | |
from setuptools.command.install import install | ||
|
||
|
||
P2PD_VERSION = 'v0.3.1' | ||
P2PD_CHECKSUM = '5094d094740f4e375afe80a5683b1bb2' | ||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
class cd: | ||
"""Context manager for changing the current working directory""" | ||
def __init__(self, newPath): | ||
self.newPath = os.path.expanduser(newPath) | ||
def __init__(self, new_path): | ||
self.newPath = os.path.expanduser(new_path) | ||
|
||
def __enter__(self): | ||
self.savedPath = os.getcwd() | ||
|
@@ -30,6 +35,14 @@ def __exit__(self, etype, value, traceback): | |
os.chdir(self.savedPath) | ||
|
||
|
||
def md5(fname): | ||
hash_md5 = hashlib.md5() | ||
with open(fname, "rb") as f: | ||
for chunk in iter(lambda: f.read(4096), b""): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move 4096 to a constant or at least an argument with default value |
||
hash_md5.update(chunk) | ||
return hash_md5.hexdigest() | ||
|
||
|
||
def proto_compile(output_path): | ||
import grpc_tools.protoc | ||
|
||
|
@@ -49,16 +62,15 @@ def proto_compile(output_path): | |
file.truncate() | ||
|
||
|
||
def install_libp2p_daemon(): | ||
# check go version: | ||
def libp2p_build_install(): | ||
try: | ||
proc = subprocess.Popen(['go', 'version'], | ||
stdout=subprocess.PIPE) | ||
result, _ = proc.communicate() | ||
result = result.decode('ascii', 'replace') | ||
_, _, v, _ = result.split(' ') | ||
v = v.lstrip('go') | ||
|
||
if version.parse(v) < version.parse("1.13"): | ||
raise EnvironmentError(f'newer version of go required: must be >= 1.13, found {version}') | ||
|
||
|
@@ -67,38 +79,44 @@ def install_libp2p_daemon(): | |
|
||
with tempfile.TemporaryDirectory() as tempdir: | ||
url = 'https://github.com/libp2p/go-libp2p-daemon/archive/master.tar.gz' | ||
dest = os.path.join(tempdir, 'libp2p-daemon.tar.gz') | ||
dest = os.path.join(tempdir, 'libp2p-daemon.tar.gz') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to change the URL to learning-at-home and to pin the version |
||
urllib.request.urlretrieve(url, os.path.join(tempdir, dest)) | ||
|
||
tar = tarfile.open(dest, 'r:gz') | ||
tar.extractall(tempdir) | ||
tar.close() | ||
|
||
with cd(os.path.join(tempdir, 'go-libp2p-daemon-master', 'p2pd')): | ||
status = os.system(f'go build -o {os.path.join(here, "hivemind/hivemind_cli", "p2pd")}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure whether the class |
||
if status: | ||
raise RuntimeError('Failed to build or install libp2p-daemon:'\ | ||
raise RuntimeError('Failed to build or install libp2p-daemon:' | ||
f' exited with status code :{status}') | ||
|
||
|
||
class ProtoCompileInstall(install): | ||
def libp2p_download_install(): | ||
install_path = os.path.join(here, 'hivemind/hivemind_cli/') | ||
binary_path = os.path.join(install_path, 'p2pd') | ||
if 'p2pd' not in os.listdir(install_path) or md5(binary_path) != P2PD_CHECKSUM: | ||
print('Downloading Peer to Peer Daemon') | ||
mryab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
url = f'https://github.com/learning-at-home/go-libp2p-daemon/releases/download/{P2PD_VERSION}/p2pd' | ||
urllib.request.urlretrieve(url, binary_path) | ||
os.chmod(binary_path, 777) | ||
|
||
|
||
class Install(install): | ||
def run(self): | ||
libp2p_download_install() | ||
proto_compile(os.path.join(self.build_lib, 'hivemind', 'proto')) | ||
super().run() | ||
|
||
|
||
class ProtoCompileDevelop(develop): | ||
class Develop(develop): | ||
def run(self): | ||
libp2p_build_install() | ||
proto_compile(os.path.join('hivemind', 'proto')) | ||
super().run() | ||
|
||
|
||
class LibP2PInstall(install): | ||
def run(self): | ||
install_libp2p_daemon() | ||
|
||
|
||
|
||
with open('requirements.txt') as requirements_file: | ||
install_requires = list(map(str, parse_requirements(requirements_file))) | ||
|
||
|
@@ -120,7 +138,7 @@ def run(self): | |
setup( | ||
name='hivemind', | ||
version=version_string, | ||
cmdclass={'install': ProtoCompileInstall, 'develop': ProtoCompileDevelop, 'libp2p': LibP2PInstall}, | ||
cmdclass={'install': Install, 'develop': Develop}, | ||
description='Decentralized deep learning in PyTorch', | ||
long_description='Decentralized deep learning in PyTorch. Built to train giant models on ' | ||
'thousands of volunteers across the world.', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to parametrize Go versions for all three pipelines with something like pipeline variables