diff --git a/scons/packaging.py b/scons/packaging.py index 4578a3e676..8b62a4b721 100644 --- a/scons/packaging.py +++ b/scons/packaging.py @@ -19,7 +19,13 @@ def __build_python_wheel(package_dir: str): def __install_python_wheels(wheels: List[str]): - run_python_program('pip', 'install', '--force-reinstall', '--no-deps', *wheels, print_args=True) + run_python_program('pip', + 'install', + '--force-reinstall', + '--no-deps', + '--disable-pip-version-check', + *wheels, + print_args=True) # pylint: disable=unused-argument diff --git a/scons/run.py b/scons/run.py index e6922827d5..d6d97f5011 100644 --- a/scons/run.py +++ b/scons/run.py @@ -8,83 +8,65 @@ from functools import reduce from os import path -from typing import List, Optional, Tuple +from typing import List, Optional from modules import BUILD_MODULE, CPP_MODULE, PYTHON_MODULE -from pkg_resources import DistributionNotFound, VersionConflict, parse_requirements, require -def __run_command(cmd: str, *args, print_args: bool = False): - cmd_formatted = cmd + (reduce(lambda aggr, argument: aggr + ' ' + argument, args, '') if print_args else '') - print('Running external command "' + cmd_formatted + '"...') +def __format_command(cmd: str, *args, format_args: bool) -> str: + return cmd + (reduce(lambda aggr, argument: aggr + ' ' + argument, args, '') if format_args else '') + + +def __run_command(cmd: str, *args, print_cmd: bool = True, print_args: bool = False, capture_output: bool = False): + if print_cmd: + print('Running external command "' + __format_command(cmd, *args, format_args=print_args) + '"...') + cmd_args = [cmd] for arg in args: cmd_args.append(str(arg)) - out = subprocess.run(cmd_args, check=False) + out = subprocess.run(cmd_args, check=False, text=capture_output, capture_output=capture_output) exit_code = out.returncode if exit_code != 0: - print('External command "' + cmd_formatted + '" terminated with non-zero exit code ' + str(exit_code)) + print('External command "' + __format_command(cmd, *args, format_args=print_args) + + '" terminated with non-zero exit code ' + str(exit_code)) sys.exit(exit_code) + return out -def __is_dependency_missing(dependency: str) -> bool: - try: - require(dependency) - return False - except DistributionNotFound: - return True - except VersionConflict: - return False +def __pip_install(requirement: str): + out = __run_command('python', + '-m', + 'pip', + 'install', + '--upgrade', + '--prefer-binary', + '--disable-pip-version-check', + requirement, + print_cmd=False, + capture_output=True) + stdout = str(out.stdout).strip() -def __is_dependency_outdated(dependency: str) -> bool: - try: - require(dependency) - return False - except DistributionNotFound: - return False - except VersionConflict: - return True + if not reduce(lambda aggr, line: aggr & line.startswith('Requirement already satisfied'), stdout.split('\n'), True): + print(stdout) -def __find_dependencies(requirements_file: str, *dependencies: str) -> List[str]: +def __find_requirements(requirements_file: str, *dependencies: str) -> List[str]: with open(requirements_file, mode='r', encoding='utf-8') as file: - dependency_dict = {dependency.key: str(dependency) for dependency in parse_requirements(file.read())} + requirements = {line.split(' ')[0]: line.strip() for line in file.readlines()} if dependencies: - return [dependency_dict[dependency] for dependency in dependencies if dependency in dependency_dict] - - return list(dependency_dict.values()) - - -def __find_missing_and_outdated_dependencies(requirements_file: str, *dependencies: str) -> Tuple[List[str], List[str]]: - dependencies = __find_dependencies(requirements_file, *dependencies) - missing_dependencies = [dependency for dependency in dependencies if __is_dependency_missing(dependency)] - outdated_dependencies = [dependency for dependency in dependencies if __is_dependency_outdated(dependency)] - return missing_dependencies, outdated_dependencies + return [requirements[dependency] for dependency in dependencies if dependency in requirements] - -def __pip_install(dependencies: List[str], force_reinstall: bool = False): - args = ['--prefer-binary'] - - if force_reinstall: - args.append('--force-reinstall') - - __run_command('python', '-m', 'pip', 'install', *args, *dependencies, print_args=True) + return list(requirements.values()) def __install_dependencies(requirements_file: str, *dependencies: str): - missing_dependencies, outdated_dependencies = __find_missing_and_outdated_dependencies( - requirements_file, *dependencies) - - if missing_dependencies: - __pip_install(missing_dependencies) - - if outdated_dependencies: - __pip_install(outdated_dependencies, force_reinstall=True) + for requirement in __find_requirements(requirements_file, *dependencies): + __pip_install(requirement) def install_build_dependencies(*dependencies: str):