From 4dea04e26215af36408b10817c9f2b99de32e76c Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Sun, 30 Jun 2024 05:02:23 +0800 Subject: [PATCH 1/8] setup uv --- installer.py | 7 ++++--- launch.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/installer.py b/installer.py index a00a12624..0d0d74e2a 100644 --- a/installer.py +++ b/installer.py @@ -235,13 +235,14 @@ def uninstall(package, quiet = False): @lru_cache() -def pip(arg: str, ignore: bool = False, quiet: bool = False): +def pip(arg: str, ignore: bool = False, quiet: bool = False, uv=True): arg = arg.replace('>=', '==') if not quiet and '-r ' not in arg: log.info(f'Install: package="{arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}"') env_args = os.environ.get("PIP_EXTRA_ARGS", "") log.debug(f'Running: pip="{pip_log}{arg} {env_args}"') - result = subprocess.run(f'"{sys.executable}" -m pip {pip_log}{arg} {env_args}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + pipCmd = "uv pip" if uv else "pip" + result = subprocess.run(f'"{sys.executable}" -m {pipCmd} {pip_log}{arg} {env_args}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) txt = result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stderr) > 0: txt += ('\n' if len(txt) > 0 else '') + result.stderr.decode(encoding="utf8", errors="ignore") @@ -264,7 +265,7 @@ def install(package, friendly: str = None, ignore: bool = False, reinstall: bool quick_allowed = False if args.reinstall or reinstall or not installed(package, friendly, quiet=quiet): deps = '' if not no_deps else '--no-deps ' - res = pip(f"install --upgrade {deps}{package}", ignore=ignore) + res = pip(f"install {deps}{package}", ignore=ignore) try: import imp # pylint: disable=deprecated-module imp.reload(pkg_resources) diff --git a/launch.py b/launch.py index f1d8b7ec5..5e1e8075f 100755 --- a/launch.py +++ b/launch.py @@ -183,6 +183,7 @@ def start_server(immediate=True, server=None): def main(): global args # pylint: disable=global-statement installer.ensure_base_requirements() + installer.pip("install uv", uv=False) init_args() # setup argparser and default folders installer.args = args installer.setup_logging() From 00ddc02971e062b39fca55616ad0c2da06db900a Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Sun, 30 Jun 2024 05:03:56 +0800 Subject: [PATCH 2/8] install uv before base requirements --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.py b/launch.py index 5e1e8075f..ed62bc8b8 100755 --- a/launch.py +++ b/launch.py @@ -182,8 +182,8 @@ def start_server(immediate=True, server=None): def main(): global args # pylint: disable=global-statement - installer.ensure_base_requirements() installer.pip("install uv", uv=False) + installer.ensure_base_requirements() init_args() # setup argparser and default folders installer.args = args installer.setup_logging() From 4bcf5e346b479254aae8c66fea69d6c8f04ef16a Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 00:20:16 +0800 Subject: [PATCH 3/8] makes uv an apt-in features, add uv testing to GH actions --- .github/workflows/on_pull_request.yaml | 4 ++++ installer.py | 18 +++++++++++------- launch.py | 4 +++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 7abade093..de0486b54 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -29,3 +29,7 @@ jobs: run: | export COMMANDLINE_ARGS="--debug --test" python launch.py + - name: test-startup-with-uv + run: | + export COMMANDLINE_ARGS="--debug --test --uv" + python launch.py diff --git a/installer.py b/installer.py index 0d0d74e2a..a209643ae 100644 --- a/installer.py +++ b/installer.py @@ -52,6 +52,7 @@ args = Dot({ 'reinstall': False, 'version': False, 'ignore': False, + 'uv': False, }) git_commit = "unknown" submodules_commit = { @@ -235,23 +236,25 @@ def uninstall(package, quiet = False): @lru_cache() -def pip(arg: str, ignore: bool = False, quiet: bool = False, uv=True): +def pip(arg: str, ignore: bool = False, quiet: bool = False, forcePip = False): + uv = args.uv and not forcePip + pipCmd = "uv pip" if uv else "pip" + uvMode = "[uv] " if uv else "" arg = arg.replace('>=', '==') if not quiet and '-r ' not in arg: - log.info(f'Install: package="{arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}"') + log.info(f'{uvMode}Install: package="{arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}"') env_args = os.environ.get("PIP_EXTRA_ARGS", "") - log.debug(f'Running: pip="{pip_log}{arg} {env_args}"') - pipCmd = "uv pip" if uv else "pip" + log.debug(f'Running: {pipCmd}="{pip_log}{arg} {env_args}"') result = subprocess.run(f'"{sys.executable}" -m {pipCmd} {pip_log}{arg} {env_args}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) txt = result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stderr) > 0: txt += ('\n' if len(txt) > 0 else '') + result.stderr.decode(encoding="utf8", errors="ignore") txt = txt.strip() - debug(f'Install pip: {txt}') + debug(f'Install {pipCmd}: {txt}') if result.returncode != 0 and not ignore: global errors # pylint: disable=global-statement errors += 1 - log.error(f'Error running pip: {arg}') + log.error(f'Error running {pipCmd}: {arg}') log.debug(f'Pip output: {txt}') return txt @@ -265,7 +268,7 @@ def install(package, friendly: str = None, ignore: bool = False, reinstall: bool quick_allowed = False if args.reinstall or reinstall or not installed(package, friendly, quiet=quiet): deps = '' if not no_deps else '--no-deps ' - res = pip(f"install {deps}{package}", ignore=ignore) + res = pip(f"install{' --upgrade' if not args.uv else ''} {deps}{package}", ignore=ignore, forcePip=(package == "uv")) try: import imp # pylint: disable=deprecated-module imp.reload(pkg_resources) @@ -1224,6 +1227,7 @@ def add_args(parser): group.add_argument('--version', default = False, action='store_true', help = "Print version information") group.add_argument('--ignore', default = os.environ.get("SD_IGNORE",False), action='store_true', help = "Ignore any errors and attempt to continue") group.add_argument('--safe', default = os.environ.get("SD_SAFE",False), action='store_true', help = "Run in safe mode with no user extensions") + group.add_argument('--uv', default = os.environ.get("SD_UV",False), action='store_true', help = "Use uv instead of pip to install the packages") group = parser.add_argument_group('Logging options') group.add_argument("--log", type=str, default=os.environ.get("SD_LOG", None), help="Set log file, default: %(default)s") diff --git a/launch.py b/launch.py index ed62bc8b8..c7cc71d09 100755 --- a/launch.py +++ b/launch.py @@ -182,7 +182,6 @@ def start_server(immediate=True, server=None): def main(): global args # pylint: disable=global-statement - installer.pip("install uv", uv=False) installer.ensure_base_requirements() init_args() # setup argparser and default folders installer.args = args @@ -205,6 +204,9 @@ def main(): installer.log.info(f'Platform: {installer.print_dict(installer.get_platform())}') if not args.skip_env: installer.set_environment() + if args.uv: + installer.install("uv", "uv") + installer.log.info('Using "uv pip" instead of "pip" for packages installation') installer.check_torch() installer.check_onnx() installer.check_diffusers() From 7562bde0fdb16c88593d3adda1fda19cfaae7ab4 Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 00:25:56 +0800 Subject: [PATCH 4/8] delete venv before testing uv --- .github/workflows/on_pull_request.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index de0486b54..938713ac7 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -31,5 +31,6 @@ jobs: python launch.py - name: test-startup-with-uv run: | + rm -rf venv export COMMANDLINE_ARGS="--debug --test --uv" python launch.py From 07381bd3d3b63dfd74cc7f1903d3848f591bc748 Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 00:36:57 +0800 Subject: [PATCH 5/8] use matrix to test installation w/wo uv --- .github/workflows/on_pull_request.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 938713ac7..5b00eec65 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -7,6 +7,12 @@ on: jobs: lint: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + flags: + - --debug --test --uv + - --debug --test steps: - name: checkout-code uses: actions/checkout@main @@ -27,10 +33,5 @@ jobs: msg: apply code formatting and linting auto-fixes - name: test-startup run: | - export COMMANDLINE_ARGS="--debug --test" - python launch.py - - name: test-startup-with-uv - run: | - rm -rf venv - export COMMANDLINE_ARGS="--debug --test --uv" + export COMMANDLINE_ARGS="${{ matrix.flags }}" python launch.py From fee84fe6b51df2744685afda3342ad785313cca5 Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 01:58:24 +0800 Subject: [PATCH 6/8] add --uv to CLI Arguments page --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 8c44b3055..349c11b66 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 8c44b305543f8b612b3b0fbc935ac40997360588 +Subproject commit 349c11b669053b0e50d5e8b88806f9a12cc3be0c From 3fa0c6bce56c6400483af5064a8ce95b17d8604d Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 02:06:20 +0800 Subject: [PATCH 7/8] Revert "add --uv to CLI Arguments page" This reverts commit fee84fe6b51df2744685afda3342ad785313cca5. --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 349c11b66..8c44b3055 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 349c11b669053b0e50d5e8b88806f9a12cc3be0c +Subproject commit 8c44b305543f8b612b3b0fbc935ac40997360588 From 47d865acc1794033579dca8fd9ef776b018bb91b Mon Sep 17 00:00:00 2001 From: Yoink3000 Date: Mon, 1 Jul 2024 02:13:59 +0800 Subject: [PATCH 8/8] inline with SD Next logging style --- installer.py | 2 +- launch.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/installer.py b/installer.py index a209643ae..913da981e 100644 --- a/installer.py +++ b/installer.py @@ -242,7 +242,7 @@ def pip(arg: str, ignore: bool = False, quiet: bool = False, forcePip = False): uvMode = "[uv] " if uv else "" arg = arg.replace('>=', '==') if not quiet and '-r ' not in arg: - log.info(f'{uvMode}Install: package="{arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}"') + log.info(f'Install: package="{arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}" mode={"uv" if uv else "pip"}') env_args = os.environ.get("PIP_EXTRA_ARGS", "") log.debug(f'Running: {pipCmd}="{pip_log}{arg} {env_args}"') result = subprocess.run(f'"{sys.executable}" -m {pipCmd} {pip_log}{arg} {env_args}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/launch.py b/launch.py index c7cc71d09..1db8a81f6 100755 --- a/launch.py +++ b/launch.py @@ -206,7 +206,6 @@ def main(): installer.set_environment() if args.uv: installer.install("uv", "uv") - installer.log.info('Using "uv pip" instead of "pip" for packages installation') installer.check_torch() installer.check_onnx() installer.check_diffusers()