Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 57 additions & 5 deletions src/parxy_cli/commands/drivers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import typer

from rich.table import Table
from pydantic import ValidationError

from parxy_core.facade import Parxy
from parxy_cli.console.console import Console

Expand All @@ -12,11 +15,60 @@
def drivers():
"""List supported drivers."""

drivers = Parxy.drivers()
factory = Parxy._get_factory()

# Get supported and custom drivers
supported_drivers = factory.get_supported_drivers()
custom_drivers = factory.get_custom_drivers()

drivers = supported_drivers + custom_drivers

console.action('Parxy drivers', space_after=False)

console.print(
f'[faint]⎿ [/faint] [bold]{len(drivers)}[/bold] driver{"s" if len(drivers) > 1 else ""} supported ({len(custom_drivers)} custom{"s" if len(custom_drivers) > 1 else ""}).'
)

if not drivers:
return

console.newline()

with console.shimmer(f'Checking installed drivers...'):
# Create a table for displaying driver information
table = Table(
show_header=True,
# header_style='bold',
show_lines=False,
padding=(0, 1),
)

table.add_column('Driver', no_wrap=True)
table.add_column('Status', no_wrap=True)
table.add_column('Type', style='faint')
table.add_column('Details', style='faint')

# Check each driver
for driver_name in drivers:
driver_type = 'custom' if driver_name in custom_drivers else 'built-in'

console.action('Parxy available drivers')
try:
# Attempt to create driver instance
factory.driver(driver_name)
status = '[green]✓ Ready[/green]'
details = ''
except ImportError as e:
status = '[red]✗ Not installed[/red]'
# Extract the missing module name from the error
missing_module = (
str(e).split("'")[1] if "'" in str(e) else 'dependencies'
)
details = f'Missing: {missing_module}'
except Exception as e:
status = '[yellow]⚠ Installed with warnings[/yellow]'
details = str(e)[:50].strip()

console.print(f'{len(drivers)} drivers supported:')
table.add_row(driver_name, status, driver_type, details)

driver_list = '\n'.join(f'- {driver}' for driver in drivers)
console.markdown(driver_list)
console.print(table)
console.newline()
10 changes: 10 additions & 0 deletions src/parxy_core/drivers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ def get_supported_drivers(self) -> List[str]:

return supported_drivers

def get_custom_drivers(self) -> List[str]:
"""Get the list of custom registered drivers.

Returns
-------
List[str]
The custom driver names
"""
return list(self.__custom_creators.keys())

def forget_drivers(self) -> 'DriverFactory':
"""Forget all instantiated and custom "drivers".

Expand Down
5 changes: 4 additions & 1 deletion src/parxy_core/facade/parxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def drivers(cls) -> Dict[str, Driver]:
Driver
The requested driver instance
"""
return cls._get_factory().get_supported_drivers()
return (
cls._get_factory().get_supported_drivers()
+ cls._get_factory().get_custom_drivers()
)

@classmethod
def config(cls) -> ParxyConfig:
Expand Down