2023-07-27 14:54:01 +00:00
|
|
|
"""
|
2023-02-12 03:32:48 +00:00
|
|
|
Minimalist updater script. Prompts user for the tag or branch to update to and runs
|
|
|
|
pip install <path_to_git_source>.
|
2023-07-27 14:54:01 +00:00
|
|
|
"""
|
2023-02-23 21:33:57 +00:00
|
|
|
import os
|
2023-02-12 03:32:48 +00:00
|
|
|
import platform
|
2023-12-18 22:58:10 +00:00
|
|
|
from distutils.version import LooseVersion
|
2023-08-18 14:57:18 +00:00
|
|
|
|
2023-05-22 21:51:47 +00:00
|
|
|
import pkg_resources
|
|
|
|
import psutil
|
2023-02-12 03:32:48 +00:00
|
|
|
import requests
|
|
|
|
from rich import box, print
|
2023-05-22 21:51:47 +00:00
|
|
|
from rich.console import Console, group
|
2023-02-12 03:32:48 +00:00
|
|
|
from rich.panel import Panel
|
|
|
|
from rich.prompt import Prompt
|
|
|
|
from rich.style import Style
|
|
|
|
|
2023-03-03 05:02:15 +00:00
|
|
|
from invokeai.version import __version__
|
2023-02-12 03:32:48 +00:00
|
|
|
|
2023-04-02 15:08:12 +00:00
|
|
|
INVOKE_AI_SRC = "https://github.com/invoke-ai/InvokeAI/archive"
|
|
|
|
INVOKE_AI_TAG = "https://github.com/invoke-ai/InvokeAI/archive/refs/tags"
|
|
|
|
INVOKE_AI_BRANCH = "https://github.com/invoke-ai/InvokeAI/archive/refs/heads"
|
|
|
|
INVOKE_AI_REL = "https://api.github.com/repos/invoke-ai/InvokeAI/releases"
|
2023-02-12 03:32:48 +00:00
|
|
|
|
|
|
|
OS = platform.uname().system
|
|
|
|
ARCH = platform.uname().machine
|
|
|
|
|
|
|
|
if OS == "Windows":
|
|
|
|
# Windows terminals look better without a background colour
|
|
|
|
console = Console(style=Style(color="grey74"))
|
|
|
|
else:
|
2023-02-23 21:33:57 +00:00
|
|
|
console = Console(style=Style(color="grey74", bgcolor="grey19"))
|
2023-02-12 03:32:48 +00:00
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-05-22 21:51:47 +00:00
|
|
|
def invokeai_is_running() -> bool:
|
|
|
|
for p in psutil.process_iter():
|
|
|
|
try:
|
|
|
|
cmdline = p.cmdline()
|
|
|
|
matches = [x for x in cmdline if x.endswith(("invokeai", "invokeai.exe"))]
|
|
|
|
if matches:
|
|
|
|
print(
|
|
|
|
f":exclamation: [bold red]An InvokeAI instance appears to be running as process {p.pid}[/red bold]"
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
except (psutil.AccessDenied, psutil.NoSuchProcess):
|
|
|
|
continue
|
|
|
|
return False
|
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-12-18 22:30:40 +00:00
|
|
|
def get_pypi_versions():
|
2023-12-18 22:58:10 +00:00
|
|
|
url = "https://pypi.org/pypi/invokeai/json"
|
|
|
|
try:
|
2023-12-18 22:30:40 +00:00
|
|
|
data = requests.get(url).json()
|
2023-12-18 22:58:10 +00:00
|
|
|
except Exception:
|
2023-12-18 22:30:40 +00:00
|
|
|
raise Exception("Unable to fetch version information from PyPi")
|
|
|
|
|
|
|
|
versions = list(data["releases"].keys())
|
|
|
|
versions.sort(key=LooseVersion, reverse=True)
|
2023-12-18 22:58:10 +00:00
|
|
|
latest_version = [v for v in versions if "rc" not in v][0]
|
|
|
|
latest_release_candidate = [v for v in versions if "rc" in v][0]
|
2023-12-19 00:04:21 +00:00
|
|
|
return latest_version, latest_release_candidate, versions
|
2023-12-18 22:30:40 +00:00
|
|
|
|
|
|
|
|
2023-10-30 19:49:27 +00:00
|
|
|
def welcome(latest_release: str, latest_prerelease: str):
|
2023-02-12 03:32:48 +00:00
|
|
|
@group()
|
|
|
|
def text():
|
2023-04-02 15:08:12 +00:00
|
|
|
yield f"InvokeAI Version: [bold yellow]{__version__}"
|
|
|
|
yield ""
|
2023-09-05 11:50:12 +00:00
|
|
|
yield "This script will update InvokeAI to the latest release, or to the development version of your choice."
|
|
|
|
yield ""
|
2023-04-02 15:08:12 +00:00
|
|
|
yield "[bold yellow]Options:"
|
2023-10-30 19:49:27 +00:00
|
|
|
yield f"""[1] Update to the latest [bold]official release[/bold] ([italic]{latest_release}[/italic])
|
2024-01-02 22:44:45 +00:00
|
|
|
[2] Update to the latest [bold]pre-release[/bold] (may be buggy, database backups are recommended before installation; caveat emptor!) ([italic]{latest_prerelease}[/italic])
|
2023-12-18 22:30:40 +00:00
|
|
|
[3] Manually enter the [bold]version[/bold] you wish to update to"""
|
2023-02-12 03:32:48 +00:00
|
|
|
|
|
|
|
console.rule()
|
2023-02-23 21:33:57 +00:00
|
|
|
print(
|
2023-02-12 03:32:48 +00:00
|
|
|
Panel(
|
|
|
|
title="[bold wheat1]InvokeAI Updater",
|
|
|
|
renderable=text(),
|
|
|
|
box=box.DOUBLE,
|
|
|
|
expand=True,
|
|
|
|
padding=(1, 2),
|
2023-02-23 21:33:57 +00:00
|
|
|
style=Style(bgcolor="grey23", color="orange1"),
|
2023-02-12 03:32:48 +00:00
|
|
|
subtitle=f"[bold grey39]{OS}-{ARCH}",
|
|
|
|
)
|
|
|
|
)
|
2023-02-23 21:33:57 +00:00
|
|
|
console.line()
|
2023-02-12 03:32:48 +00:00
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-05-22 21:51:47 +00:00
|
|
|
def get_extras():
|
|
|
|
extras = ""
|
|
|
|
try:
|
2023-08-17 22:45:25 +00:00
|
|
|
_ = pkg_resources.get_distribution("xformers")
|
2023-05-22 21:51:47 +00:00
|
|
|
extras = "[xformers]"
|
|
|
|
except pkg_resources.DistributionNotFound:
|
|
|
|
pass
|
|
|
|
return extras
|
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-02-12 03:32:48 +00:00
|
|
|
def main():
|
2023-05-22 21:51:47 +00:00
|
|
|
if invokeai_is_running():
|
2023-08-17 22:45:25 +00:00
|
|
|
print(":exclamation: [bold red]Please terminate all running instances of InvokeAI before updating.[/red bold]")
|
2023-05-22 21:51:47 +00:00
|
|
|
input("Press any key to continue...")
|
|
|
|
return
|
|
|
|
|
2023-12-19 00:04:21 +00:00
|
|
|
latest_release, latest_prerelease, versions = get_pypi_versions()
|
2023-12-18 22:30:40 +00:00
|
|
|
|
2023-10-30 19:49:27 +00:00
|
|
|
welcome(latest_release, latest_prerelease)
|
2023-02-12 03:32:48 +00:00
|
|
|
|
2023-12-18 22:30:40 +00:00
|
|
|
release = latest_release
|
|
|
|
choice = Prompt.ask("Choice:", choices=["1", "2", "3"], default="1")
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-04-02 15:08:12 +00:00
|
|
|
if choice == "1":
|
2023-10-30 19:49:27 +00:00
|
|
|
release = latest_release
|
2023-04-02 15:08:12 +00:00
|
|
|
elif choice == "2":
|
2023-10-30 19:49:27 +00:00
|
|
|
release = latest_prerelease
|
|
|
|
elif choice == "3":
|
2023-12-19 00:04:21 +00:00
|
|
|
while True:
|
|
|
|
release = Prompt.ask("Enter an InvokeAI version")
|
|
|
|
release.strip()
|
|
|
|
if release in versions:
|
|
|
|
break
|
|
|
|
print(f":exclamation: [bold red]'{release}' is not a recognized InvokeAI release.[/red bold]")
|
2023-04-02 15:08:12 +00:00
|
|
|
|
2023-05-22 21:51:47 +00:00
|
|
|
extras = get_extras()
|
|
|
|
|
2023-12-18 22:30:40 +00:00
|
|
|
print(f":crossed_fingers: Upgrading to [yellow]{release}[/yellow]")
|
|
|
|
cmd = f'pip install "invokeai{extras}=={release}" --use-pep517 --upgrade'
|
|
|
|
|
2023-04-02 15:08:12 +00:00
|
|
|
print("")
|
|
|
|
print("")
|
|
|
|
if os.system(cmd) == 0:
|
2023-08-17 22:45:25 +00:00
|
|
|
print(":heavy_check_mark: Upgrade successful")
|
2023-04-02 15:08:12 +00:00
|
|
|
else:
|
2023-08-17 22:45:25 +00:00
|
|
|
print(":exclamation: [bold red]Upgrade failed[/red bold]")
|
2023-07-27 14:54:01 +00:00
|
|
|
|
|
|
|
|
2023-02-12 03:32:48 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|