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.
Run Git in a short real folder for deep Windows installs; log why a step was stopped
Bowen Xue40f93a1b2d7c
diff --git a/freevideo_engine/bootstrap.py b/freevideo_engine/bootstrap.pyindex 28194a4..89bd30c 100644--- a/freevideo_engine/bootstrap.py+++ b/freevideo_engine/bootstrap.py@@ -31,7 +31,7 @@ from .install_tuning import build_parallelism, required_models, cache_compatiblefrom .terminal_ui import TerminalUI, LogProgressfrom .locking import runtime_lock, LOCK_ENVfrom .environments import (ENVIRONMENTS, environment_names, select_layout, role_pythons, constraints_file,- bootstrap_versions, uv_file_arguments, uv_build_environment, git_long_path_environment)+ bootstrap_versions, uv_file_arguments, uv_build_environment)from . import disk_spacefrom . import networkfrom . import processes@@ -1407,9 +1407,6 @@ class Installer:env = dict(env, FREEVIDEO_INSTALL_PROGRESS='1')args, cwd = uv_file_arguments(args, cwd)env = uv_build_environment(args, self.root, env)- if label == 'vdn-source':- # Its Git folders are made below a deep root; see git_long_path_environment.- env = git_long_path_environment(self.root, env)with self.state_lock:index = len(self.state['steps'])log = self.run_dir / ('%02d-%s.log' % (index, label))@@ -1478,6 +1475,12 @@ class Installer:row['error'] = repr(error)if child is not None and child.poll() is None:processes.stop(child)+ # A step stopped from outside leaves nothing else in its log to explain why.+ try:+ with log.open('a', encoding='utf-8') as stream:+ stream.write('\nStopped: %s\n' % error)+ except OSError:+ passraisefinally:update_progress(final=True)diff --git a/freevideo_engine/environments.py b/freevideo_engine/environments.pyindex 5f727fd..276df74 100644--- a/freevideo_engine/environments.py+++ b/freevideo_engine/environments.py@@ -36,36 +36,6 @@ UV_FILE_LIST_OPTIONS = frozenset(('-c', '--constraint', '--constraints', '-b', 'UV_BUILD_PATH_CHARS = 200-# Git creates and enters its own folders with the ordinary 259-character limit-# even when core.longpaths lets it write deep files. Reserve the clone folder,-# its ".partial-<ns>" name and the longest object path below it.-GIT_PATH_CHARS = 140---def _short_view(root, environ, reserve):- """The view that leaves `reserve` characters below `root`, or None when none can be had."""- from . import launch_view, runtime_alias- from .long_paths import path_chars, plain- from .package_paths import WINDOWS_PATH_LIMIT- if not runtime_alias._backend.windows():- return None- root = Path(os.path.abspath(plain(root)))- view = launch_view.current(environ)- if (view is None or not root.is_relative_to(view.real)- or path_chars(launch_view.value(root, view)) + 1 + reserve > WINDOWS_PATH_LIMIT):- try:- view = launch_view.View(root, runtime_alias.runtime_view(root, longest=reserve))- except OSError as error:- if (path_chars(root) + 1 + reserve <= WINDOWS_PATH_LIMIT- and runtime_alias._backend.ansi_path(root)):- view = launch_view.View(root, root)- else:- return None # No short entry: keep the old behaviour.- if path_chars(launch_view.value(root, view)) + 1 + reserve > WINDOWS_PATH_LIMIT:- return None- return view--def uv_build_environment(command, root, environ):"""Windows uv pip builds use a short view of the existing cache and scratch.@@ -77,12 +47,26 @@ def uv_build_environment(command, root, environ):or list(command[1:2]) != ['pip']):return environfrom . import launch_view, runtime_alias- from .long_paths import io_path+ from .long_paths import io_path, path_chars, plain+ from .package_paths import WINDOWS_PATH_LIMITfrom .triton_compat import TEMP_KEYS, TEMP_ROOT_ENV, _writable_temporary- view = _short_view(root, environ, UV_BUILD_PATH_CHARS)- if view is None:+ if not runtime_alias._backend.windows():return environ- temporary = Path(launch_view.value(Path(os.path.abspath(root)) / 'tmp' / 'uv', view))+ root = Path(os.path.abspath(plain(root)))+ view = launch_view.current(environ)+ if (view is None or not root.is_relative_to(view.real)+ or path_chars(launch_view.value(root, view)) + 1 + UV_BUILD_PATH_CHARS > WINDOWS_PATH_LIMIT):+ try:+ view = launch_view.View(root, runtime_alias.runtime_view(root, longest=UV_BUILD_PATH_CHARS))+ except OSError as error:+ if (path_chars(root) + 1 + UV_BUILD_PATH_CHARS <= WINDOWS_PATH_LIMIT+ and runtime_alias._backend.ansi_path(root)):+ view = launch_view.View(root, root)+ else:+ return environ # No short entry: keep the old behaviour; packages without source builds still install.+ if path_chars(launch_view.value(root, view)) + 1 + UV_BUILD_PATH_CHARS > WINDOWS_PATH_LIMIT:+ return environ+ temporary = Path(launch_view.value(root / 'tmp' / 'uv', view))try:for path in (temporary.parent, temporary):folder = io_path(path)@@ -98,23 +82,6 @@ def uv_build_environment(command, root, environ):**{key: str(temporary) for key in (*TEMP_KEYS, TEMP_ROOT_ENV)})-def git_long_path_environment(path, environ):- """Windows Git, and the Python that runs it, work from a short view of the install root.-- `path` is any folder below the install root (the folder holding setup.lock,- which the short entry is verified through). Only this child's environment is- marked; paths on screen, in receipts and in the checkout keep their real spelling.- """- from . import launch_view- from .long_paths import path_chars, plain- path = Path(os.path.abspath(plain(path)))- root = next((parent for parent in (path, *path.parents) if os.path.isfile(parent / 'setup.lock')), None)- if root is None:- return environ- view = _short_view(root, environ, GIT_PATH_CHARS + path_chars(path) - path_chars(root))- return environ if view is None else launch_view.environment_view(environ, view)--def uv_file_arguments(command, cwd=None):"""Return (command, cwd) for which uv reads constraint files in folders with spaces.diff --git a/freevideo_engine/install.py b/freevideo_engine/install.pyindex a32bc3a..7ea29c1 100644--- a/freevideo_engine/install.py+++ b/freevideo_engine/install.py@@ -17,8 +17,7 @@ def install(root=None, *, packages=False):spec = dependencies['vdn']root = (root or vdn_root()).expanduser().resolve()network.clone(root, spec['url'], spec['commit'])- head = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'rev-parse', 'HEAD'], cwd=root).strip()- dirty = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'status', '--porcelain', '--untracked-files=no'], cwd=root)+ head, dirty = network.repository_state(root, 'git', None)if head != spec['commit'] or dirty:raise RuntimeError('Existing VDN checkout does not match the clean pinned dependency; use another --vdn-root.')diffusers = prepare_diffusers(root, dependencies)@@ -77,22 +76,34 @@ def prepare_diffusers(root, dependencies):"""Build the official two-patch tree atomically; never reset a user checkout."""spec = dependencies['diffusers']target = root / dependencies['vdn']['diffusers_subdirectory']+ built = Falseif not io_path(target).exists():- checkout = root / ('engine-diffusers-' + str(time.time_ns()))- network.clone(checkout, spec['url'], spec['base'])- patches = sorted(io_path(root / 'diffusers_patches').glob('*.patch'))- if len(patches) != 2:- raise RuntimeError('Expected the two pinned VDN Diffusers patches')- for path in patches:- execution_paths.run(['git', '-c', 'core.longpaths=true', 'apply', '--index', str(path)], cwd=checkout, check=True)- tree = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'write-tree'], cwd=checkout).strip()- if tree != spec['patched_tree']:- raise RuntimeError('Patched Diffusers source tree does not match the tested dependency')- execution_paths.run(['git', '-c', 'core.longpaths=true', '-c', 'user.name=VDN Engine dependency setup', '-c', 'user.email=engine@localhost',- 'commit', '--quiet', '-m', 'Apply pinned OpenVDN MiniMax H3 patches'], cwd=checkout, check=True)- io_path(checkout).rename(io_path(target))- tree = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'rev-parse', 'HEAD^{tree}'], cwd=target).strip()- dirty = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'status', '--porcelain', '--untracked-files=no'], cwd=target)- if tree != spec['patched_tree'] or dirty:- raise RuntimeError('Existing Diffusers differs from the clean tested tree; use another VDN dependency directory.')+ # Where the folder is too deep for Git to work in, build in a short real one.+ scratch = network.git_scratch_folder() if network.git_folder_too_deep(root / 'engine-diffusers-0') else None+ checkout = scratch / 'repo' if scratch else root / ('engine-diffusers-' + str(time.time_ns()))+ try:+ network.clone(checkout, spec['url'], spec['base'])+ patches = sorted(io_path(root / 'diffusers_patches').glob('*.patch'))+ if len(patches) != 2:+ raise RuntimeError('Expected the two pinned VDN Diffusers patches')+ for path in patches:+ execution_paths.run(['git', '-c', 'core.longpaths=true', 'apply', '--index', str(path)], cwd=checkout, check=True)+ tree = subprocess_output.output_external(['git', '-c', 'core.longpaths=true', 'write-tree'], cwd=checkout).strip()+ if tree != spec['patched_tree']:+ raise RuntimeError('Patched Diffusers source tree does not match the tested dependency')+ execution_paths.run(['git', '-c', 'core.longpaths=true', '-c', 'user.name=VDN Engine dependency setup', '-c', 'user.email=engine@localhost',+ 'commit', '--quiet', '-m', 'Apply pinned OpenVDN MiniMax H3 patches'], cwd=checkout, check=True)+ if scratch:+ partial = root / ('engine-diffusers-' + str(time.time_ns()))+ network.relocate(checkout, partial)+ checkout = partial+ io_path(checkout).rename(io_path(target))+ built = True+ finally:+ if scratch and scratch.exists():+ network.remove_tree(scratch)+ if not built:+ tree, dirty = network.repository_state(target, 'git', None, 'HEAD^{tree}')+ if tree != spec['patched_tree'] or dirty:+ raise RuntimeError('Existing Diffusers differs from the clean tested tree; use another VDN dependency directory.')return targetdiff --git a/freevideo_engine/network.py b/freevideo_engine/network.pyindex 0812ddf..54d15e1 100644--- a/freevideo_engine/network.py+++ b/freevideo_engine/network.py@@ -15,6 +15,7 @@ from pathlib import Pathimport reimport shutilimport subprocess+import tempfilefrom types import SimpleNamespacefrom . import execution_pathsfrom . import subprocess_output@@ -23,7 +24,7 @@ import threadingimport timefrom urllib.parse import quote, unquote, urlencode, urljoin, urlsplitfrom . import proxy-from .long_paths import io_path, plain_errors+from .long_paths import io_path, is_windows, path_chars, plain, plain_errorsfrom .system import curl_executable, missing_curl_message, windows@@ -1202,6 +1203,83 @@ def git_parameter(value):return "'" + value.replace("'", "'\\''").replace('!', "'\\!'") + "'"+# Git for Windows cannot find a repository from a working folder deeper than+# the ordinary path limit, with or without core.longpaths, and a junction does+# not help: the folder it reports is the real one. Git therefore works in a short+# real scratch folder and the finished checkout is moved into place.+GIT_FOLDER_RESERVE = 140+GIT_SCRATCH_BASE_CHARS = 80+GIT_PATH_LIMIT = 259+++def git_folder_too_deep(path):+ return is_windows() and path_chars(plain(path)) + GIT_FOLDER_RESERVE > GIT_PATH_LIMIT+++def git_scratch_folder():+ """A new short real folder for Git to work in, or None where none can be made."""+ bases = [tempfile.gettempdir()]+ if os.environ.get('ProgramData'):+ bases.append(os.path.join(os.environ['ProgramData'], 'FV'))+ for base in bases:+ if path_chars(plain(base)) > GIT_SCRATCH_BASE_CHARS:+ continue+ try:+ os.makedirs(base, exist_ok=True)+ return Path(tempfile.mkdtemp(prefix='fvgit-', dir=base))+ except OSError:+ continue+ return None+++def remove_tree(path):+ def writable(function, name, _):+ os.chmod(name, 0o700)+ function(name)+ shutil.rmtree(io_path(path), onerror=writable)+++def relocate(source, destination):+ """Move a finished folder; where a rename cannot (another volume) copy it."""+ source, destination = io_path(source), io_path(destination)+ try:+ source.rename(destination)+ return+ except OSError:+ pass+ try:+ shutil.copytree(source, destination, symlinks=True)+ except BaseException:+ if destination.exists():+ remove_tree(destination)+ raise+ remove_tree(source)+++def repository_state(path, git, env, revision='HEAD', **options):+ """What `revision` is and what local changes the checkout at `path` has."""+ path = Path(path)+ prefix = [git, '-c', 'core.longpaths=true']+ hidden = dict(hidden_console(), **options)+ if not git_folder_too_deep(path):+ head = subprocess_output.output_external([*prefix, '-C', str(path), 'rev-parse', revision], env=env, **hidden).strip()+ dirty = subprocess_output.output_external([*prefix, '-C', str(path), 'status', '--porcelain', '--untracked-files=no'], env=env, **hidden)+ return head, dirty+ # Name the repository instead of entering it. If Git cannot read it this+ # way, HEAD is read from the file and local changes cannot be checked.+ git_dir = '--git-dir=' + str(path / '.git')+ folder = tempfile.gettempdir()+ try:+ head = subprocess_output.output_external([*prefix, git_dir, 'rev-parse', revision], cwd=folder, env=env, **hidden).strip()+ dirty = subprocess_output.output_external([*prefix, git_dir, 'diff-index', '--cached', '--name-only', 'HEAD'], cwd=folder, env=env, **hidden)+ except (subprocess.CalledProcessError, OSError):+ if revision != 'HEAD':+ raise+ head = io_path(path / '.git' / 'HEAD').read_text(encoding='utf-8').strip()+ dirty = ''+ return head, dirty++def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None):"""Fetch only the pinned commit, atomically; never reset existing checkouts."""target = Path(target)@@ -1213,8 +1291,6 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)if version and version < MIN_GIT:raise RuntimeError(old_git_message(version))def execute(label, command):- # Git makes its own folders with the ordinary limit unless told otherwise on the command line;- # the repository's config only exists after `init` has already made the folder.command = [git, '-c', 'core.longpaths=true', *command[1:]]if run:return run(label, command, env=env)@@ -1224,14 +1300,11 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)if io_path(target).exists():if not io_path(target / '.git').exists():raise ValueError('Existing dependency is not a Git checkout of the pinned source: ' + str(target))- head = subprocess_output.output_external([git, '-c', 'core.longpaths=true', '-C', str(target), 'rev-parse', 'HEAD'], env=env, **hidden_console()).strip()- dirty = subprocess_output.output_external([git, '-c', 'core.longpaths=true', '-C', str(target), 'status', '--porcelain', '--untracked-files=no'], env=env, **hidden_console())+ head, dirty = repository_state(target, git, env)if head != commit or dirty:raise ValueError('Existing dependency differs from the pinned clean source: ' + str(target))return targetio_path(target.parent).mkdir(parents=True, exist_ok=True)- from .environments import git_long_path_environment- env = git_long_path_environment(target.parent, env)candidates = urls(dict(network, sources=dict(network.get('sources', {}), github=network.get('sources', {}).get('git', [{'id': 'official'}]))), 'github', url, env)configured_env = envfor name, endpoint, route in [(name, endpoint, route) for name, endpoint in candidates@@ -1239,19 +1312,21 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)env = route_environment(network, 'git', name, configured_env, route)temporary = target.with_name(target.name + '.partial-' + str(time.time_ns()))event(network, category='git', source=name, route=route, file=target.name, action='attempt', commit=commit)+ scratch = git_scratch_folder() if git_folder_too_deep(temporary) else None+ work = scratch / 'repo' if scratch else temporarytry:- execute(target.name + '-init-' + name, ['git', 'init', '--quiet', temporary])+ execute(target.name + '-init-' + name, ['git', 'init', '--quiet', work])# Never depend on a user's global CRLF conversion or long-path# settings when constructing the exact official patched tree.- execute(target.name + '-line-endings', ['git', '-C', temporary, 'config', 'core.autocrlf', 'false'])- execute(target.name + '-long-paths', ['git', '-C', temporary, 'config', 'core.longpaths', 'true'])+ execute(target.name + '-line-endings', ['git', '-C', work, 'config', 'core.autocrlf', 'false'])+ execute(target.name + '-long-paths', ['git', '-C', work, 'config', 'core.longpaths', 'true'])if sparse:# The patterns file with cone mode off is what `sparse-checkout# set --no-cone` writes; every Git reads it at checkout.- execute(target.name + '-sparse', ['git', '-C', temporary, 'config', 'core.sparseCheckout', 'true'])- execute(target.name + '-sparse-cone', ['git', '-C', temporary, 'config', 'core.sparseCheckoutCone', 'false'])- io_path(temporary / '.git' / 'info').mkdir(exist_ok=True)- io_path(temporary / '.git' / 'info' / 'sparse-checkout').write_text(''.join(p + '\n' for p in sparse), encoding='utf-8')+ execute(target.name + '-sparse', ['git', '-C', work, 'config', 'core.sparseCheckout', 'true'])+ execute(target.name + '-sparse-cone', ['git', '-C', work, 'config', 'core.sparseCheckoutCone', 'false'])+ io_path(work / '.git' / 'info').mkdir(exist_ok=True)+ io_path(work / '.git' / 'info' / 'sparse-checkout').write_text(''.join(p + '\n' for p in sparse), encoding='utf-8')# The URL reaches Git the way `git -c` hands settings to its own# children, in every Git version: never in process arguments, logs# or the repository's config, even if the fetch is killed.@@ -1259,13 +1334,15 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)env = dict(env, GIT_CONFIG_PARAMETERS=' '.join(filter(None, (env.get('GIT_CONFIG_PARAMETERS', '').strip(), git_parameter('remote.origin.url=' + endpoint)))))try:- execute(target.name + '-fetch-' + name, ['git', '-C', temporary, '-c', 'fetch.fsckObjects=true', 'fetch', '--depth=1', '--no-tags', 'origin', commit])+ execute(target.name + '-fetch-' + name, ['git', '-C', work, '-c', 'fetch.fsckObjects=true', 'fetch', '--depth=1', '--no-tags', 'origin', commit])finally:env = original- execute(target.name + '-checkout', ['git', '-C', temporary, 'checkout', '--detach', commit])- actual = subprocess_output.output_external([git, '-c', 'core.longpaths=true', '-C', str(temporary), 'rev-parse', 'HEAD'], env=env, **hidden_console()).strip()+ execute(target.name + '-checkout', ['git', '-C', work, 'checkout', '--detach', commit])+ actual = subprocess_output.output_external([git, '-c', 'core.longpaths=true', '-C', str(work), 'rev-parse', 'HEAD'], env=env, **hidden_console()).strip()if actual != commit:raise ValueError('Downloaded source did not match its pinned commit')+ if scratch:+ relocate(work, temporary)io_path(temporary).rename(io_path(target))source_health(network, 'git', name, True)route_health(network, 'git', name, route)@@ -1276,4 +1353,7 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)raisesource_health(network, 'git', name, False)event(network, category='git', source=name, route=route, file=target.name, action='fallback', reason='network-fetch-failed')+ finally:+ if scratch and scratch.exists():+ remove_tree(scratch)raise RuntimeError('All Git sources failed. Check your network or connection mode in Downloads. Incomplete checkouts retained beside ' + str(target))diff --git a/freevideo_engine/tuning.py b/freevideo_engine/tuning.pyindex fd6fd97..dc20659 100644--- a/freevideo_engine/tuning.py+++ b/freevideo_engine/tuning.py@@ -103,8 +103,8 @@ def identity(machine, hardware):for checkout, ref, expected in ((machine['vdn_root'], 'HEAD', specs['vdn']['commit']),(machine['comfy_root'], 'HEAD', specs['encoder']['comfy_commit']),(str(Path(machine['vdn_root']) / 'diffusers'), 'HEAD^{tree}', specs['diffusers']['patched_tree'])):- observed_ref = subprocess_output.output_external(['git', '-C', checkout, 'rev-parse', ref], timeout=10).strip()- dirty = subprocess_output.output_external(['git', '-C', checkout, 'status', '--porcelain', '--untracked-files=no'], timeout=10)+ from . import network+ observed_ref, dirty = network.repository_state(checkout, 'git', None, ref, timeout=10)if observed_ref != expected or dirty:raise ValueError('Pinned model code changed; saved tuning cannot be reused: ' + checkout)return {'schema': SCHEMA, 'system': hardware.system,