diff --git a/builder/pip.py b/builder/pip.py index 2fce0180..bb050114 100644 --- a/builder/pip.py +++ b/builder/pip.py @@ -1,10 +1,10 @@ """Pip build commands.""" import os -import subprocess -import sys from pathlib import Path from typing import List, Optional +from .utils import run_command + def build_wheels_package( package: str, @@ -24,12 +24,8 @@ def build_wheels_package( # Add constraint constraint_cmd = f"--constraint {constraint}" if constraint else "" - subprocess.run( + run_command( f'pip3 wheel --progress-bar off --no-binary "{skip_binary}" --wheel-dir {output} --find-links {index} {constraint_cmd} "{package}"', - shell=True, - check=True, - stdout=sys.stdout, - stderr=sys.stderr, env=build_env, timeout=timeout, ) @@ -53,12 +49,8 @@ def build_wheels_requirement( # Add constraint constraint_cmd = f"--constraint {constraint}" if constraint else "" - subprocess.run( + run_command( f'pip3 wheel --progress-bar off --no-binary "{skip_binary}" --wheel-dir {output} --find-links {index} {constraint_cmd} --requirement {requirement}', - shell=True, - check=True, - stdout=sys.stdout, - stderr=sys.stderr, env=build_env, timeout=timeout, ) @@ -72,12 +64,8 @@ def build_wheels_local(index: str, output: Path) -> None: build_env = os.environ.copy() build_env["MAKEFLAGS"] = f"-j{cpu}" - subprocess.run( + run_command( f"pip3 wheel --progress-bar off --wheel-dir {output} --find-links {index} .", - shell=True, - check=True, - stdout=sys.stdout, - stderr=sys.stderr, env=build_env, ) @@ -118,10 +106,6 @@ def install_pips(index: str, pips: str) -> None: """Install all pipy string formated as 'package1;package2'.""" packages = " ".join(pips.split(";")) - subprocess.run( + run_command( f"pip install --progress-bar off --upgrade --no-cache-dir --prefer-binary --find-links {index} {packages}", - shell=True, - check=True, - stdout=sys.stdout, - stderr=sys.stderr, ) diff --git a/builder/upload/rsync.py b/builder/upload/rsync.py index b6b14f4a..86147639 100644 --- a/builder/upload/rsync.py +++ b/builder/upload/rsync.py @@ -1,15 +1,11 @@ """Upload plugin rsync.""" from pathlib import Path -import subprocess -import sys + +from ..utils import run_command def upload(local: Path, remote: str) -> None: """Upload wheels from folder to remote rsync server.""" - subprocess.run( + run_command( f"rsync --human-readable --recursive --partial --progress --checksum {local}/* {remote}/", - shell=True, - check=True, - stdout=sys.stdout, - stderr=sys.stderr, ) diff --git a/builder/utils.py b/builder/utils.py index 6dc3643a..aff2a1ce 100644 --- a/builder/utils.py +++ b/builder/utils.py @@ -2,6 +2,9 @@ from pathlib import Path import os import re +import subprocess +import sys +from typing import Optional, Dict import requests @@ -33,3 +36,26 @@ def fix_wheels_name(wheels_folder: Path) -> None: if not match: continue package.rename(Path(package.parent, f"{match.group('name')}none-any.whl")) + + +def run_command( + cmd: str, env: Optional[Dict[str, str]] = None, timeout: Optional[int] = None +) -> None: + """Implement subprocess.run but handle timeout different.""" + process = subprocess.Popen( + cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr, env=env + ) + + # Run command and wait + try: + process.communicate(timeout=timeout) + except subprocess.TimeoutExpired as err: + print(f"Timeout for '{cmd}'", flash=True) + process.kill() + raise err + + # Process return code + if process.returncode == 0: + return + print(f"Command '{cmd}' return error {process.returncode}", flash=True) + raise subprocess.CalledProcessError(process.returncode, cmd) diff --git a/setup.py b/setup.py index b733dae7..0a49106e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "1.12.0" +VERSION = "1.12.1" setup( name="builder",