Pārlūkot izejas kodu

Disable p2pd compilation by default (#270)

After these changes, both pip install hivemind and pip install -e hivemind will use precompiled binary p2pd, and will not require Go installation.


Co-authored-by: justheuristic <justheuristic@gmail.com>
Michael Diskin 4 gadi atpakaļ
vecāks
revīzija
bcd177171c
2 mainītis faili ar 28 papildinājumiem un 14 dzēšanām
  1. 3 3
      .circleci/config.yml
  2. 25 11
      setup.py

+ 3 - 3
.circleci/config.yml

@@ -26,7 +26,7 @@ jobs:
           paths:
             - '~/.cache/pip'
       - run:
-          command: pip install -e .
+          command: pip install -e . --install-option="--buildgo"
           name: setup
       - run:
           command: pytest ./tests
@@ -50,7 +50,7 @@ jobs:
           paths:
             - '~/.cache/pip'
       - run:
-          command: pip install -e .
+          command: pip install -e . --install-option="--buildgo"
           name: setup
       - run:
           command: pytest ./tests
@@ -74,7 +74,7 @@ jobs:
           paths:
             - '~/.cache/pip'
       - run:
-          command: pip install -e .
+          command: pip install -e . --install-option="--buildgo"
           name: setup
       - run:
           command: pytest ./tests

+ 25 - 11
setup.py

@@ -19,7 +19,6 @@ P2PD_VERSION = 'v0.3.1'
 P2PD_CHECKSUM = '8810097959db720208cdc9f2945804a4'
 LIBP2P_TAR_URL = f'https://github.com/learning-at-home/go-libp2p-daemon/archive/refs/tags/{P2PD_VERSION}.tar.gz'
 
-
 here = os.path.abspath(os.path.dirname(__file__))
 
 
@@ -51,16 +50,13 @@ def proto_compile(output_path):
 
 
 def libp2p_build_install():
-    try:
-        result = subprocess.run("go version", capture_output=True, shell=True).stdout.decode('ascii', 'replace')
-        m = re.search(r'^go version go([\d.]+)', result)
-        v = m.group(1)
-
-        if version.parse(v) < version.parse("1.13"):
-            raise EnvironmentError(f'Newer version of go required: must be >= 1.13, found {version}')
+    result = subprocess.run("go version", capture_output=True, shell=True).stdout.decode('ascii', 'replace')
+    m = re.search(r'^go version go([\d.]+)', result)
 
-    except FileNotFoundError:
+    if m is None:
         raise FileNotFoundError('Could not find golang installation')
+    if version.parse(m.group(1)) < version.parse("1.13"):
+        raise EnvironmentError(f'Newer version of go required: must be >= 1.13, found {version}')
 
     with tempfile.TemporaryDirectory() as tempdir:
         dest = os.path.join(tempdir, 'libp2p-daemon.tar.gz')
@@ -90,15 +86,33 @@ def libp2p_download_install():
 
 
 class Install(install):
+    user_options = install.user_options + [('buildgo', None, "Builds p2pd from source")]
+
+    def initialize_options(self):
+        super().initialize_options()
+        self.buildgo = False
+
     def run(self):
-        libp2p_download_install()
+        if self.buildgo:
+            libp2p_build_install()
+        else:
+            libp2p_download_install()
         proto_compile(os.path.join(self.build_lib, 'hivemind', 'proto'))
         super().run()
 
 
 class Develop(develop):
+    user_options = develop.user_options + [('buildgo', None, None)]
+
+    def initialize_options(self):
+        super().initialize_options()
+        self.buildgo = False
+
     def run(self):
-        libp2p_build_install()
+        if self.buildgo:
+            libp2p_build_install()
+        else:
+            libp2p_download_install()
         proto_compile(os.path.join('hivemind', 'proto'))
         super().run()