Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Setup downloads: retry once with a longer wait when every source fails on a slow network

Bowen Xue329c5d892771
diff --git a/freevideo.ps1 b/freevideo.ps1
index ecaa21f..f112fbf 100644
--- a/freevideo.ps1
+++ b/freevideo.ps1
@@ -92,8 +92,6 @@ try {
-EngineRoot $freevideoRoot -LogPath $bootstrapLog -GithubSources $routes `
-ProxyRoutes $proxyRoutes -OfficialOnly:$officialOnly
$env:UV_PYTHON_INSTALL_DIR = Join-Path $bootstrapRoot 'python'
- $env:UV_HTTP_TIMEOUT = '20'
- $env:UV_HTTP_RETRIES = '1'
$env:UV_NO_CONFIG = '1'
$installed = $false
$pythonRoutes = @($routes | ForEach-Object { "$_/astral-sh/python-build-standalone/releases/download" })
@@ -101,18 +99,40 @@ try {
$pythonRoutes = @($freevideoSavedEnvironment['UV_PYTHON_INSTALL_MIRROR']) + $pythonRoutes
}
$attempt = 0
- foreach ($route in $pythonRoutes) {
- foreach ($proxyRoute in $proxyRoutes) {
- if ($installed) { break }
- $attempt++
- $env:UV_PYTHON_INSTALL_MIRROR = $route
- Write-Progress -Activity 'FreeVideo bootstrap' -Status ('Install isolated Python ' + $versions.python)
- $pythonExit = Invoke-FreeVideoBootstrapCommand -Executable $uv `
- -Arguments @('python', 'install', '--no-bin', '--no-registry', '--no-progress', '--color', 'never', $versions.python) `
- -LogPath $bootstrapLog -Label ("Install Python $($versions.python), attempt $attempt ($proxyRoute connection)") `
- -Direct:($proxyRoute -eq 'direct')
- if ($pythonExit -eq 0) { $installed = $true; break }
- Write-Host "Python install source $attempt returned exit code $pythonExit. Details retained in $bootstrapLog"
+ $allNetworkFailures = $true
+ # Keep these defaults and the notice in sync with network.py (CPU tests).
+ $pythonRetryProfiles = @(
+ @{Mode='fast'; UV_HTTP_TIMEOUT='20'; UV_HTTP_RETRIES='1'},
+ @{Mode='patient'; UV_HTTP_TIMEOUT='120'; UV_HTTP_RETRIES='5'}
+ )
+ foreach ($profile in $pythonRetryProfiles) {
+ if ($installed) { break }
+ if ($profile.Mode -eq 'patient') {
+ if (-not $allNetworkFailures) { break }
+ Write-Host 'The network is slow. Downloading again; this may take a while.'
+ }
+ foreach ($name in @('UV_HTTP_TIMEOUT', 'UV_HTTP_RETRIES')) {
+ $value = $freevideoSavedEnvironment[$name]
+ if ($null -eq $value) { $value = $profile[$name] }
+ [Environment]::SetEnvironmentVariable($name, $value, 'Process')
+ }
+ foreach ($route in $pythonRoutes) {
+ foreach ($proxyRoute in $proxyRoutes) {
+ if ($installed) { break }
+ $attempt++
+ $env:UV_PYTHON_INSTALL_MIRROR = $route
+ Write-Progress -Activity 'FreeVideo bootstrap' -Status ('Install isolated Python ' + $versions.python)
+ $pythonOutput = ''
+ $pythonLabel = "Install Python $($versions.python), attempt $attempt ($proxyRoute connection)"
+ if ($profile.Mode -eq 'patient') { $pythonLabel += ", $($profile.Mode)" }
+ $pythonExit = Invoke-FreeVideoBootstrapCommand -Executable $uv `
+ -Arguments @('python', 'install', '--no-bin', '--no-registry', '--no-progress', '--color', 'never', $versions.python) `
+ -LogPath $bootstrapLog -Label $pythonLabel `
+ -Direct:($proxyRoute -eq 'direct') -OutputTail ([ref]$pythonOutput)
+ if ($pythonExit -eq 0) { $installed = $true; break }
+ if (-not (Test-FreeVideoSlowDownloadFailure $pythonOutput)) { $allNetworkFailures = $false }
+ Write-Host "Python install source $attempt returned exit code $pythonExit. Details retained in $bootstrapLog"
+ }
}
}
if (-not $installed) { throw "Python installation failed (uv exit $pythonExit). Check your network or connection mode in Downloads. See $bootstrapLog and retry." }
@@ -123,6 +143,11 @@ try {
Write-Progress -Activity 'FreeVideo bootstrap' -Completed
}
}
+ # Restore only our download defaults before Python determines user overrides.
+ # A null saved value removes the variable from the child environment.
+ foreach ($name in @('UV_HTTP_TIMEOUT', 'UV_HTTP_RETRIES')) {
+ [Environment]::SetEnvironmentVariable($name, $freevideoSavedEnvironment[$name], 'Process')
+ }
& $freevideoPython @freevideoPythonPrefix -B -X utf8 -m freevideo_engine.managed @freevideoArguments
$freevideoExit = $LASTEXITCODE
} catch {
diff --git a/freevideo_engine/bootstrap.py b/freevideo_engine/bootstrap.py
index 8c29a70..37f15c7 100644
--- a/freevideo_engine/bootstrap.py
+++ b/freevideo_engine/bootstrap.py
@@ -1517,7 +1517,8 @@ class Installer:
def packages(self, label, args, family='pypi'):
return network.package_command(self.network, family,
- lambda env, source: self.command(label if source == 'official' else label + '-' + source, args, env=env), self.env)
+ lambda env, source: self.command(label if source == 'official' else label + '-' + source, args, env=env),
+ self.env, notice=lambda message: self.ui.write(message + '\n'))
def python_install(self, uv):
from .system import bootstrap_root
@@ -1542,24 +1543,21 @@ class Installer:
'import sys; print("Reusing verified bootstrap Python: " + sys.executable)'])
return
custom = self.env.get('UV_PYTHON_INSTALL_MIRROR') if self.network.get('mode') != 'official' else None
- sources = (['user-python'] if custom else []) + network.ordered(self.network, 'github')
isolation = ['--no-bin', '--no-registry']
- for source in sources:
- for route in network.route_order(self.network, 'github', source, self.env):
- env = network.route_environment(self.network, 'github', source, self.env, route)
- env.update(UV_HTTP_TIMEOUT='20', UV_HTTP_RETRIES='1')
- env['UV_PYTHON_INSTALL_MIRROR'] = custom if source == 'user-python' else network.source_url('github', source, self.env) + '/astral-sh/python-build-standalone/releases/download'
- try:
- result = self.command('python-' + source + '-' + route, [uv, 'python', 'install', *isolation, self.versions['python']], env=env)
- network.route_health(self.network, 'github', source, route)
- return result
- except RuntimeError as error:
- if not network.retryable(error):
- raise
- network.event(self.network, category='python', source=source, route=route, action='fallback', reason='network-download-failed')
- if not network.connection_failure(error):
- break
- raise RuntimeError('Python download failed on every route; see retained logs')
+ def attempt(source, route, retry_mode):
+ env = network.download_environment(
+ network.route_environment(self.network, 'github', source, self.env, route), retry_mode)
+ env['UV_PYTHON_INSTALL_MIRROR'] = custom if source == 'user-python' else network.source_url('github', source, self.env) + '/astral-sh/python-build-standalone/releases/download'
+ return self.command('python-' + source + '-' + route,
+ [uv, 'python', 'install', *isolation, self.versions['python']], env=env)
+ try:
+ return network.download_command(self.network, 'github', attempt, self.env, category='python',
+ extra_sources=['user-python'] if custom else [],
+ notice=lambda message: self.ui.write(message + '\n'))
+ except network.PackageSourcesError as error:
+ failure = RuntimeError('Python download failed on every route; see retained logs')
+ failure.package_attempts = error.attempts
+ raise failure from error
def install_sage(self, uv, python):
if self.system == 'Windows':
diff --git a/freevideo_engine/network.py b/freevideo_engine/network.py
index 966a25c..4da1905 100644
--- a/freevideo_engine/network.py
+++ b/freevideo_engine/network.py
@@ -42,6 +42,10 @@ SAMPLE_BYTES = 256 * 1024
SPEED_SAMPLE_BYTES = 32 * 2**20
SPEED_SAMPLE_SECONDS = 3.
MIN_TRANSFER_LIMIT = 1024 * 1024
+# One quick pass over sources/routes, followed by at most one patient pass.
+# These are inactivity timeouts, not deadlines for an entire installation.
+DOWNLOAD_RETRY_PROFILES = (('fast', '20', '1'), ('patient', '120', '5'))
+PATIENT_DOWNLOAD_NOTICE = 'The network is slow. Downloading again; this may take a while.'
def proxy_environment(environ=None):
@@ -564,57 +568,136 @@ def _package_attempt(error, source, route):
returncode=getattr(error, 'returncode', None), detail=detail, summary=summary)
-def package_environment(network, family, name, environ=None, *, route=None):
+def download_environment(environ, retry_mode='fast'):
+ """Apply shared uv/pip defaults without replacing any user setting."""
+ _, timeout, retries = next(row for row in DOWNLOAD_RETRY_PROFILES if row[0] == retry_mode)
+ env = dict(environ)
+ for key, value in (('UV_HTTP_TIMEOUT', timeout), ('UV_HTTP_RETRIES', retries),
+ ('PIP_DEFAULT_TIMEOUT', timeout), ('PIP_RETRIES', retries)):
+ env.setdefault(key, value)
+ return env
+
+
+# Only a validation failure counts: a package or service that merely has
+# "checksum" in its name must stay eligible for the slow-network retry. Keep in
+# sync with fv_slow_download_failure in scripts/bootstrap_linux.sh.
+_INTEGRITY_FAILURE = re.compile(
+ r"\b(?:invalid|bad|wrong|incorrect|mismatched?)\s+checksums?\b"
+ r"|\bchecksums?\s+(?:mismatch|error|failed|failure)\b"
+ r"|\bchecksums?\s+(?:verification|validation)\s+(?:failed|failure|error)\b"
+ r"|\bchecksums?\s+(?:does not|doesn't|did not|didn't|do not|don't)\s+match\b"
+ r"|\b(?:does not|doesn't|did not|didn't|do not|don't)\s+match\s+(?:the\s+|its\s+|expected\s+)?(?:checksums?|hash(?:es)?)\b"
+ r"|\bhash\s+(?:mismatch|check\s+failed|does\s+not\s+match)\b|\bhashes\s+(?:do\s+not|didn't)\s+match\b"
+ r"|\bsha-?256\s+mismatch\b|\bdigest\s+mismatch\b"
+ r"|\bintegrity\s+(?:check|verification)\s+failed\b")
+
+
+def _download_integrity_failure(detail):
+ # URL paths may contain validation words without a validation failure.
+ detail = re.sub(r'https?://\S+', '', detail.lower())
+ return bool(_INTEGRITY_FAILURE.search(detail))
+
+
+def slow_download_failure(detail):
+ """Mirror fallback is broader than permission to retry a whole slow pass."""
+ return (connection_failure(detail) and not _download_integrity_failure(detail)
+ and not re.search(r'\b(?:401|403|404|410)\b', detail)
+ and not any(word in detail.lower() for word in
+ ('certificate verify failed', 'certificate_verify_failed',
+ 'invalid peer certificate', 'unknown issuer', 'not found',
+ 'resolutionimpossible', 'failed to build', 'invalid wheel',
+ 'permission denied', 'no space left on device', 'disk full')))
+
+
+def package_environment(network, family, name, environ=None, *, route=None, retry_mode='fast'):
env = route_environment(network, family, name, environ, route)
+ env = download_environment(env, retry_mode)
endpoint = source_url(family, name, environ)
if family.startswith('torch-'):
endpoint += '/' + family.split('-')[1]
- env.update(UV_DEFAULT_INDEX=endpoint, UV_INDEX_URL=endpoint, PIP_INDEX_URL=endpoint,
- UV_HTTP_TIMEOUT='20', UV_HTTP_RETRIES='1', PIP_DEFAULT_TIMEOUT='20', PIP_RETRIES='1',
- UV_NO_CONFIG='1')
+ env.update(UV_DEFAULT_INDEX=endpoint, UV_INDEX_URL=endpoint, PIP_INDEX_URL=endpoint, UV_NO_CONFIG='1')
for key in ('UV_INDEX', 'UV_EXTRA_INDEX_URL', 'PIP_EXTRA_INDEX_URL'):
env.pop(key, None)
return env
-def package_command(network, family, run, env=None):
+def download_command(network, family, run, env=None, *, category=None, extra_sources=(), notice=None):
+ """Run a source/route callback with the same bounded policy for uv and pip.
+
+ Callbacks receive (source, route, retry_mode); each builds its child env from
+ the original environment, so our fast defaults never become user overrides.
+ """
+ category = category or family
+ operation = 'python' if category == 'python' else 'package'
attempts = []
- for name in ordered(network, family):
- for route in route_order(network, family, name, env):
- event(network, category=family, source=name, route=route, action='package-attempt')
- try:
- attempt_env = package_environment(network, family, name, env, route=route)
- # The host setup uses these private markers to retain one log
- # per source/route instead of overwriting the first failure.
- # They are never included in a report or sent to a package
- # manager as configuration.
- attempt_env['FREEVIDEO_PACKAGE_SOURCE'] = name
- attempt_env['FREEVIDEO_PACKAGE_ROUTE'] = route
- result = run(attempt_env, name)
- source_health(network, family, name, True)
- route_health(network, family, name, route)
- return result
- except (RuntimeError, subprocess.CalledProcessError) as error:
- attempt = _package_attempt(error, name, route)
- attempts.append(attempt)
- event(network, category=family, source=name, route=route, action='package-failed',
- error_type=attempt['error_type'], returncode=attempt['returncode'],
- detail=attempt['detail'], summary=attempt['summary'])
- detail = attempt['detail']
- if not retryable(detail):
- # Preserve the original exception type and traceback for
- # build/configuration errors, but make the attempt data
- # available to the local report collector.
- try:
- error.package_attempts = attempts
- except Exception:
- pass
- raise
- event(network, category=family, source=name, route=route, action='package-fallback', reason='network-or-unavailable-pinned-package')
- if not connection_failure(detail):
- break
- source_health(network, family, name, False)
- raise PackageSourcesError(family, attempts)
+ for retry_mode, timeout, retries in DOWNLOAD_RETRY_PROFILES:
+ if retry_mode == 'patient':
+ if not attempts or not all(slow_download_failure(row['detail']) for row in attempts):
+ break
+ event(network, category=category, action='download-round-result', retry_mode='fast',
+ result='failed', attempts=len(attempts))
+ event(network, category=category, action='download-patient-retry', retry_mode=retry_mode,
+ default_timeout_seconds=int(timeout), default_retries=int(retries))
+ if notice is None:
+ print(PATIENT_DOWNLOAD_NOTICE, flush=True)
+ else:
+ notice(PATIENT_DOWNLOAD_NOTICE)
+ round_start = len(attempts)
+ retry_details = {'retry_mode': retry_mode} if retry_mode == 'patient' else {}
+ if retry_mode == 'patient':
+ event(network, category=category, action='download-round-start', retry_mode=retry_mode)
+ # Re-read health and allowed routes after the fast pass. Equal failures
+ # retain the existing probe order; no new connectivity probes are made.
+ for name in [*extra_sources, *ordered(network, family)]:
+ for route in route_order(network, family, name, env):
+ if operation == 'package' or retry_mode == 'patient':
+ event(network, category=category, source=name, route=route,
+ action=operation + '-attempt', **retry_details)
+ try:
+ result = run(name, route, retry_mode)
+ source_health(network, family, name, True)
+ route_health(network, family, name, route)
+ if retry_mode == 'patient':
+ event(network, category=category, action='download-round-result', retry_mode=retry_mode,
+ result='success', attempts=len(attempts)-round_start+1)
+ return result
+ except (RuntimeError, subprocess.CalledProcessError) as error:
+ attempt = dict(_package_attempt(error, name, route), retry_mode=retry_mode)
+ attempts.append(attempt)
+ event(network, category=category, source=name, route=route, action=operation + '-failed',
+ error_type=attempt['error_type'], returncode=attempt['returncode'],
+ detail=attempt['detail'], summary=attempt['summary'], **retry_details)
+ detail = attempt['detail']
+ if (not retryable(detail)
+ or (retry_mode == 'patient' and not slow_download_failure(detail))):
+ if retry_mode == 'patient':
+ event(network, category=category, action='download-round-result', retry_mode=retry_mode,
+ result='failed', attempts=len(attempts)-round_start, reason='non-network-error')
+ # Retain original build/configuration/integrity errors.
+ try:
+ error.package_attempts = attempts
+ except Exception:
+ pass
+ raise
+ event(network, category=category, source=name, route=route, action=operation + '-fallback',
+ reason='network-or-unavailable-pinned-package', **retry_details)
+ if not connection_failure(detail):
+ break
+ source_health(network, family, name, False)
+ if retry_mode == 'patient':
+ event(network, category=category, action='download-round-result', retry_mode=retry_mode,
+ result='failed', attempts=len(attempts)-round_start)
+ raise PackageSourcesError(category, attempts)
+
+
+def package_command(network, family, run, env=None, *, notice=None):
+ def attempt(name, route, retry_mode):
+ attempt_env = package_environment(network, family, name, env, route=route, retry_mode=retry_mode)
+ # Private markers retain per-source/route logs; no package configuration.
+ attempt_env['FREEVIDEO_PACKAGE_SOURCE'] = name
+ attempt_env['FREEVIDEO_PACKAGE_ROUTE'] = route
+ return run(attempt_env, name)
+ return download_command(network, family, attempt, env, notice=notice)
def hash_file(path, algorithm='sha256', git_blob=False, *, discard_cache=False, progress=None):
diff --git a/freevideo_engine/windows_bootstrap.ps1 b/freevideo_engine/windows_bootstrap.ps1
index 7040f99..b1bcb68 100644
--- a/freevideo_engine/windows_bootstrap.ps1
+++ b/freevideo_engine/windows_bootstrap.ps1
@@ -5,7 +5,8 @@ function Invoke-FreeVideoBootstrapCommand {
[Parameter(Mandatory=$true)][string[]]$Arguments,
[Parameter(Mandatory=$true)][string]$LogPath,
[Parameter(Mandatory=$true)][string]$Label,
- [switch]$Direct
+ [switch]$Direct,
+ [ref]$OutputTail
)
# Windows PowerShell 5.1 turns redirected native stderr into ErrorRecords.
# uv writes normal progress there. Let the child finish and inspect its
@@ -24,6 +25,7 @@ function Invoke-FreeVideoBootstrapCommand {
$log = [IO.StreamWriter]::new($LogPath, $true, $encoding)
$log.AutoFlush = $true
$previousExitCode = $global:LASTEXITCODE
+ $tail = [Collections.Generic.Queue[string]]::new()
$savedProxy = @{}
if ($Direct) {
foreach ($name in @('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY')) {
@@ -37,7 +39,14 @@ function Invoke-FreeVideoBootstrapCommand {
# LASTEXITCODE would shadow their result and keep a stale/null value.
$global:LASTEXITCODE = $null
$log.WriteLine(('[{0}] {1}' -f [DateTime]::UtcNow.ToString('o'), $Label))
- & $Executable @Arguments 2>&1 | ForEach-Object { $log.WriteLine($_.ToString()) }
+ & $Executable @Arguments 2>&1 | ForEach-Object {
+ $line = $_.ToString()
+ $log.WriteLine($line)
+ if ($OutputTail) {
+ $tail.Enqueue($line.Substring([Math]::Max(0, $line.Length - 4096)))
+ if ($tail.Count -gt 12) { [void]$tail.Dequeue() }
+ }
+ }
$nativeExit = $global:LASTEXITCODE
if ($null -eq $nativeExit) { throw "Native command did not return an exit code: $Executable" }
$log.WriteLine("Exit code: $nativeExit")
@@ -46,6 +55,7 @@ function Invoke-FreeVideoBootstrapCommand {
$log.WriteLine('Invocation failed: ' + $_.Exception.Message)
throw
} finally {
+ if ($OutputTail) { $OutputTail.Value = ($tail.ToArray() -join "`n") }
foreach ($name in $savedProxy.Keys) {
[Environment]::SetEnvironmentVariable($name, $savedProxy[$name], 'Process')
}
@@ -54,6 +64,14 @@ function Invoke-FreeVideoBootstrapCommand {
}
}
+function Test-FreeVideoSlowDownloadFailure {
+ param([string]$Detail)
+ # Keep the patient-round gate aligned with network.slow_download_failure.
+ return ($Detail -match 'timed out|timeout|connection|could not resolve|failed to download|failed to fetch|network is unreachable|ssl|tls|http status|status code|requested url returned error|rpc failed|early eof|unable to access|remote end hung up|couldn''t connect|proxy' -and
+ $Detail -notmatch '\b(401|403|404|410)\b' -and
+ $Detail -notmatch 'no solution found|no matching distribution|could not find a version|checksum|hash mismatch|hashes do not match|hashes didn''t match|hash does not match|hash check failed|sha256 mismatch|sha-256 mismatch|digest mismatch|integrity|certificate verify failed|certificate_verify_failed|invalid peer certificate|unknown issuer|not found|resolutionimpossible|failed to build|invalid wheel|permission denied|no space left on device|disk full')
+}
+
function Test-FreeVideoUvArchive {
param([string]$Path, [string]$Hash, [long]$Bytes)
return ((Test-Path -LiteralPath $Path -PathType Leaf) -and
diff --git a/scripts/bootstrap_linux.sh b/scripts/bootstrap_linux.sh
index b5ebc2f..32bcc15 100644
--- a/scripts/bootstrap_linux.sh
+++ b/scripts/bootstrap_linux.sh
@@ -9,6 +9,30 @@ FV_PYTHON_VERSION=3.12.3
fv_note() { printf 'FreeVideo: %s\n' "$*" >&2; }
fv_fail() { fv_note "$*"; return 1; }
+# Match network.slow_download_failure: unavailable artifacts and local errors
+# may try another source, but must not earn a longer download round.
+fv_slow_download_failure() {
+ # Keep in sync with slow_download_failure in freevideo_engine/network.py.
+ # Only a validation failure blocks the slow retry: a package or service
+ # with "checksum" in its name is still a plain network failure.
+ local detail="${1,,}" sp='[[:space:]]+' edge='(^|[^[:alnum:]_])' q="'"
+ while [[ "$detail" =~ https?://[^[:space:]]+ ]]; do detail=${detail//"${BASH_REMATCH[0]}"/}; done
+ local aux="(does${sp}not|doesn${q}t|did${sp}not|didn${q}t|do${sp}not|don${q}t)" end='($|[^[:alnum:]_])'
+ local integrity="${edge}(invalid|bad|wrong|incorrect|mismatched?)${sp}checksums?${end}"
+ integrity+="|${edge}checksums?${sp}(mismatch|error|failed|failure)${end}"
+ integrity+="|${edge}checksums?${sp}(verification|validation)${sp}(failed|failure|error)${end}"
+ integrity+="|${edge}checksums?${sp}${aux}${sp}match${end}"
+ integrity+="|${edge}${aux}${sp}match${sp}(the${sp}|its${sp}|expected${sp})?(checksums?|hash(es)?)${end}"
+ integrity+="|${edge}hash${sp}(mismatch|check${sp}failed|does${sp}not${sp}match)${end}"
+ integrity+="|${edge}hashes${sp}(do${sp}not|didn${q}t)${sp}match${end}"
+ integrity+="|${edge}(sha-?256|digest)${sp}mismatch${end}"
+ integrity+="|${edge}integrity${sp}(check|verification)${sp}failed${end}"
+ [[ "$detail" =~ timed\ out|timeout|connection|could\ not\ resolve|failed\ to\ download|failed\ to\ fetch|network\ is\ unreachable|ssl|tls|http\ status|status\ code|requested\ url\ returned\ error|rpc\ failed|early\ eof|unable\ to\ access|remote\ end\ hung\ up|couldn\'t\ connect|proxy ]] &&
+ [[ ! "$detail" =~ (^|[^[:alnum:]_])(401|403|404|410)($|[^[:alnum:]_]) ]] &&
+ [[ ! "$detail" =~ $integrity ]] &&
+ [[ ! "$detail" =~ no\ solution\ found|no\ matching\ distribution|could\ not\ find\ a\ version|certificate\ verify\ failed|certificate_verify_failed|invalid\ peer\ certificate|unknown\ issuer|not\ found|resolutionimpossible|failed\ to\ build|invalid\ wheel|permission\ denied|no\ space\ left\ on\ device|disk\ full ]]
+}
+
fv_python_ok() {
[[ -n "$1" ]] && command -v -- "$1" >/dev/null 2>&1 &&
"$1" -I -B -c 'import sys; sys.exit(0 if sys.version_info >= (3, 9) else 1)' >/dev/null 2>&1
@@ -222,6 +246,12 @@ fv_install_python() (
fv_note "Files and log: $FREEVIDEO_BOOTSTRAP_ROOT"
fv_download_uv || exit 1
local uv="$FREEVIDEO_BOOTSTRAP_ROOT/tools/uv-x86_64-unknown-linux-gnu/uv" source route attempt=0
+ local retry_mode timeout retries attempt_log attempt_dir attempt_detail python_exit tee_exit all_network_failures=1
+ local -a pipe_status
+ # The capture only classifies failures: without a writable place for it the
+ # install still runs, it just never starts the slow-network round.
+ attempt_dir=$(mktemp -d 2>/dev/null) || attempt_dir=$(mktemp -d "$FREEVIDEO_BOOTSTRAP_ROOT/.attempt.XXXXXX" 2>/dev/null) || attempt_dir=''
+ trap '[[ -z "$attempt_dir" ]] || rm -rf -- "$attempt_dir"' EXIT
local -a fv_routes=()
fv_proxy_routes
local -a sources=(https://github.com/astral-sh/python-build-standalone/releases/download)
@@ -231,17 +261,53 @@ fv_install_python() (
sources+=(https://ghfast.top/https://github.com/astral-sh/python-build-standalone/releases/download)
fi
export UV_PYTHON_INSTALL_DIR="$FREEVIDEO_BOOTSTRAP_ROOT/python" UV_CACHE_DIR="$FREEVIDEO_BOOTSTRAP_ROOT/cache"
- export UV_HTTP_TIMEOUT=20 UV_HTTP_RETRIES=1
- for source in "${sources[@]}"; do
- for route in "${fv_routes[@]}"; do
- ((attempt+=1))
- fv_note "Installing private Python, attempt $attempt ($route connection)…"
- printf 'Python source %s\n' "$attempt" >>"$FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log"
- if UV_PYTHON_INSTALL_MIRROR="$source" fv_with_route "$route" "$uv" --no-config python install --no-bin --no-registry \
- --no-progress --color never "$FV_PYTHON_VERSION" >>"$FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log" 2>&1; then
- fv_python_ok "$UV_PYTHON_INSTALL_DIR/cpython-$FV_PYTHON_VERSION-linux-x86_64-gnu/bin/python3.12" && exit 0
- fi
- fv_note 'Python preparation failed; retrying the next source. Existing files retained.'
+ # Keep these defaults and the notice in sync with network.py (CPU tests).
+ for retry_mode in fast patient; do
+ timeout=20 retries=1
+ if [[ "$retry_mode" == patient ]]; then
+ (( all_network_failures )) || break
+ timeout=120 retries=5
+ fv_note 'The network is slow. Downloading again; this may take a while.'
+ fi
+ for source in "${sources[@]}"; do
+ for route in "${fv_routes[@]}"; do
+ ((attempt+=1))
+ fv_note "Installing private Python, attempt $attempt ($route connection)…"
+ if [[ "$retry_mode" == patient ]]; then
+ printf 'Python source %s (%s)\n' "$attempt" "$retry_mode" >>"$FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log"
+ else
+ printf 'Python source %s\n' "$attempt" >>"$FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log"
+ fi
+ attempt_log=''
+ [[ -z "$attempt_dir" ]] || attempt_log=$(mktemp "$attempt_dir/output.XXXXXX" 2>/dev/null) || attempt_log=''
+ # Command-local defaults never turn our fast values into user settings.
+ # Classify this attempt independently of main-log truncation/rotation.
+ if UV_HTTP_TIMEOUT="${UV_HTTP_TIMEOUT-$timeout}" UV_HTTP_RETRIES="${UV_HTTP_RETRIES-$retries}" \
+ UV_PYTHON_INSTALL_MIRROR="$source" fv_with_route "$route" "$uv" --no-config python install --no-bin --no-registry \
+ --no-progress --color never "$FV_PYTHON_VERSION" 2>&1 | \
+ tee -a -- "${attempt_log:-/dev/null}" >>"$FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log"; then
+ pipe_status=("${PIPESTATUS[@]}")
+ else
+ pipe_status=("${PIPESTATUS[@]}")
+ fi
+ python_exit=${pipe_status[0]} tee_exit=${pipe_status[1]:-0}
+ attempt_detail=''
+ [[ -z "$attempt_log" ]] || attempt_detail=$(tail -n 12 -- "$attempt_log")
+ [[ -z "$attempt_log" ]] || rm -f -- "$attempt_log"
+ if (( tee_exit != 0 )); then
+ # The main log could not take the output: keep what uv said on screen.
+ [[ -z "$attempt_detail" ]] || printf '%s\n' "$attempt_detail" >&2
+ fv_fail "Could not retain Python installation output. Check $FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log and retry the same command."
+ exit 1
+ fi
+ if (( python_exit == 0 )); then
+ fv_python_ok "$UV_PYTHON_INSTALL_DIR/cpython-$FV_PYTHON_VERSION-linux-x86_64-gnu/bin/python3.12" && exit 0
+ all_network_failures=0
+ elif ! fv_slow_download_failure "$attempt_detail"; then
+ all_network_failures=0
+ fi
+ fv_note 'Python preparation failed; retrying the next source. Existing files retained.'
+ done
done
done
fv_fail "Could not prepare Python. Check $FREEVIDEO_BOOTSTRAP_ROOT/bootstrap.log and retry the same command."