marcoabreu closed pull request #10496: Minor simplifications in ci/build.py
URL: https://github.com/apache/incubator-mxnet/pull/10496
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ci/build.py b/ci/build.py
index e1e4560d947..ee36876db74 100755
--- a/ci/build.py
+++ b/ci/build.py
@@ -25,18 +25,18 @@
 __author__ = 'Marco de Abreu, Kellen Sunderland, Anton Chernov, Pedro Larroy'
 __version__ = '0.1'
 
-import os
-import sys
-import subprocess
-import logging
 import argparse
-from subprocess import check_call, call
 import glob
+import logging
+import os
 import re
-from typing import *
-from itertools import chain
-from copy import deepcopy
 import shutil
+import subprocess
+import sys
+from copy import deepcopy
+from itertools import chain
+from subprocess import call, check_call
+from typing import *
 
 
 def get_platforms(path: Optional[str]="docker"):
@@ -44,8 +44,7 @@ def get_platforms(path: Optional[str]="docker"):
     dockerfiles = glob.glob(os.path.join(path, "Dockerfile.build.*"))
     dockerfiles = list(filter(lambda x: x[-1] != '~', dockerfiles))
     files = list(map(lambda x: re.sub(r"Dockerfile.build.(.*)", r"\1", x), 
dockerfiles))
-    files.sort()
-    platforms = list(map(lambda x: os.path.split(x)[1], files))
+    platforms = list(map(lambda x: os.path.split(x)[1], sorted(files)))
     return platforms
 
 
@@ -53,14 +52,13 @@ def get_docker_tag(platform: str) -> str:
     return "mxnet/build.{0}".format(platform)
 
 
-def get_dockerfile(platform: str, path="docker"):
+def get_dockerfile(platform: str, path="docker") -> str:
     return os.path.join(path, "Dockerfile.build.{0}".format(platform))
 
-def get_docker_binary(use_nvidia_docker: bool):
-    if use_nvidia_docker:
-        return "nvidia-docker"
-    else:
-        return "docker"
+
+def get_docker_binary(use_nvidia_docker: bool) -> str:
+    return "nvidia-docker" if use_nvidia_docker else "docker"
+
 
 def build_docker(platform: str, docker_binary: str) -> None:
     """Build a container for the given platform"""
@@ -74,6 +72,7 @@ def build_docker(platform: str, docker_binary: str) -> None:
     logging.info("Running command: '%s'", ' '.join(cmd))
     check_call(cmd)
 
+
 def get_mxnet_root() -> str:
     curpath = os.path.abspath(os.path.dirname(__file__))
     def is_mxnet_root(path: str) -> bool:
@@ -85,9 +84,11 @@ def is_mxnet_root(path: str) -> bool:
         curpath = parent
     return curpath
 
+
 def buildir() -> str:
     return os.path.join(get_mxnet_root(), "build")
 
+
 def container_run(platform: str, docker_binary: str, command: List[str], 
dry_run: bool = False, into_container: bool = False) -> str:
     tag = get_docker_tag(platform)
     mx_root = get_mxnet_root()
@@ -120,11 +121,9 @@ def container_run(platform: str, docker_binary: str, 
command: List[str], dry_run
 
     return docker_run_cmd
 
-def list_platforms():
-    platforms = get_platforms()
-    print("\nSupported platforms:\n")
-    print('\n'.join(platforms))
-    print()
+
+def list_platforms() -> str:
+    print("\nSupported platforms:\n{}".format('\n'.join(get_platforms())))
 
 
 def main() -> int:
@@ -134,6 +133,7 @@ def main() -> int:
     os.chdir(base)
 
     logging.getLogger().setLevel(logging.INFO)
+
     def script_name() -> str:
         return os.path.split(sys.argv[0])[1]
 
@@ -208,14 +208,14 @@ def script_name() -> str:
             build_docker(platform, docker_binary)
             if args.build_only:
                 continue
-            cmd = ["/work/mxnet/ci/docker/runtime_functions.sh", 
"build_{}".format(platform)]
+            build_platform = "build_{}".format(platform)
+            cmd = ["/work/mxnet/ci/docker/runtime_functions.sh", 
build_platform]
             shutil.rmtree(buildir(), ignore_errors=True)
             container_run(platform, docker_binary, cmd)
-            plat_buildir = os.path.join(get_mxnet_root(), 
"build_{}".format(platform))
+            plat_buildir = os.path.join(get_mxnet_root(), build_platform)
             shutil.move(buildir(), plat_buildir)
             logging.info("Built files left in: %s", plat_buildir)
 
-
     else:
         parser.print_help()
         list_platforms()
@@ -245,7 +245,6 @@ def script_name() -> str:
 
     """)
 
-
     return 0
 
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to