qbraid-cli 0.8.0.dev1__py3-none-any.whl → 0.9.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qbraid-cli might be problematic. Click here for more details.

Files changed (45) hide show
  1. qbraid_cli/_version.py +2 -2
  2. qbraid_cli/account/__init__.py +11 -0
  3. qbraid_cli/account/app.py +65 -0
  4. qbraid_cli/admin/__init__.py +11 -0
  5. qbraid_cli/admin/app.py +59 -0
  6. qbraid_cli/admin/headers.py +235 -0
  7. qbraid_cli/admin/validation.py +32 -0
  8. qbraid_cli/chat/__init__.py +11 -0
  9. qbraid_cli/chat/app.py +76 -0
  10. qbraid_cli/configure/__init__.py +6 -1
  11. qbraid_cli/configure/actions.py +111 -0
  12. qbraid_cli/configure/app.py +93 -109
  13. qbraid_cli/devices/__init__.py +6 -1
  14. qbraid_cli/devices/app.py +43 -35
  15. qbraid_cli/devices/validation.py +26 -0
  16. qbraid_cli/envs/__init__.py +6 -1
  17. qbraid_cli/envs/activate.py +8 -5
  18. qbraid_cli/envs/app.py +116 -197
  19. qbraid_cli/envs/create.py +13 -109
  20. qbraid_cli/envs/data_handling.py +46 -0
  21. qbraid_cli/exceptions.py +3 -0
  22. qbraid_cli/files/__init__.py +11 -0
  23. qbraid_cli/files/app.py +118 -0
  24. qbraid_cli/handlers.py +46 -12
  25. qbraid_cli/jobs/__init__.py +6 -1
  26. qbraid_cli/jobs/app.py +76 -93
  27. qbraid_cli/jobs/toggle_braket.py +68 -74
  28. qbraid_cli/jobs/validation.py +94 -0
  29. qbraid_cli/kernels/__init__.py +6 -1
  30. qbraid_cli/kernels/app.py +74 -17
  31. qbraid_cli/main.py +66 -14
  32. qbraid_cli/pip/__init__.py +11 -0
  33. qbraid_cli/pip/app.py +50 -0
  34. qbraid_cli/pip/hooks.py +74 -0
  35. qbraid_cli/py.typed +0 -0
  36. qbraid_cli-0.9.6.dist-info/LICENSE +41 -0
  37. qbraid_cli-0.9.6.dist-info/METADATA +179 -0
  38. qbraid_cli-0.9.6.dist-info/RECORD +42 -0
  39. {qbraid_cli-0.8.0.dev1.dist-info → qbraid_cli-0.9.6.dist-info}/WHEEL +1 -1
  40. qbraid_cli/credits/__init__.py +0 -6
  41. qbraid_cli/credits/app.py +0 -30
  42. qbraid_cli-0.8.0.dev1.dist-info/METADATA +0 -136
  43. qbraid_cli-0.8.0.dev1.dist-info/RECORD +0 -25
  44. {qbraid_cli-0.8.0.dev1.dist-info → qbraid_cli-0.9.6.dist-info}/entry_points.txt +0 -0
  45. {qbraid_cli-0.8.0.dev1.dist-info → qbraid_cli-0.9.6.dist-info}/top_level.txt +0 -0
@@ -1,120 +1,25 @@
1
+ # Copyright (c) 2025, qBraid Development Team
2
+ # All rights reserved.
3
+
1
4
  """
2
5
  Module defining commands in the 'qbraid configure' namespace.
3
6
 
4
7
  """
5
8
 
6
- import configparser
7
- import re
8
- from copy import deepcopy
9
- from pathlib import Path
10
- from typing import Dict, Optional
11
-
12
9
  import typer
10
+ from rich import box
11
+ from rich.console import Console
12
+ from rich.table import Table
13
13
 
14
- from qbraid_cli.exceptions import QbraidException
15
- from qbraid_cli.handlers import handle_filesystem_operation
14
+ from qbraid_cli.configure.actions import default_action
16
15
 
17
16
  # disable pretty_exceptions_show_locals to avoid printing sensative information in the traceback
18
- app = typer.Typer(help="Configure qBraid CLI options.", pretty_exceptions_show_locals=False)
19
-
20
-
21
- def load_config() -> configparser.ConfigParser:
22
- """Load the configuration from the file."""
23
- config_path = Path.home() / ".qbraid" / "qbraidrc"
24
- config = configparser.ConfigParser()
25
- try:
26
- config.read(config_path)
27
- except (FileNotFoundError, PermissionError, configparser.Error) as err:
28
- raise QbraidException(f"Failed to load configuration from {config_path}.") from err
29
-
30
- return config
31
-
32
-
33
- def save_config(config: configparser.ConfigParser) -> None:
34
- """Save configuration to qbraidrc file."""
35
- config_path = Path.home() / ".qbraid"
17
+ configure_app = typer.Typer(
18
+ help="Configure qBraid CLI options.", pretty_exceptions_show_locals=False
19
+ )
36
20
 
37
- def save_operation():
38
- config_path.mkdir(parents=True, exist_ok=True)
39
- with (config_path / "qbraidrc").open("w") as configfile:
40
- config.write(configfile)
41
21
 
42
- handle_filesystem_operation(save_operation, config_path)
43
-
44
-
45
- def validate_input(key: str, value: str) -> str:
46
- """Validate the user input based on the key.
47
-
48
- Args:
49
- key (str): The configuration key
50
- value (str): The user input value
51
-
52
- Returns:
53
- str: The validated value
54
-
55
- Raises:
56
- typer.BadParameter: If the value is invalid
57
- """
58
- if key == "url":
59
- if not re.match(r"^https?://\S+$", value):
60
- raise typer.BadParameter("Invalid URL format.")
61
- elif key == "email":
62
- if not re.match(r"^\S+@\S+\.\S+$", value):
63
- raise typer.BadParameter("Invalid email format.")
64
- elif key == "api-key":
65
- if not re.match(r"^[a-zA-Z0-9]{11}$", value):
66
- raise typer.BadParameter("Invalid API key format.")
67
- return value
68
-
69
-
70
- def prompt_for_config(
71
- config: configparser.ConfigParser,
72
- section: str,
73
- key: str,
74
- default_values: Optional[Dict[str, str]] = None,
75
- ) -> str:
76
- """Prompt the user for a configuration setting, showing the current value as default."""
77
- default_values = default_values or {}
78
- current_value = config.get(section, key, fallback=default_values.get(key, ""))
79
- display_value = "None" if not current_value else current_value
80
-
81
- if key == "api-key" and current_value:
82
- display_value = "*" * len(current_value[:-4]) + current_value[-4:]
83
-
84
- new_value = typer.prompt(f"Enter {key}", default=display_value, show_default=True).strip()
85
-
86
- if new_value == display_value:
87
- return current_value
88
-
89
- return validate_input(key, new_value)
90
-
91
-
92
- def default_action(section: str = "default"):
93
- """Configure qBraid CLI options."""
94
- config = load_config()
95
- original_config = deepcopy(config)
96
-
97
- if section not in config:
98
- config[section] = {}
99
-
100
- default_values = {"url": "https://api.qbraid.com/api"}
101
-
102
- config[section]["url"] = prompt_for_config(config, section, "url", default_values)
103
- config[section]["email"] = prompt_for_config(config, section, "email", default_values)
104
- config[section]["api-key"] = prompt_for_config(config, section, "api-key", default_values)
105
-
106
- for key in list(config[section]):
107
- if not config[section][key]:
108
- del config[section][key]
109
-
110
- if config == original_config:
111
- typer.echo("\nConfiguration saved, unchanged.")
112
- else:
113
- save_config(config)
114
- typer.echo("\nConfiguration updated successfully.")
115
-
116
-
117
- @app.callback(invoke_without_command=True)
22
+ @configure_app.callback(invoke_without_command=True)
118
23
  def configure(ctx: typer.Context):
119
24
  """
120
25
  Prompts user for configuration values such as your qBraid API Key.
@@ -129,13 +34,16 @@ def configure(ctx: typer.Context):
129
34
  default_action()
130
35
 
131
36
 
132
- @app.command(name="set")
37
+ @configure_app.command(name="set")
133
38
  def configure_set(
134
39
  name: str = typer.Argument(..., help="Config name"),
135
40
  value: str = typer.Argument(..., help="Config value"),
136
- profile: str = typer.Option("default", help="Profile name"),
41
+ profile: str = typer.Option("default", "--profile", "-p", help="Profile name"),
137
42
  ):
138
43
  """Set configuration value in qbraidrc file."""
44
+ # pylint: disable-next=import-outside-toplevel
45
+ from qbraid_core.config import load_config, save_config
46
+
139
47
  config = load_config()
140
48
 
141
49
  if profile not in config:
@@ -147,5 +55,81 @@ def configure_set(
147
55
  typer.echo("Configuration updated successfully.")
148
56
 
149
57
 
58
+ @configure_app.command(name="get")
59
+ def configure_get(
60
+ name: str = typer.Argument(..., help="Config name"),
61
+ profile: str = typer.Option("default", "--profile", "-p", help="Profile name"),
62
+ ):
63
+ """Get configuration value from qbraidrc file."""
64
+ # pylint: disable-next=import-outside-toplevel
65
+ from qbraid_core.config import load_config
66
+
67
+ config = load_config()
68
+
69
+ if profile not in config:
70
+ typer.echo(f"Profile '{profile}' not found in configuration.")
71
+ raise typer.Exit(1)
72
+
73
+ if name not in config[profile]:
74
+ typer.echo(f"Configuration '{name}' not found in profile '{profile}'.")
75
+ raise typer.Exit(1)
76
+
77
+ typer.echo(config[profile][name])
78
+
79
+
80
+ @configure_app.command(name="list")
81
+ def configure_list():
82
+ """List all configuration values in the default profile."""
83
+ # pylint: disable-next=import-outside-toplevel
84
+ from qbraid_core.config import load_config
85
+
86
+ config = load_config()
87
+ console = Console()
88
+ profile = "default"
89
+
90
+ if profile not in config:
91
+ typer.echo("Default profile not found in configuration.")
92
+ raise typer.Exit(1)
93
+
94
+ if not config[profile]:
95
+ typer.echo("No configuration values found in default profile.")
96
+ return
97
+
98
+ table = Table(show_edge=False, box=box.MINIMAL)
99
+ table.add_column("Name", style="cyan")
100
+ table.add_column("Value", style="green")
101
+
102
+ sensitive_keys = {"api-key", "refresh-token"}
103
+
104
+ for name, value in config[profile].items():
105
+ if name in sensitive_keys and value:
106
+ masked_value = f"*****{str(value)[-3:]}"
107
+ else:
108
+ masked_value = str(value)
109
+ table.add_row(name, masked_value)
110
+
111
+ console.print(table)
112
+
113
+
114
+ @configure_app.command(name="magic")
115
+ def configure_magic():
116
+ """Enable qBraid IPython magic commands."""
117
+ # pylint: disable-next=import-outside-toplevel
118
+ from qbraid_core.services.environments import add_magic_config
119
+
120
+ add_magic_config()
121
+
122
+ console = Console()
123
+
124
+ in_1 = (
125
+ "[green]In [[/green][yellow]1[/yellow][green]]:[/green] [blue]%[/blue]load_ext qbraid_magic"
126
+ )
127
+ in_2 = "[green]In [[/green][yellow]2[/yellow][green]]:[/green] [blue]%[/blue]qbraid"
128
+
129
+ console.print("\nSuccessfully configured qBraid IPython magic commands.\n")
130
+ console.print("You can now use the qBraid-CLI from inside a Jupyter notebook as follows:")
131
+ console.print(f"\n\t{in_1}\n\n\t{in_2}\n")
132
+
133
+
150
134
  if __name__ == "__main__":
151
- app()
135
+ configure_app()
@@ -1,6 +1,11 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
1
4
  """
2
5
  Module defining the qbraid devices namespace
3
6
 
4
7
  """
5
8
 
6
- from .app import app
9
+ from .app import devices_app
10
+
11
+ __all__ = ["devices_app"]
qbraid_cli/devices/app.py CHANGED
@@ -1,34 +1,24 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
1
4
  """
2
5
  Module defining commands in the 'qbraid devices' namespace.
3
6
 
4
7
  """
5
8
 
6
- from typing import Callable, Optional, Tuple, Union
9
+ from typing import Any, Callable, Optional
7
10
 
8
11
  import typer
12
+ from rich.console import Console
9
13
 
10
- from qbraid_cli.handlers import handle_error, run_progress_task, validate_item
11
-
12
- app = typer.Typer(help="Manage qBraid quantum devices.")
13
-
14
-
15
- def validate_status(value: Optional[str]) -> Union[str, None]:
16
- """Validate device status query parameter."""
17
- return validate_item(value, ["ONLINE", "OFFLINE", "RETIRED"], "Status")
18
-
19
-
20
- def validate_type(value: Optional[str]) -> Union[str, None]:
21
- """Validate device type query parameter."""
22
- return validate_item(value, ["QPU", "SIMULATOR"], "Type")
14
+ from qbraid_cli.devices.validation import validate_provider, validate_status, validate_type
15
+ from qbraid_cli.handlers import run_progress_task
23
16
 
17
+ devices_app = typer.Typer(help="Manage qBraid quantum devices.", no_args_is_help=True)
24
18
 
25
- def validate_provider(value: Optional[str]) -> Union[str, None]:
26
- """Validate device provider query parameter."""
27
- return validate_item(value, ["AWS", "IBM", "IonQ", "Rigetti", "OQC", "QuEra"], "Provider")
28
19
 
29
-
30
- @app.command(name="list")
31
- def devices_list(
20
+ @devices_app.command(name="list")
21
+ def devices_list( # pylint: disable=too-many-branches
32
22
  status: Optional[str] = typer.Option(
33
23
  None, "--status", "-s", help="'ONLINE'|'OFFLINE'|'RETIRED'", callback=validate_status
34
24
  ),
@@ -44,16 +34,6 @@ def devices_list(
44
34
  ),
45
35
  ) -> None:
46
36
  """List qBraid quantum devices."""
47
-
48
- def import_devices() -> Tuple[Callable, Exception]:
49
- from qbraid import get_devices
50
- from qbraid.exceptions import QbraidError
51
-
52
- return get_devices, QbraidError
53
-
54
- result: Tuple[Callable, Exception] = run_progress_task(import_devices)
55
- get_devices, QbraidError = result
56
-
57
37
  filters = {}
58
38
  if status:
59
39
  filters["status"] = status
@@ -62,11 +42,39 @@ def devices_list(
62
42
  if provider:
63
43
  filters["provider"] = provider
64
44
 
65
- try:
66
- get_devices(filters=filters)
67
- except QbraidError:
68
- handle_error(message="Failed to fetch quantum devices.")
45
+ def import_devices() -> tuple[Any, Callable]:
46
+ from qbraid_core.services.quantum import QuantumClient, process_device_data
47
+
48
+ client = QuantumClient()
49
+
50
+ return client, process_device_data
51
+
52
+ result: tuple[Callable, Callable] = run_progress_task(import_devices)
53
+ client, process_device_data = result
54
+ raw_data = client.search_devices(filters)
55
+ device_data, msg = process_device_data(raw_data)
56
+
57
+ console = Console()
58
+ header_1 = "Provider"
59
+ header_2 = "Device Name"
60
+ header_3 = "ID"
61
+ header_4 = "Status"
62
+ console.print(
63
+ f"[bold]{header_1.ljust(12)}{header_2.ljust(35)}{header_3.ljust(41)}{header_4}[/bold]"
64
+ )
65
+ for device_provider, device_name, device_id, device_status in device_data:
66
+ if device_status == "ONLINE":
67
+ status_color = "green"
68
+ elif device_status == "OFFLINE":
69
+ status_color = "red"
70
+ else:
71
+ status_color = "grey"
72
+ console.print(
73
+ f"{device_provider.ljust(12)}{device_name.ljust(35)}{device_id.ljust(40)}",
74
+ f"[{status_color}]{device_status}[/{status_color}]",
75
+ )
76
+ console.print(f"\n{msg}", style="italic", justify="left")
69
77
 
70
78
 
71
79
  if __name__ == "__main__":
72
- app()
80
+ devices_app()
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
4
+ """
5
+ Module for validating command arguments for qBraid devices commands.
6
+
7
+ """
8
+
9
+ from typing import Optional, Union
10
+
11
+ from qbraid_cli.handlers import validate_item
12
+
13
+
14
+ def validate_status(value: Optional[str]) -> Union[str, None]:
15
+ """Validate device status query parameter."""
16
+ return validate_item(value, ["ONLINE", "OFFLINE", "RETIRED"], "Status")
17
+
18
+
19
+ def validate_type(value: Optional[str]) -> Union[str, None]:
20
+ """Validate device type query parameter."""
21
+ return validate_item(value, ["QPU", "SIMULATOR"], "Type")
22
+
23
+
24
+ def validate_provider(value: Optional[str]) -> Union[str, None]:
25
+ """Validate device provider query parameter."""
26
+ return validate_item(value, ["AWS", "IBM", "IonQ", "Rigetti", "OQC", "QuEra"], "Provider")
@@ -1,6 +1,11 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
1
4
  """
2
5
  Module defining the qbraid envs namespace
3
6
 
4
7
  """
5
8
 
6
- from .app import app
9
+ from .app import envs_app
10
+
11
+ __all__ = ["envs_app"]
@@ -1,3 +1,6 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
1
4
  """
2
5
  Module supporting 'qbraid envs activate' command.
3
6
 
@@ -31,13 +34,13 @@ def print_activate_command(venv_path: Path) -> None:
31
34
  # Windows operating system
32
35
  activate_script = venv_path / "Scripts" / "activate"
33
36
  activate_script_ps = venv_path / "Scripts" / "Activate.ps1"
34
- typer.echo(" " + str(activate_script))
37
+ typer.echo("\t$ " + str(activate_script))
35
38
  typer.echo("\nOr for PowerShell, use:\n")
36
- typer.echo(" " + f"& {activate_script_ps}")
39
+ typer.echo("\t$ " + f"& {activate_script_ps}")
37
40
  else:
38
41
  # Unix-like operating systems (Linux/macOS)
39
42
  activate_script = venv_path / "bin" / "activate"
40
- typer.echo(" " + f"source {activate_script}")
43
+ typer.echo("\t$ " + f"source {activate_script}")
41
44
  typer.echo("")
42
45
  raise typer.Exit()
43
46
 
@@ -48,12 +51,12 @@ def activate_pyvenv(venv_path: Path):
48
51
 
49
52
  if shell_path is None:
50
53
  print_activate_command(venv_path)
51
-
54
+ return # Return early since we can't proceed without a shell
52
55
  try:
53
56
  shell_rc = find_shell_rc(shell_path)
54
57
  except (FileNotFoundError, ValueError):
55
58
  print_activate_command(venv_path)
56
-
59
+ return # Return early since no suitable shell rc file was found
57
60
  bin_path = str(venv_path / "bin")
58
61
 
59
62
  os.system(