Python
forgot setup.py last commit
Chris Malone941bee0e90ef
diff --git a/setup.py b/setup.pyindex e9f4bb2..d05d85f 100644--- a/setup.py+++ b/setup.py@@ -4,13 +4,36 @@ import jsonimport subprocessimport argparseimport shutil+import platformCONFIG_PATH = "setup_config.json"+IS_WIN = os.name == 'nt'+ENV_MAP = {- "uv": {"dir": "env_uv", "create": "uv venv --python {ver} {dir}", "run": r"{dir}\Scripts\python.exe", "install": r"{dir}\Scripts\python.exe -m uv pip install"},- "venv": {"dir": "env_venv", "create": "{sys_py} -m venv {dir}", "run": r"{dir}\Scripts\python.exe", "install": r"{dir}\Scripts\python.exe -m pip install"},- "conda": {"dir": "wangp", "create": "conda create -y -n {dir} python={ver}", "run": "conda run -n {dir} python", "install": "conda run -n {dir} pip install"},- "none": {"dir": "", "create": "", "run": "python", "install": "pip install"}+ "uv": {+ "dir": "env_uv",+ "create": "uv venv --python {ver} {dir}",+ "run": os.path.join("{dir}", "Scripts", "python.exe") if IS_WIN else os.path.join("{dir}", "bin", "python"),+ "install": (os.path.join("{dir}", "Scripts", "python.exe") if IS_WIN else os.path.join("{dir}", "bin", "python")) + " -m uv pip install"+ },+ "venv": {+ "dir": "env_venv",+ "create": "{sys_py} -m venv {dir}",+ "run": os.path.join("{dir}", "Scripts", "python.exe") if IS_WIN else os.path.join("{dir}", "bin", "python"),+ "install": (os.path.join("{dir}", "Scripts", "python.exe") if IS_WIN else os.path.join("{dir}", "bin", "python")) + " -m pip install"+ },+ "conda": {+ "dir": "wangp",+ "create": "conda create -y -n {dir} python={ver}",+ "run": "conda run -n {dir} python",+ "install": "conda run -n {dir} pip install"+ },+ "none": {+ "dir": "",+ "create": "",+ "run": "python" if IS_WIN else "python3",+ "install": "pip install"+ }}def load_config():@@ -25,12 +48,21 @@ def get_gpu_info():return name, "NVIDIA"except: pass- try:- name = subprocess.check_output("wmic path win32_VideoController get name", shell=True, encoding='utf-8')- name = name.replace("Name", "").strip().split('\n')[0].strip()- if "Radeon" in name or "AMD" in name: return name, "AMD"- return name, "INTEL"- except: return "Unknown", "UNKNOWN"+ if IS_WIN:+ try:+ name = subprocess.check_output("wmic path win32_VideoController get name", shell=True, encoding='utf-8')+ name = name.replace("Name", "").strip().split('\n')[0].strip()+ if "Radeon" in name or "AMD" in name: return name, "AMD"+ return name, "INTEL"+ except: pass+ else:+ try:+ name = subprocess.check_output("lspci | grep -i vga", shell=True, encoding='utf-8')+ if "NVIDIA" in name: return name, "NVIDIA"+ if "AMD" in name or "Advanced Micro Devices" in name: return name, "AMD"+ except: pass++ return "Unknown", "UNKNOWN"def get_profile_key(gpu_name, vendor):g = gpu_name.upper()@@ -47,21 +79,39 @@ def get_profile_key(gpu_name, vendor):return "AMD_GFX110X"return "RTX_40"+def get_os_key():+ return "win" if IS_WIN else "linux"++def resolve_cmd(cmd_entry):+ if isinstance(cmd_entry, dict):+ return cmd_entry.get(get_os_key())+ return cmd_entry+def run_cmd(cmd, env_vars=None):if not cmd: return++ if "&&" in cmd and not IS_WIN:+ print(f"\n>>> Running (Shell): {cmd}")+ custom_env = os.environ.copy()+ if env_vars: custom_env.update(env_vars)+ subprocess.run(cmd, shell=True, check=True, env=custom_env)+ return+print(f"\n>>> Running: {cmd}")custom_env = os.environ.copy()if env_vars:for k, v in env_vars.items():print(f" [ENV SET] {k}={v}")custom_env[k] = v+subprocess.run(cmd, shell=True, check=True, env=custom_env)def list_installs():found = []for k, v in ENV_MAP.items():if k in ["conda", "none"]: continue- if os.path.exists(os.path.join(v["dir"], "Scripts", "python.exe")): found.append(k)+ py_path = v["run"].format(dir=v["dir"])+ if os.path.exists(py_path): found.append(k)try:res = subprocess.check_output("conda env list", shell=True, encoding='utf-8')if "wangp " in res: found.append("conda")@@ -85,21 +135,42 @@ def install_from_keys(env_type, py_k, torch_k, triton_k, sage_k, flash_k, kernelif env_type != "none":if env_type == "conda": run_cmd(f"conda env remove -y -n {env_dir}")elif os.path.exists(env_dir): shutil.rmtree(env_dir)- run_cmd(ENV_MAP[env_type]["create"].format(ver=target_py_ver, dir=env_dir, sys_py=sys.executable))++ create_cmd = ENV_MAP[env_type]["create"].format(ver=target_py_ver, dir=env_dir, sys_py=sys.executable)+ run_cmd(create_cmd)pip = ENV_MAP[env_type]["install"].format(dir=env_dir)print(f"\n[2/3] Installing Torch: {config['components']['torch'][torch_k]['label']}...")- run_cmd(f"{pip} {config['components']['torch'][torch_k]['cmd']}")+ torch_cmd = resolve_cmd(config['components']['torch'][torch_k]['cmd'])+ run_cmd(f"{pip} {torch_cmd}")print(f"\n[3/3] Installing Requirements & Extras...")run_cmd(f"{pip} -r requirements.txt")- if triton_k: run_cmd(f"{pip} {config['components']['triton'][triton_k]['cmd']}")- if sage_k: run_cmd(f"{pip} {config['components']['sage'][sage_k]['cmd']}")- if flash_k: run_cmd(f"{pip} {config['components']['flash'][flash_k]['cmd']}")++ if triton_k:+ cmd = resolve_cmd(config['components']['triton'][triton_k]['cmd'])+ if cmd: run_cmd(f"{pip} {cmd}")++ if sage_k:+ cmd = resolve_cmd(config['components']['sage'][sage_k]['cmd'])+ if cmd.startswith("http") or cmd.startswith("sageattention"):+ run_cmd(f"{pip} {cmd}")+ else:+ if env_type == "venv" or env_type == "uv":+ act = f". {env_dir}/bin/activate && " if not IS_WIN else ""+ run_cmd(f"{act}{cmd}")+ elif env_type == "conda":+ pass++ if flash_k:+ cmd = resolve_cmd(config['components']['flash'][flash_k]['cmd'])+ if cmd: run_cmd(f"{pip} {cmd}")+for k in kernel_list:if k in config['components']['kernels']:- run_cmd(f"{pip} {config['components']['kernels'][k]['cmd']}")+ cmd = resolve_cmd(config['components']['kernels'][k]['cmd'])+ if cmd: run_cmd(f"{pip} {cmd}")def menu(title, options, recommended_key=None):print(f"\n--- {title} ---")@@ -118,13 +189,14 @@ def do_migrate(config):print("="*60)env = get_active_env()if env == "none":- print("No environment found. Please run install.bat first.")+ print("No environment found. Please run install first.")returnconfirm = input(f"This will wipe your {env} and rebuild. Proceed? (y/n): ")if confirm.lower() != 'y': return-- install_from_keys(env, target['python'], target['torch'], target['triton'], target['sage'], target['flash'], target['kernels'], config)++ target = config['gpu_profiles']['RTX_50']+ install_from_keys(env, target['python'], target['torch'], target['triton'], target['sage'], target.get('flash'), target['kernels'], config)def do_upgrade(config):print("\n" + "="*60)@@ -160,12 +232,16 @@ if __name__ == "__main__":elif args.mode == "run":env = get_active_env()env_vars = profile.get("env", {})- run_cmd(f"{ENV_MAP[env]['run'].format(dir=ENV_MAP[env]['dir'])} wgp.py", env_vars=env_vars)+ cmd_fmt = ENV_MAP[env]['run']+ cmd = f"{cmd_fmt.format(dir=ENV_MAP[env]['dir'])} wgp.py"+ run_cmd(cmd, env_vars=env_vars)elif args.mode == "update":run_cmd("git pull")env = get_active_env()- run_cmd(f"{ENV_MAP[env]['run'].format(dir=ENV_MAP[env]['dir'])} -m pip install -r requirements.txt")+ cmd_fmt = ENV_MAP[env]['run']+ cmd = f"{cmd_fmt.format(dir=ENV_MAP[env]['dir'])} -m pip install -r requirements.txt"+ run_cmd(cmd)elif args.mode == "migrate":do_migrate(cfg)