mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-06-25 12:22:49 +02:00
Developer console which shows an activated mamba environment; A script to enable developer mode and auto-create the symlinks
This commit is contained in:
parent
19a868b2df
commit
582b594789
11
Open Developer Console.cmd
Normal file
11
Open Developer Console.cmd
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
set SD_BASE_DIR=%cd%
|
||||||
|
set MAMBA_ROOT_PREFIX=%SD_BASE_DIR%\env\mamba
|
||||||
|
set INSTALL_ENV_DIR=%SD_BASE_DIR%\env\installer_env
|
||||||
|
|
||||||
|
call "%MAMBA_ROOT_PREFIX%\condabin\mamba_hook.bat"
|
||||||
|
|
||||||
|
call micromamba activate "%INSTALL_ENV_DIR%"
|
||||||
|
|
||||||
|
cmd /k
|
@ -1,5 +1,9 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
@rem This file initializes micromamba and activates the env.
|
||||||
|
@rem A similar bootstrap file needs to exist for each platform (win, linux, macOS)
|
||||||
|
@rem Ready to hand-over to the platform-independent installer after this (written in python).
|
||||||
|
|
||||||
set MAMBA_ROOT_PREFIX=%SD_BASE_DIR%\env\mamba
|
set MAMBA_ROOT_PREFIX=%SD_BASE_DIR%\env\mamba
|
||||||
set INSTALL_ENV_DIR=%SD_BASE_DIR%\env\installer_env
|
set INSTALL_ENV_DIR=%SD_BASE_DIR%\env\installer_env
|
||||||
set INSTALLER_YAML_FILE=%SD_BASE_DIR%\installer\yaml\installer-environment.yaml
|
set INSTALLER_YAML_FILE=%SD_BASE_DIR%\installer\yaml\installer-environment.yaml
|
||||||
|
85
installer/developer/enable_dev_mode.py
Normal file
85
installer/developer/enable_dev_mode.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
config_path = os.path.join('config.json')
|
||||||
|
|
||||||
|
if not os.path.exists('installer') or not os.path.exists('ui') or not os.path.exists('engine'):
|
||||||
|
print('Error: This script needs to be run from the root of the stable-diffusion-ui folder! Please cd to the correct folder, and run this again.')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--symlink_dir", type=str, default=None, help="the absolute path to the project git repository (to link to)"
|
||||||
|
)
|
||||||
|
opt = parser.parse_args()
|
||||||
|
|
||||||
|
def run(cmd):
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
||||||
|
|
||||||
|
for c in iter(lambda: p.stdout.read(1), b""):
|
||||||
|
sys.stdout.buffer.write(c)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
return p.returncode == 0
|
||||||
|
|
||||||
|
def get_config():
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def save_config(config):
|
||||||
|
with open(config_path, "w") as f:
|
||||||
|
json.dump(config, f)
|
||||||
|
|
||||||
|
# set the `is_developer_mode` flag to `true` in the config
|
||||||
|
config = get_config()
|
||||||
|
config['is_developer_mode'] = True
|
||||||
|
save_config(config)
|
||||||
|
|
||||||
|
print('set is_developer_mode=true in config.json')
|
||||||
|
|
||||||
|
# make the symlink, if requested
|
||||||
|
if opt.symlink_dir is not None:
|
||||||
|
if not os.path.exists(opt.symlink_dir):
|
||||||
|
print(f'Symlink directory "{opt.symlink_dir}" was not found! Are you sure it has been escaped correctly?')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
installer_target_path = os.path.join(opt.symlink_dir, 'installer')
|
||||||
|
ui_target_path = os.path.join(opt.symlink_dir, 'ui')
|
||||||
|
engine_target_path = os.path.join(opt.symlink_dir, 'engine')
|
||||||
|
|
||||||
|
shutil.rmtree('installer', ignore_errors=True)
|
||||||
|
shutil.rmtree('ui', ignore_errors=True)
|
||||||
|
shutil.rmtree('engine', ignore_errors=True)
|
||||||
|
|
||||||
|
if not os.path.exists(ui_target_path) or not os.path.exists(installer_target_path) or not os.path.exists(engine_target_path):
|
||||||
|
print('The target symlink directory does not contain the required {ui, installer, engine} folders. Are you sure it is the correct git repo for the project?')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
cmds = []
|
||||||
|
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
cmds.append(f'mklink /J "installer" "{installer_target_path}"')
|
||||||
|
cmds.append(f'mklink /J "ui" "{ui_target_path}"')
|
||||||
|
cmds.append(f'mklink /J "engine" "{engine_target_path}"')
|
||||||
|
elif platform.system() in ('Linux', 'Darwin'):
|
||||||
|
cmds.append(f'ln -s "{installer_target_path}" "installer"')
|
||||||
|
cmds.append(f'ln -s "{ui_target_path}" "ui"')
|
||||||
|
cmds.append(f'ln -s "{engine_target_path}" "engine"')
|
||||||
|
|
||||||
|
for cmd in cmds:
|
||||||
|
if not run(cmd):
|
||||||
|
print('Error while running', cmd)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
print(f'Created symlinks! Your installation will now automatically use the files present in the repository at {opt.symlink_dir}')
|
9
open_dev_console.sh
Normal file
9
open_dev_console.sh
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export SD_BASE_DIR=`pwd`
|
||||||
|
export MAMBA_ROOT_PREFIX="$SD_BASE_DIR/env/mamba"
|
||||||
|
export INSTALL_ENV_DIR="$SD_BASE_DIR/env/installer_env"
|
||||||
|
|
||||||
|
eval "$($MAMBA_ROOT_PREFIX/micromamba shell hook -s posix)"
|
||||||
|
|
||||||
|
micromamba activate "$INSTALL_ENV_DIR"
|
Loading…
x
Reference in New Issue
Block a user