Skip to content

Commit

Permalink
fix: ✨ install process tested in comfy-manager (embed, colab)
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass committed Jul 22, 2023
1 parent 3c66de2 commit b40730d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/package_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ jobs:
- name: 📦 Building and Bundling wheels
shell: bash
run: |
python -m pip wheel --no-cache-dir -r requirements-wheels.txt -w ./wheels > build.log
cat build.log
python -m pip wheel --no-cache-dir --no-deps -r requirements-wheels.txt -w ./wheels 2>&1 | tee build.log
# find source wheels
packages=$(cat build.log | awk -F 'Building wheels for collected packages: ' '{print $2}')
Expand Down
59 changes: 53 additions & 6 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ def print_formatted(text, *formats, color=None, background=None, **kwargs):
formatted_text = apply_format(text, *formats)
formatted_text = apply_color(formatted_text, color, background)
file = kwargs.get("file", sys.stdout)
print(formatted_text, file=file)
print(
apply_color(apply_format("[mtb install] ", "bold"), color="yellow"),
formatted_text,
file=file,
)


# endregion
Expand Down Expand Up @@ -201,9 +205,10 @@ def get_requirements(path: Path):
return parsed_requirements


def import_or_install(requirement, dry=False):
def try_import(requirement):
dependency = requirement.name.strip()
import_name = pip_map.get(dependency, dependency)
installed = False

pip_name = dependency
if specs := requirement.specs:
Expand All @@ -216,7 +221,17 @@ def import_or_install(requirement, dry=False):
"bold",
color="green",
)
installed = True
except ImportError:
pass

return (installed, pip_name, import_name)


def import_or_install(requirement, dry=False):
installed, pip_name, import_name = try_import(requirement)

if not installed:
print_formatted(f"Installing package {pip_name}...", "italic", color="yellow")
if dry:
print_formatted(
Expand Down Expand Up @@ -277,6 +292,15 @@ def install_dependencies(dry=False):
here = clone_dir
full = True

if len(sys.argv) == 1:
print_formatted(
"No arguments provided, doing a full install/update...",
"italic",
color="yellow",
)

full = True

# Parse command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -298,14 +322,15 @@ def install_dependencies(dry=False):
# )

args = parser.parse_args()

wheels_directory = here / "wheels"
print(f"Detected environment: {apply_color(mode,'cyan')}")
print_formatted(f"Detected environment: {apply_color(mode,'cyan')}")

# Install dependencies from requirements.txt
# if args.requirements or mode == "venv":
install_dependencies(dry=args.dry)

if (not args.wheels and mode not in ["colab", "embeded"]) or not full:
if (not args.wheels and mode not in ["colab", "embeded"]) and not full:
print_formatted(
"Skipping wheel installation. Use --wheels to install wheel dependencies. (only needed for Comfy embed)",
"italic",
Expand All @@ -314,9 +339,29 @@ def install_dependencies(dry=False):
sys.exit()

if mode in ["colab", "embeded"]:
print(
print_formatted(
f"Downloading and installing release wheels since we are in a Comfy {apply_color(mode,'cyan')} environment",
)
if full:
print_formatted(
f"Downloading and installing release wheels since no arguments where provided"
)

# - Check the env before proceeding.
missing_wheels = False
parsed_requirements = get_requirements(here / "requirements-wheels.txt")
if parsed_requirements:
for requirement in parsed_requirements:
installed, pip_name, import_name = try_import(requirement)
if not installed:
missing_wheels = True
break

if not missing_wheels:
print_formatted(
f"All required wheels are already installed.", "italic", color="green"
)
sys.exit()

# Fetch the JSON data from the GitHub API URL
owner = "melmass"
Expand Down Expand Up @@ -358,7 +403,9 @@ def install_dependencies(dry=False):
asset for asset in tag_data["assets"] if current_platform in asset["name"]
]
if not matching_assets:
print(f"Unsupported operating system: {current_platform}")
print_formatted(
f"Unsupported operating system: {current_platform}", color="yellow"
)

wheels_directory.mkdir(exist_ok=True)

Expand Down

0 comments on commit b40730d

Please sign in to comment.