Resolve subprocess calls to cover edge cases like broken PATH
This commit is contained in:
parent
593e72447d
commit
f875cc1fcc
@ -82,6 +82,9 @@ def pre_check() -> bool:
|
||||
if sys.version_info < (3, 9):
|
||||
logger.error(wording.get('python_not_supported').format(version = '3.9'), __name__)
|
||||
return False
|
||||
if not shutil.which('curl'):
|
||||
logger.error(wording.get('curl_not_installed'), __name__)
|
||||
return False
|
||||
if not shutil.which('ffmpeg'):
|
||||
logger.error(wording.get('ffmpeg_not_installed'), __name__)
|
||||
return False
|
||||
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import ssl
|
||||
import subprocess
|
||||
import urllib.request
|
||||
@ -27,7 +28,7 @@ def conditional_download(download_directory_path : str, urls : List[str]) -> Non
|
||||
|
||||
if initial_size < download_size:
|
||||
with tqdm(total = download_size, initial = initial_size, desc = wording.get('downloading'), unit = 'B', unit_scale = True, unit_divisor = 1024, ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||
subprocess.Popen([ 'curl', '--create-dirs', '--silent', '--insecure', '--location', '--continue-at', '-', '--output', download_file_path, url ])
|
||||
subprocess.Popen([ shutil.which('curl'), '--create-dirs', '--silent', '--insecure', '--location', '--continue-at', '-', '--output', download_file_path, url ])
|
||||
current_size = initial_size
|
||||
|
||||
progress.set_postfix(file = download_file_name)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from typing import List, Optional
|
||||
@ -13,7 +14,7 @@ from facefusion.vision import restrict_video_fps
|
||||
|
||||
|
||||
def run_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
||||
commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'error' ]
|
||||
commands = [ shutil.which('ffmpeg'), '-hide_banner', '-loglevel', 'error' ]
|
||||
commands.extend(args)
|
||||
process = subprocess.Popen(commands, stderr = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||
|
||||
@ -32,7 +33,7 @@ def run_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
||||
|
||||
|
||||
def open_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
||||
commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'quiet' ]
|
||||
commands = [ shutil.which('ffmpeg'), '-hide_banner', '-loglevel', 'quiet' ]
|
||||
commands.extend(args)
|
||||
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||
|
||||
|
@ -56,7 +56,7 @@ def run(program : ArgumentParser) -> None:
|
||||
onnxruntime = answers['onnxruntime']
|
||||
onnxruntime_name, onnxruntime_version = ONNXRUNTIMES[onnxruntime]
|
||||
|
||||
subprocess.call([ 'pip', 'install', '-r', 'requirements.txt', '--force-reinstall' ])
|
||||
subprocess.call([ shutil.which('pip'), 'install', '-r', 'requirements.txt', '--force-reinstall' ])
|
||||
|
||||
if onnxruntime == 'rocm':
|
||||
python_id = 'cp' + str(sys.version_info.major) + str(sys.version_info.minor)
|
||||
@ -65,13 +65,13 @@ def run(program : ArgumentParser) -> None:
|
||||
wheel_name = 'onnxruntime_rocm-' + onnxruntime_version +'-' + python_id + '-' + python_id + '-linux_x86_64.whl'
|
||||
wheel_path = os.path.join(tempfile.gettempdir(), wheel_name)
|
||||
wheel_url = 'https://repo.radeon.com/rocm/manylinux/rocm-rel-6.2/' + wheel_name
|
||||
subprocess.call([ 'curl', '--silent', '--location', '--continue-at', '-', '--output', wheel_path, wheel_url ])
|
||||
subprocess.call([ 'pip', 'uninstall', 'onnxruntime', wheel_path, '-y', '-q' ])
|
||||
subprocess.call([ 'pip', 'install', wheel_path, '--force-reinstall' ])
|
||||
subprocess.call([ shutil.which('curl'), '--silent', '--location', '--continue-at', '-', '--output', wheel_path, wheel_url ])
|
||||
subprocess.call([ shutil.which('pip'), 'uninstall', 'onnxruntime', wheel_path, '-y', '-q' ])
|
||||
subprocess.call([ shutil.which('pip'), 'install', wheel_path, '--force-reinstall' ])
|
||||
os.remove(wheel_path)
|
||||
else:
|
||||
subprocess.call([ 'pip', 'uninstall', 'onnxruntime', onnxruntime_name, '-y', '-q' ])
|
||||
subprocess.call([ 'pip', 'install', onnxruntime_name + '==' + onnxruntime_version, '--force-reinstall' ])
|
||||
subprocess.call([ shutil.which('pip'), 'uninstall', 'onnxruntime', onnxruntime_name, '-y', '-q' ])
|
||||
subprocess.call([ shutil.which('pip'), 'install', onnxruntime_name + '==' + onnxruntime_version, '--force-reinstall' ])
|
||||
|
||||
if onnxruntime == 'cuda' and has_conda:
|
||||
library_paths = []
|
||||
@ -88,7 +88,7 @@ def run(program : ArgumentParser) -> None:
|
||||
])
|
||||
library_paths = [ library_path for library_path in library_paths if os.path.exists(library_path) ]
|
||||
|
||||
subprocess.call([ 'conda', 'env', 'config', 'vars', 'set', 'LD_LIBRARY_PATH=' + os.pathsep.join(library_paths) ])
|
||||
subprocess.call([ shutil.which('conda'), 'env', 'config', 'vars', 'set', 'LD_LIBRARY_PATH=' + os.pathsep.join(library_paths) ])
|
||||
|
||||
if is_windows():
|
||||
if os.getenv('PATH'):
|
||||
|
@ -4,6 +4,7 @@ WORDING : Dict[str, Any] =\
|
||||
{
|
||||
'conda_not_activated': 'Conda is not activated',
|
||||
'python_not_supported': 'Python version is not supported, upgrade to {version} or higher',
|
||||
'curl_not_installed': 'CURL is not installed',
|
||||
'ffmpeg_not_installed': 'FFMpeg is not installed',
|
||||
'creating_temp': 'Creating temporary resources',
|
||||
'extracting_frames': 'Extracting frames with a resolution of {resolution} and {fps} frames per second',
|
||||
|
@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
os.environ['SYSTEM_VERSION_COMPAT'] = '0'
|
||||
os.environ['PIP_BREAK_SYSTEM_PACKAGES'] = '1'
|
||||
subprocess.call([ 'pip', 'install', 'inquirer', '-q' ])
|
||||
subprocess.call([ shutil.which('pip'), 'install', 'inquirer', '-q' ])
|
||||
|
||||
from facefusion import installer
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user