mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
fix: correct all hanzo_cli imports to relative imports after package merge
- Fixed all imports in commands/*.py to use relative imports - Fixed cli.py and interactive modules imports - Hanzo CLI now works properly after package consolidation - Version 0.2.4 fully functional
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fix all remaining hanzo_cli imports to use relative imports."""
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
def fix_imports_in_file(filepath):
|
||||
"""Fix imports in a single file."""
|
||||
with open(filepath, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
original_content = content
|
||||
|
||||
# Replace hanzo_cli imports with relative imports
|
||||
replacements = [
|
||||
(r'from hanzo_cli\.utils\.output import', 'from ..utils.output import'),
|
||||
(r'from hanzo_cli\.utils\.config import', 'from ..utils.config import'),
|
||||
(r'from hanzo_cli\.utils import', 'from ..utils import'),
|
||||
(r'from hanzo_cli\.interactive\.dashboard import', 'from .interactive.dashboard import'),
|
||||
(r'from hanzo_cli\.interactive\.repl import', 'from .interactive.repl import'),
|
||||
(r'from hanzo_cli\.interactive import', 'from ..interactive import'),
|
||||
(r'from hanzo_cli\.cli import', 'from .cli import'),
|
||||
(r'from hanzo_cli import cli', 'from .. import cli'),
|
||||
(r'import hanzo_cli', 'from .. import cli as hanzo_cli'),
|
||||
]
|
||||
|
||||
for pattern, replacement in replacements:
|
||||
content = re.sub(pattern, replacement, content)
|
||||
|
||||
if content != original_content:
|
||||
with open(filepath, 'w') as f:
|
||||
f.write(content)
|
||||
return True
|
||||
return False
|
||||
|
||||
def main():
|
||||
base_path = Path("/Users/z/work/hanzo/python-sdk/pkg/hanzo/src/hanzo")
|
||||
|
||||
# Find all Python files
|
||||
python_files = list(base_path.rglob("*.py"))
|
||||
|
||||
print(f"Found {len(python_files)} Python files to check")
|
||||
|
||||
fixed_count = 0
|
||||
for filepath in python_files:
|
||||
if fix_imports_in_file(filepath):
|
||||
fixed_count += 1
|
||||
print(f"Fixed imports in: {filepath.relative_to(base_path.parent.parent)}")
|
||||
|
||||
print(f"\nFixed {fixed_count} files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Entry point for python -m hanzo_cli."""
|
||||
|
||||
from hanzo_cli.cli import main
|
||||
from .cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -84,7 +84,7 @@ def serve(ctx, name: str, port: int):
|
||||
@click.pass_context
|
||||
def dashboard(ctx):
|
||||
"""Open interactive dashboard."""
|
||||
from hanzo_cli.interactive.dashboard import run_dashboard
|
||||
from .interactive.dashboard import run_dashboard
|
||||
run_dashboard()
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from typing import List, Optional
|
||||
import click
|
||||
from rich.table import Table
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="agent")
|
||||
|
||||
@@ -9,7 +9,7 @@ import click
|
||||
import httpx
|
||||
from rich.prompt import Prompt
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="auth")
|
||||
|
||||
@@ -7,7 +7,7 @@ import click
|
||||
import httpx
|
||||
from rich.markdown import Markdown
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.command(name="chat")
|
||||
|
||||
@@ -8,7 +8,7 @@ import httpx
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
from rich.table import Table
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="cluster")
|
||||
|
||||
@@ -8,7 +8,7 @@ import click
|
||||
import yaml
|
||||
from rich.syntax import Syntax
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="config")
|
||||
@@ -24,7 +24,7 @@ def config_group():
|
||||
@click.pass_context
|
||||
def show(ctx, is_global: bool, is_local: bool, system: bool):
|
||||
"""Show configuration."""
|
||||
from hanzo_cli.utils.config import load_config, get_config_paths
|
||||
from ..utils.config import load_config, get_config_paths
|
||||
|
||||
# Determine which configs to show
|
||||
show_all = not (is_global or is_local or system)
|
||||
@@ -74,7 +74,7 @@ def show(ctx, is_global: bool, is_local: bool, system: bool):
|
||||
@click.pass_context
|
||||
def set(ctx, key: str, value: str, is_global: bool, is_local: bool):
|
||||
"""Set configuration value."""
|
||||
from hanzo_cli.utils.config import load_config, save_config, get_config_paths
|
||||
from ..utils.config import load_config, save_config, get_config_paths
|
||||
|
||||
# Determine target config
|
||||
paths = get_config_paths()
|
||||
@@ -127,7 +127,7 @@ def set(ctx, key: str, value: str, is_global: bool, is_local: bool):
|
||||
@click.pass_context
|
||||
def get(ctx, key: str, is_global: bool, is_local: bool):
|
||||
"""Get configuration value."""
|
||||
from hanzo_cli.utils.config import get_config_value
|
||||
from ..utils.config import get_config_value
|
||||
|
||||
scope = "local" if is_local else ("global" if is_global else None)
|
||||
value = get_config_value(key, scope=scope)
|
||||
@@ -148,7 +148,7 @@ def get(ctx, key: str, is_global: bool, is_local: bool):
|
||||
@click.pass_context
|
||||
def unset(ctx, key: str, is_global: bool, is_local: bool):
|
||||
"""Unset configuration value."""
|
||||
from hanzo_cli.utils.config import load_config, save_config, get_config_paths
|
||||
from ..utils.config import load_config, save_config, get_config_paths
|
||||
|
||||
# Determine target config
|
||||
paths = get_config_paths()
|
||||
@@ -194,7 +194,7 @@ def edit(ctx, system: bool, is_global: bool, is_local: bool):
|
||||
"""Edit configuration file in editor."""
|
||||
import os
|
||||
import subprocess
|
||||
from hanzo_cli.utils.config import get_config_paths
|
||||
from ..utils.config import get_config_paths
|
||||
|
||||
# Determine which config to edit
|
||||
paths = get_config_paths()
|
||||
@@ -229,7 +229,7 @@ def edit(ctx, system: bool, is_global: bool, is_local: bool):
|
||||
@click.pass_context
|
||||
def init(ctx):
|
||||
"""Initialize configuration."""
|
||||
from hanzo_cli.utils.config import init_config
|
||||
from ..utils.config import init_config
|
||||
|
||||
try:
|
||||
paths = init_config()
|
||||
|
||||
@@ -8,7 +8,7 @@ import click
|
||||
from rich.table import Table
|
||||
from rich.syntax import Syntax
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="mcp")
|
||||
|
||||
@@ -7,7 +7,7 @@ import click
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
from rich.table import Table
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="miner")
|
||||
|
||||
@@ -7,7 +7,7 @@ import click
|
||||
from rich.table import Table
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="network")
|
||||
|
||||
@@ -6,7 +6,7 @@ from typing import Optional
|
||||
|
||||
import click
|
||||
|
||||
from hanzo_cli.utils.output import console
|
||||
from ..utils.output import console
|
||||
|
||||
|
||||
@click.group(name="repl")
|
||||
|
||||
@@ -7,7 +7,7 @@ import click
|
||||
from rich.table import Table
|
||||
from rich.syntax import Syntax
|
||||
|
||||
from hanzo_cli.utils.output import console, handle_errors
|
||||
from ..utils.output import console, handle_errors
|
||||
|
||||
|
||||
@click.group(name="tools")
|
||||
|
||||
@@ -130,7 +130,7 @@ hanzo> mcp run read_file --arg path=README.md
|
||||
async def execute_command(self, cmd: str, args: str):
|
||||
"""Execute a CLI command."""
|
||||
# Import here to avoid circular imports
|
||||
from hanzo_cli import cli
|
||||
from .. import cli
|
||||
import click
|
||||
import sys
|
||||
|
||||
|
||||
Reference in New Issue
Block a user