From 8153eb41da603f5cddaab2104db38bb65191723d Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 1 May 2019 15:51:51 +0200 Subject: [PATCH] Evaluate CPU for build --- builder/__main__.py | 7 ++++++- builder/pip.py | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/builder/__main__.py b/builder/__main__.py index 27cce6df..522ba67e 100644 --- a/builder/__main__.py +++ b/builder/__main__.py @@ -1,6 +1,7 @@ """Hass.io Builder main application.""" from pathlib import Path from tempfile import TemporaryDirectory +from subprocess import CalledProcessError import click import click_pathlib @@ -34,7 +35,11 @@ def builder(apk, index, requirement, upload, remote): wheels_dir = create_wheels_folder(output) wheels_index = create_wheels_index(index) - build_wheels(requirement, wheels_index, wheels_dir) + try: + build_wheels(requirement, wheels_index, wheels_dir) + except CalledProcessError: + pass + run_upload(upload, output, remote) diff --git a/builder/pip.py b/builder/pip.py index fcbbe34e..310c83dc 100644 --- a/builder/pip.py +++ b/builder/pip.py @@ -1,14 +1,21 @@ """Pip build commands.""" from pathlib import Path +import os import subprocess import sys def build_wheels(requirement: Path, index: str, output: Path) -> None: """Build wheels from a requirements file into output.""" + cpu = os.cpu_count() or 4 + + # Modify speed + build_env = os.environ.copy() + build_env['MAKEFLAGS'] = f"-j{cpu}" + result = subprocess.run( f"pip3 wheel --wheel-dir {output} --find-links {index} --requirement {requirement}", - shell=True, stdout=sys.stdout, stderr=sys.stderr + shell=True, stdout=sys.stdout, stderr=sys.stderr, env=build_env ) # Check result of program