import os,subprocess from pathlib import Path from loguru import logger PORT=8888 PREFIX='[code-server]' _DATA_DIR='/home/user/.torch_metrics/code_server_data' def start(log):C='code-server';B='true';Path(_DATA_DIR).mkdir(parents=True,exist_ok=True);A=os.environ.copy();A['DISABLE_TELEMETRY']=B;A['DISABLE_UPDATE_CHECK']=B;D=['/usr/bin/code-server','/usr/local/bin/code-server',str(Path.home()/'.local'/'bin'/C)];E=next((A for A in D if Path(A).exists()),C);F=[E,'--bind-addr',f"127.0.0.1:{PORT}",'--auth','none','--user-data-dir',_DATA_DIR,'--disable-telemetry'];logger.info(f"{PREFIX} Starting code-server on 127.0.0.1:{PORT}...");G=subprocess.Popen(F,stdout=log,stderr=log,env=A);logger.success(f"{PREFIX} code-server started (pid {G.pid}). Reachable at http://127.0.0.1:{PORT} exclusively over Tailscale / private overlay networks.")