mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
Use new sub_run function
This commit is contained in:
+18
-38
@@ -265,18 +265,13 @@ def pip(arg: str, ignore: bool = False, quiet: bool = True, uv = True):
|
||||
all_args = f'{pip_log}{arg} {env_args}'.strip()
|
||||
if not quiet:
|
||||
log.debug(f'Running: {pipCmd}="{all_args}"')
|
||||
result = subprocess.run(f'"{sys.executable}" -m {pipCmd} {all_args}', shell=True, check=False, env=os.environ, capture_output=True)
|
||||
txt = result.stdout.decode(encoding="utf8", errors="ignore")
|
||||
result, txt = sub_run(sys.executable, "-m", pipCmd, all_args)
|
||||
if len(result.stderr) > 0:
|
||||
if uv and result.returncode != 0:
|
||||
err = result.stderr.decode(encoding="utf8", errors="ignore")
|
||||
log.warning(f'Install: cmd="{pipCmd}" args="{all_args}" cannot use uv, fallback to pip')
|
||||
debug(f'Install: uv pip error: {err}')
|
||||
debug(f'Install: uv pip error: {result.stderr}')
|
||||
cleanup_broken_packages()
|
||||
return pip(originalArg, ignore, quiet, uv=False)
|
||||
else:
|
||||
txt += ('\n' if len(txt) > 0 else '') + result.stderr.decode(encoding="utf8", errors="ignore")
|
||||
txt = txt.strip()
|
||||
debug(f'Install {pipCmd}: {txt}')
|
||||
if result.returncode != 0 and not ignore:
|
||||
errors.append(f'pip: {package}')
|
||||
@@ -312,25 +307,21 @@ def git(arg: str, folder: str = None, ignore: bool = False, optional: bool = Fal
|
||||
git_cmd = os.environ.get('GIT', "git")
|
||||
if git_cmd != "git":
|
||||
git_cmd = os.path.abspath(git_cmd)
|
||||
result = subprocess.run(f'"{git_cmd}" {arg}', check=False, shell=True, env=os.environ, capture_output=True, cwd=folder or '.')
|
||||
stdout = result.stdout.decode(encoding="utf8", errors="ignore")
|
||||
if len(result.stderr) > 0:
|
||||
stdout += ('\n' if len(stdout) > 0 else '') + result.stderr.decode(encoding="utf8", errors="ignore")
|
||||
stdout = stdout.strip()
|
||||
result, txt = sub_run(git_cmd, arg, cwd=folder or ".")
|
||||
if result.returncode != 0 and not ignore:
|
||||
if folder is None:
|
||||
folder = 'root'
|
||||
if "couldn't find remote ref" in stdout: # not a git repo
|
||||
if "couldn't find remote ref" in txt: # not a git repo
|
||||
log.error(f'Git: folder="{folder}" could not identify repository')
|
||||
elif "no submodule mapping found" in stdout:
|
||||
elif "no submodule mapping found" in txt:
|
||||
log.warning(f'Git: folder="{folder}" submodules changed')
|
||||
elif 'or stash them' in stdout:
|
||||
elif 'or stash them' in txt:
|
||||
log.error(f'Git: folder="{folder}" local changes detected')
|
||||
else:
|
||||
log.error(f'Git: folder="{folder}" arg="{arg}" output={stdout}')
|
||||
log.error(f'Git: folder="{folder}" arg="{arg}" output={txt}')
|
||||
errors.append(f'git: {folder}')
|
||||
ts('git', t_start)
|
||||
return stdout
|
||||
return txt
|
||||
|
||||
|
||||
# reattach as needed as head can get detached
|
||||
@@ -944,13 +935,10 @@ def run_extension_installer(folder):
|
||||
if os.environ.get('PYTHONPATH', None) is not None:
|
||||
seperator = ';' if sys.platform == 'win32' else ':'
|
||||
env['PYTHONPATH'] += seperator + os.environ.get('PYTHONPATH', None)
|
||||
result = subprocess.run(f'"{sys.executable}" "{path_installer}"', shell=True, env=env, check=False, capture_output=True, cwd=folder)
|
||||
txt = result.stdout.decode(encoding="utf8", errors="ignore")
|
||||
debug(f'Extension installer: file="{path_installer}" {txt}')
|
||||
result, txt = sub_run(sys.executable, path_installer, env=env, cwd=folder)
|
||||
debug(f'Extension installer: file="{path_installer}" {result.stdout}')
|
||||
if result.returncode != 0:
|
||||
errors.append(f'ext: {os.path.basename(folder)}')
|
||||
if len(result.stderr) > 0:
|
||||
txt = txt + '\n' + result.stderr.decode(encoding="utf8", errors="ignore")
|
||||
log.error(f'Extension installer error: {path_installer}')
|
||||
log.debug(txt)
|
||||
except Exception as e:
|
||||
@@ -1279,17 +1267,14 @@ def get_version(force=False):
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
res = subprocess.run('git log --pretty=format:"%h %ad" -1 --date=short', capture_output=True, shell=True, check=True)
|
||||
ver = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ' '
|
||||
ver = sub_run('git log --pretty=format:"%h %ad" -1 --date=short', check=True)[0].stdout or ' '
|
||||
commit, updated = ver.split(' ')
|
||||
version['commit'], version['updated'] = commit, updated
|
||||
except Exception as e:
|
||||
log.warning(f'Version: where=commit {e}')
|
||||
try:
|
||||
res = subprocess.run('git remote get-url origin', capture_output=True, shell=True, check=True)
|
||||
origin = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
|
||||
res = subprocess.run('git rev-parse --abbrev-ref HEAD', capture_output=True, shell=True, check=True)
|
||||
branch_name = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
|
||||
origin = sub_run('git remote get-url origin', check=True)[0].stdout
|
||||
branch_name = sub_run('git rev-parse --abbrev-ref HEAD', check=True)[0].stdout
|
||||
version['url'] = origin.replace('\n', '').removesuffix('.git') + '/tree/' + branch_name.replace('\n', '')
|
||||
version['branch'] = branch_name.replace('\n', '')
|
||||
if version['branch'] == 'HEAD':
|
||||
@@ -1298,10 +1283,8 @@ def get_version(force=False):
|
||||
log.warning(f'Version: where=branch {e}')
|
||||
try:
|
||||
if os.path.exists('extensions-builtin/sdnext-modernui'):
|
||||
res = subprocess.run('git rev-parse --abbrev-ref HEAD', capture_output=True, shell=True, check=True, cwd='extensions-builtin/sdnext-modernui')
|
||||
branch_ui = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
|
||||
branch_ui = 'dev' if 'dev' in branch_ui else 'main'
|
||||
version['ui'] = branch_ui
|
||||
branch_ui = sub_run('git rev-parse --abbrev-ref HEAD', check=True, cwd='extensions-builtin/sdnext-modernui')[0].stdout
|
||||
version['ui'] = 'dev' if 'dev' in branch_ui else 'main'
|
||||
else:
|
||||
version['ui'] = 'unavailable'
|
||||
except Exception as e:
|
||||
@@ -1311,10 +1294,8 @@ def get_version(force=False):
|
||||
if os.environ.get('SD_KANVAS_DISABLE', None) is not None:
|
||||
version['kanvas'] = 'disabled'
|
||||
elif os.path.exists('extensions-builtin/sdnext-kanvas'):
|
||||
res = subprocess.run('git rev-parse --abbrev-ref HEAD', capture_output=True, shell=True, check=True, cwd='extensions-builtin/sdnext-kanvas')
|
||||
branch_kanvas = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
|
||||
branch_kanvas = 'dev' if 'dev' in branch_kanvas else 'main'
|
||||
version['kanvas'] = branch_kanvas
|
||||
branch_kanvas = sub_run('git rev-parse --abbrev-ref HEAD', check=True, cwd='extensions-builtin/sdnext-kanvas')[0].stdout
|
||||
version['kanvas'] = 'dev' if 'dev' in branch_kanvas else 'main'
|
||||
else:
|
||||
version['kanvas'] = 'unavailable'
|
||||
except Exception as e:
|
||||
@@ -1502,8 +1483,7 @@ def get_state():
|
||||
def _get_commit(item):
|
||||
ext, ext_dir = item
|
||||
try:
|
||||
res = subprocess.run('git rev-parse HEAD', capture_output=True, shell=True, check=False, cwd=ext_dir)
|
||||
return ext, res.stdout.decode(encoding='utf8', errors='ignore').strip()
|
||||
return ext, sub_run('git rev-parse HEAD', cwd=ext_dir)[0].stdout
|
||||
except Exception:
|
||||
return ext, ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user