mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
chore(installer): typing pass
This commit is contained in:
parent
3b41104427
commit
3dcbb79ef7
@ -11,7 +11,7 @@ import sys
|
|||||||
import venv
|
import venv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from typing import Union
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
SUPPORTED_PYTHON = ">=3.10.0,<=3.11.100"
|
SUPPORTED_PYTHON = ">=3.10.0,<=3.11.100"
|
||||||
INSTALLER_REQS = ["rich", "semver", "requests", "plumbum", "prompt-toolkit"]
|
INSTALLER_REQS = ["rich", "semver", "requests", "plumbum", "prompt-toolkit"]
|
||||||
@ -78,7 +78,7 @@ class Installer:
|
|||||||
|
|
||||||
return venv_dir
|
return venv_dir
|
||||||
|
|
||||||
def bootstrap(self, verbose: bool = False) -> TemporaryDirectory:
|
def bootstrap(self, verbose: bool = False) -> TemporaryDirectory | None:
|
||||||
"""
|
"""
|
||||||
Bootstrap the installer venv with packages required at install time
|
Bootstrap the installer venv with packages required at install time
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ class Installer:
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def app_venv(self, path: str = None):
|
def app_venv(self, path: Optional[str] = None) -> Path:
|
||||||
"""
|
"""
|
||||||
Create a virtualenv for the InvokeAI installation
|
Create a virtualenv for the InvokeAI installation
|
||||||
"""
|
"""
|
||||||
@ -115,6 +115,7 @@ class Installer:
|
|||||||
|
|
||||||
# experimental / testing
|
# experimental / testing
|
||||||
elif not FF_VENV_IN_RUNTIME:
|
elif not FF_VENV_IN_RUNTIME:
|
||||||
|
venv_dir_parent = ""
|
||||||
if OS == "Windows":
|
if OS == "Windows":
|
||||||
venv_dir_parent = os.getenv("APPDATA", "~/AppData/Roaming")
|
venv_dir_parent = os.getenv("APPDATA", "~/AppData/Roaming")
|
||||||
elif OS == "Darwin":
|
elif OS == "Darwin":
|
||||||
@ -141,7 +142,7 @@ class Installer:
|
|||||||
return venv_dir
|
return venv_dir
|
||||||
|
|
||||||
def install(
|
def install(
|
||||||
self, root: str = "~/invokeai", version: str = "latest", yes_to_all=False, find_links: Path = None
|
self, root: str = "~/invokeai", version: str = "latest", yes_to_all=False, find_links: Optional[Path] = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Install the InvokeAI application into the given runtime path
|
Install the InvokeAI application into the given runtime path
|
||||||
@ -160,8 +161,11 @@ class Installer:
|
|||||||
|
|
||||||
messages.welcome()
|
messages.welcome()
|
||||||
|
|
||||||
default_path = os.environ.get("INVOKEAI_ROOT") or Path(root).expanduser().resolve()
|
default_path = Path(os.environ.get("INVOKEAI_ROOT") or Path(root).expanduser().resolve())
|
||||||
self.dest = default_path if yes_to_all else messages.dest_path(root)
|
self.dest = default_path if yes_to_all else messages.dest_path(root)
|
||||||
|
if self.dest is None:
|
||||||
|
print("Could not find or create the destination directory. Installation cancelled.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# create the venv for the app
|
# create the venv for the app
|
||||||
self.venv = self.app_venv()
|
self.venv = self.app_venv()
|
||||||
@ -233,7 +237,7 @@ class InvokeAiInstance:
|
|||||||
Install PyTorch
|
Install PyTorch
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from plumbum import FG, local
|
from plumbum import FG, local # type: ignore
|
||||||
|
|
||||||
pip = local[self.pip]
|
pip = local[self.pip]
|
||||||
|
|
||||||
@ -292,6 +296,7 @@ class InvokeAiInstance:
|
|||||||
next(src.glob("invokeai"))
|
next(src.glob("invokeai"))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
print("Unable to find a wheel or perform a source install. Giving up.")
|
print("Unable to find a wheel or perform a source install. Giving up.")
|
||||||
|
src = ""
|
||||||
|
|
||||||
elif version == "source":
|
elif version == "source":
|
||||||
# this makes an assumption about the location of the installer package in the source tree
|
# this makes an assumption about the location of the installer package in the source tree
|
||||||
@ -300,7 +305,7 @@ class InvokeAiInstance:
|
|||||||
# will install from PyPi
|
# will install from PyPi
|
||||||
src = f"invokeai=={version}" if version is not None else "invokeai"
|
src = f"invokeai=={version}" if version is not None else "invokeai"
|
||||||
|
|
||||||
from plumbum import FG, local
|
from plumbum import FG, local # type: ignore
|
||||||
|
|
||||||
pip = local[self.pip]
|
pip = local[self.pip]
|
||||||
|
|
||||||
@ -431,7 +436,7 @@ def set_sys_path(venv_path: Path) -> None:
|
|||||||
sys.path.append(str(Path(venv_path, lib, "site-packages").expanduser().resolve()))
|
sys.path.append(str(Path(venv_path, lib, "site-packages").expanduser().resolve()))
|
||||||
|
|
||||||
|
|
||||||
def get_torch_source() -> (Union[str, None], str):
|
def get_torch_source() -> Tuple[str | None, str | None]:
|
||||||
"""
|
"""
|
||||||
Determine the extra index URL for pip to use for torch installation.
|
Determine the extra index URL for pip to use for torch installation.
|
||||||
This depends on the OS and the graphics accelerator in use.
|
This depends on the OS and the graphics accelerator in use.
|
||||||
|
@ -109,7 +109,7 @@ def user_wants_auto_configuration() -> bool:
|
|||||||
return choice.lower().startswith("a")
|
return choice.lower().startswith("a")
|
||||||
|
|
||||||
|
|
||||||
def dest_path(dest=None) -> Path:
|
def dest_path(dest=None) -> Path | None:
|
||||||
"""
|
"""
|
||||||
Prompt the user for the destination path and create the path
|
Prompt the user for the destination path and create the path
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ def dest_path(dest=None) -> Path:
|
|||||||
path_completer = PathCompleter(
|
path_completer = PathCompleter(
|
||||||
only_directories=True,
|
only_directories=True,
|
||||||
expanduser=True,
|
expanduser=True,
|
||||||
get_paths=lambda: [browse_start], # noqa: B023
|
get_paths=lambda: [str(browse_start)], # noqa: B023
|
||||||
# get_paths=lambda: [".."].extend(list(browse_start.iterdir()))
|
# get_paths=lambda: [".."].extend(list(browse_start.iterdir()))
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -217,6 +217,7 @@ def graphical_accelerator():
|
|||||||
"idk",
|
"idk",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
options = []
|
||||||
if OS == "Windows":
|
if OS == "Windows":
|
||||||
options = [nvidia, nvidia_with_dml, cpu]
|
options = [nvidia, nvidia_with_dml, cpu]
|
||||||
if OS == "Linux":
|
if OS == "Linux":
|
||||||
@ -230,7 +231,7 @@ def graphical_accelerator():
|
|||||||
return options[0][1]
|
return options[0][1]
|
||||||
|
|
||||||
# "I don't know" is always added the last option
|
# "I don't know" is always added the last option
|
||||||
options.append(idk)
|
options.append(idk) # type: ignore
|
||||||
|
|
||||||
options = {str(i): opt for i, opt in enumerate(options, 1)}
|
options = {str(i): opt for i, opt in enumerate(options, 1)}
|
||||||
|
|
||||||
@ -291,7 +292,7 @@ def windows_long_paths_registry() -> None:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
with open(str(Path(__file__).parent / "WinLongPathsEnabled.reg"), "r", encoding="utf-16le") as code:
|
with open(str(Path(__file__).parent / "WinLongPathsEnabled.reg"), "r", encoding="utf-16le") as code:
|
||||||
syntax = Syntax(code.read(), line_numbers=True)
|
syntax = Syntax(code.read(), line_numbers=True, lexer="regedit")
|
||||||
|
|
||||||
console.print(
|
console.print(
|
||||||
Panel(
|
Panel(
|
||||||
@ -301,7 +302,7 @@ def windows_long_paths_registry() -> None:
|
|||||||
"We will now apply a registry fix to enable long paths on Windows. InvokeAI needs this to function correctly. We are asking your permission to modify the Windows Registry on your behalf.",
|
"We will now apply a registry fix to enable long paths on Windows. InvokeAI needs this to function correctly. We are asking your permission to modify the Windows Registry on your behalf.",
|
||||||
"",
|
"",
|
||||||
"This is the change that will be applied:",
|
"This is the change that will be applied:",
|
||||||
syntax,
|
str(syntax),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@ -340,7 +341,7 @@ def introduction() -> None:
|
|||||||
console.line(2)
|
console.line(2)
|
||||||
|
|
||||||
|
|
||||||
def _platform_specific_help() -> str:
|
def _platform_specific_help() -> Text:
|
||||||
if OS == "Darwin":
|
if OS == "Darwin":
|
||||||
text = Text.from_markup(
|
text = Text.from_markup(
|
||||||
"""[b wheat1]macOS Users![/]\n\nPlease be sure you have the [b wheat1]Xcode command-line tools[/] installed before continuing.\nIf not, cancel with [i]Control-C[/] and follow the Xcode install instructions at [deep_sky_blue1]https://www.freecodecamp.org/news/install-xcode-command-line-tools/[/]."""
|
"""[b wheat1]macOS Users![/]\n\nPlease be sure you have the [b wheat1]Xcode command-line tools[/] installed before continuing.\nIf not, cancel with [i]Control-C[/] and follow the Xcode install instructions at [deep_sky_blue1]https://www.freecodecamp.org/news/install-xcode-command-line-tools/[/]."""
|
||||||
@ -354,5 +355,5 @@ def _platform_specific_help() -> str:
|
|||||||
[deep_sky_blue1]https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170[/]"""
|
[deep_sky_blue1]https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170[/]"""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
text = ""
|
text = Text()
|
||||||
return text
|
return text
|
||||||
|
Loading…
Reference in New Issue
Block a user