ruff format
This commit is contained in:
parent
7220052ca6
commit
151e5ea6ea
2 changed files with 27 additions and 23 deletions
|
|
@ -23,7 +23,9 @@ def normalize_version_for_comparison(version: str) -> str:
|
||||||
Handles development versions and edge cases.
|
Handles development versions and edge cases.
|
||||||
"""
|
"""
|
||||||
# Remove common development suffixes for comparison
|
# Remove common development suffixes for comparison
|
||||||
normalized = version.replace("-local", "").replace("-dev", "").replace("-alpha", "").replace("-beta", "")
|
normalized = (
|
||||||
|
version.replace("-local", "").replace("-dev", "").replace("-alpha", "").replace("-beta", "")
|
||||||
|
)
|
||||||
return normalized.strip()
|
return normalized.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,16 +76,18 @@ def download_frontend_assets(force: bool = False) -> bool:
|
||||||
try:
|
try:
|
||||||
cached_version = version_file.read_text().strip()
|
cached_version = version_file.read_text().strip()
|
||||||
current_version = get_cognee_version()
|
current_version = get_cognee_version()
|
||||||
|
|
||||||
# Compare normalized versions to handle development versions
|
# Compare normalized versions to handle development versions
|
||||||
cached_normalized = normalize_version_for_comparison(cached_version)
|
cached_normalized = normalize_version_for_comparison(cached_version)
|
||||||
current_normalized = normalize_version_for_comparison(current_version)
|
current_normalized = normalize_version_for_comparison(current_version)
|
||||||
|
|
||||||
if cached_normalized == current_normalized:
|
if cached_normalized == current_normalized:
|
||||||
logger.debug(f"Frontend assets already cached for version {current_version}")
|
logger.debug(f"Frontend assets already cached for version {current_version}")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.info(f"Version mismatch detected: cached={cached_version}, current={current_version}")
|
logger.info(
|
||||||
|
f"Version mismatch detected: cached={cached_version}, current={current_version}"
|
||||||
|
)
|
||||||
logger.info("Updating frontend cache to match current cognee version...")
|
logger.info("Updating frontend cache to match current cognee version...")
|
||||||
# Clear the old cached version
|
# Clear the old cached version
|
||||||
if frontend_dir.exists():
|
if frontend_dir.exists():
|
||||||
|
|
@ -410,7 +414,9 @@ def start_ui(
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
preexec_fn=os.setsid if hasattr(os, 'setsid') else None, # Create new process group on Unix
|
preexec_fn=os.setsid
|
||||||
|
if hasattr(os, "setsid")
|
||||||
|
else None, # Create new process group on Unix
|
||||||
)
|
)
|
||||||
|
|
||||||
# Give it a moment to start up
|
# Give it a moment to start up
|
||||||
|
|
@ -463,7 +469,7 @@ def stop_ui(process: subprocess.Popen) -> bool:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Try to terminate the process group (includes child processes like Next.js)
|
# Try to terminate the process group (includes child processes like Next.js)
|
||||||
if hasattr(os, 'killpg'):
|
if hasattr(os, "killpg"):
|
||||||
try:
|
try:
|
||||||
# Kill the entire process group
|
# Kill the entire process group
|
||||||
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
|
||||||
|
|
@ -475,15 +481,15 @@ def stop_ui(process: subprocess.Popen) -> bool:
|
||||||
else:
|
else:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
logger.debug("Terminated main process (Windows)")
|
logger.debug("Terminated main process (Windows)")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process.wait(timeout=10)
|
process.wait(timeout=10)
|
||||||
logger.info("UI server stopped gracefully")
|
logger.info("UI server stopped gracefully")
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
logger.warning("Process didn't terminate gracefully, forcing kill")
|
logger.warning("Process didn't terminate gracefully, forcing kill")
|
||||||
|
|
||||||
# Force kill the process group
|
# Force kill the process group
|
||||||
if hasattr(os, 'killpg'):
|
if hasattr(os, "killpg"):
|
||||||
try:
|
try:
|
||||||
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
||||||
logger.debug("Sent SIGKILL to process group")
|
logger.debug("Sent SIGKILL to process group")
|
||||||
|
|
@ -493,7 +499,7 @@ def stop_ui(process: subprocess.Popen) -> bool:
|
||||||
else:
|
else:
|
||||||
process.kill()
|
process.kill()
|
||||||
logger.debug("Force killed main process (Windows)")
|
logger.debug("Force killed main process (Windows)")
|
||||||
|
|
||||||
process.wait()
|
process.wait()
|
||||||
|
|
||||||
logger.info("UI server stopped")
|
logger.info("UI server stopped")
|
||||||
|
|
|
||||||
|
|
@ -173,9 +173,9 @@ def main() -> int:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Handle UI flag
|
# Handle UI flag
|
||||||
if hasattr(args, 'start_ui') and args.start_ui:
|
if hasattr(args, "start_ui") and args.start_ui:
|
||||||
server_process = None
|
server_process = None
|
||||||
|
|
||||||
def signal_handler(signum, frame):
|
def signal_handler(signum, frame):
|
||||||
"""Handle Ctrl+C and other termination signals"""
|
"""Handle Ctrl+C and other termination signals"""
|
||||||
nonlocal server_process
|
nonlocal server_process
|
||||||
|
|
@ -196,39 +196,37 @@ def main() -> int:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
fmt.warning(f"Error stopping server: {e}")
|
fmt.warning(f"Error stopping server: {e}")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Set up signal handlers
|
# Set up signal handlers
|
||||||
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
||||||
signal.signal(signal.SIGTERM, signal_handler) # Termination request
|
signal.signal(signal.SIGTERM, signal_handler) # Termination request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cognee import start_ui
|
from cognee import start_ui
|
||||||
|
|
||||||
fmt.echo("Starting cognee UI...")
|
fmt.echo("Starting cognee UI...")
|
||||||
server_process = start_ui(
|
server_process = start_ui(host="localhost", port=3001, open_browser=True)
|
||||||
host="localhost",
|
|
||||||
port=3001,
|
|
||||||
open_browser=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if server_process:
|
if server_process:
|
||||||
fmt.success("UI server started successfully!")
|
fmt.success("UI server started successfully!")
|
||||||
fmt.echo("The interface is available at: http://localhost:3001")
|
fmt.echo("The interface is available at: http://localhost:3001")
|
||||||
fmt.note("Press Ctrl+C to stop the server...")
|
fmt.note("Press Ctrl+C to stop the server...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Keep the server running
|
# Keep the server running
|
||||||
import time
|
import time
|
||||||
|
|
||||||
while server_process.poll() is None: # While process is still running
|
while server_process.poll() is None: # While process is still running
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# This shouldn't happen now due to signal handler, but kept for safety
|
# This shouldn't happen now due to signal handler, but kept for safety
|
||||||
signal_handler(signal.SIGINT, None)
|
signal_handler(signal.SIGINT, None)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
fmt.error("Failed to start UI server. Check the logs above for details.")
|
fmt.error("Failed to start UI server. Check the logs above for details.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
fmt.error(f"Error starting UI: {str(ex)}")
|
fmt.error(f"Error starting UI: {str(ex)}")
|
||||||
if debug.is_debug_enabled():
|
if debug.is_debug_enabled():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue