qbraid-cli 0.8.1a0__py3-none-any.whl → 0.8.2__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.

qbraid_cli/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.8.1a0'
16
- __version_tuple__ = version_tuple = (0, 8, 1)
15
+ __version__ = version = '0.8.2'
16
+ __version_tuple__ = version_tuple = (0, 8, 2)
@@ -7,3 +7,5 @@ Module defining the qbraid admin namespace
7
7
  """
8
8
 
9
9
  from .app import admin_app
10
+
11
+ __all__ = ["admin_app"]
qbraid_cli/admin/app.py CHANGED
@@ -3,21 +3,20 @@
3
3
 
4
4
  """
5
5
  Module defining commands in the 'qbraid admin' namespace.
6
-
7
6
  """
8
7
 
9
8
  from typing import List
10
9
 
11
10
  import typer
12
11
 
12
+ from qbraid_cli.admin.buildlogs import buildlogs_app
13
13
  from qbraid_cli.admin.headers import check_and_fix_headers
14
14
  from qbraid_cli.admin.validation import validate_header_type, validate_paths_exist
15
15
 
16
- # disable pretty_exceptions_show_locals to avoid printing sensative information in the traceback
17
16
  admin_app = typer.Typer(
18
- help="CI/CD commands for qBraid maintainers.",
19
- pretty_exceptions_show_locals=False,
17
+ help="CI/CD commands for qBraid maintainers.", pretty_exceptions_show_locals=False
20
18
  )
19
+ admin_app.add_typer(buildlogs_app, name="buildlogs")
21
20
 
22
21
 
23
22
  @admin_app.command(name="headers")
@@ -0,0 +1,114 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
4
+ """
5
+ Module defining commands in the 'qbraid admin buildlogs' namespace.
6
+
7
+ This module uses the Typer library to create CLI commands for managing Docker builds and logs
8
+ in an administrative context.
9
+ """
10
+
11
+ import json
12
+
13
+ import typer
14
+ from qbraid_core.exceptions import RequestsApiError
15
+ from qbraid_core.services.admin.client import AdminClient
16
+ from rich.console import Console
17
+
18
+ from qbraid_cli.handlers import handle_error
19
+
20
+ buildlogs_app = typer.Typer(
21
+ help="Manage qBraid containerized services logs.", pretty_exceptions_show_locals=False
22
+ )
23
+ console = Console()
24
+
25
+
26
+ @buildlogs_app.command(name="get")
27
+ def get_docker_build_logs(
28
+ build_id: str = typer.Option(None, "--build_id", "-b", help="Name of the build ID")
29
+ ) -> None:
30
+ """
31
+ Fetches and displays Docker build logs for a specified build ID.
32
+
33
+ Args:
34
+ build_id (str, optional): The unique identifier for the Docker build.
35
+
36
+ This function queries the administrative backend to retrieve and display build logs.
37
+ If a build ID is provided, it will retrieve and display logs specific to that build ID.
38
+ If build ID not provided, fetches all logs.
39
+ """
40
+ client = AdminClient()
41
+
42
+ build_log = client.get_docker_build_logs(build_id)
43
+ if build_id and "buildLogs" in build_log and build_log["buildLogs"]:
44
+ log_entry = build_log["buildLogs"][0]
45
+ console.print(log_entry)
46
+ else:
47
+ console.print(build_log)
48
+
49
+
50
+ @buildlogs_app.command(name="post")
51
+ def post_docker_build_log(
52
+ data: str = typer.Option(..., "--data", "-d", help="Data to post to Docker logs")
53
+ ) -> None:
54
+ """
55
+ Posts a new Docker build log entry.
56
+
57
+ Args:
58
+ data (str): JSON string containing the data to be logged.
59
+
60
+ This command converts a JSON string into a dictionary and sends it to the backend service
61
+ to create a new Docker build log.
62
+ """
63
+ client = AdminClient()
64
+
65
+ try:
66
+ data_dict = json.loads(data)
67
+ console.print(client.post_docker_build_logs(data_dict))
68
+ except RequestsApiError:
69
+ handle_error(message="Couldn't post a build_log.")
70
+
71
+
72
+ @buildlogs_app.command(name="put")
73
+ def put_docker_build_log(
74
+ build_id: str = typer.Option(..., "--build_id", "-b", help="Name of the build ID"),
75
+ data: str = typer.Option(..., "--data", "-d", help="Data to post to Docker logs"),
76
+ ) -> None:
77
+ """
78
+ Updates an existing Docker build log entry by a given build ID.
79
+
80
+ Args:
81
+ build_id (str): The unique identifier of the Docker build to update.
82
+ data (str): JSON string containing the updated data for the log.
83
+
84
+ This command updates a Docker build log entry, identified by the provided build ID,
85
+ with the new data provided in JSON format.
86
+ """
87
+ client = AdminClient()
88
+
89
+ try:
90
+ data_dict = json.loads(data)
91
+ console.print(client.put_docker_build_logs(build_id, data_dict))
92
+ except RequestsApiError:
93
+ handle_error(message="Couldn't post a build_log.")
94
+
95
+
96
+ @buildlogs_app.command(name="delete")
97
+ def delete_docker_build_log(
98
+ build_id: str = typer.Option(..., "--build_id", "-b", help="ID of the build log to delete")
99
+ ) -> None:
100
+ """
101
+ Deletes a Docker build log entry by a specified build ID.
102
+
103
+ Args:
104
+ build_id (str): The unique identifier of the Docker build log to delete.
105
+
106
+ This command sends a request to delete a Docker build log identified by the provided build ID.
107
+ """
108
+ client = AdminClient()
109
+
110
+ console.print(client.delete_docker_build_logs(build_id))
111
+
112
+
113
+ if __name__ == "__main__":
114
+ buildlogs_app()
@@ -7,3 +7,5 @@ Module defining the qbraid configure namespace
7
7
  """
8
8
 
9
9
  from .app import configure_app
10
+
11
+ __all__ = ["configure_app"]
@@ -7,3 +7,5 @@ Module defining the qbraid credits namespace
7
7
  """
8
8
 
9
9
  from .app import credits_app
10
+
11
+ __all__ = ["credits_app"]
@@ -7,3 +7,5 @@ Module defining the qbraid devices namespace
7
7
  """
8
8
 
9
9
  from .app import devices_app
10
+
11
+ __all__ = ["devices_app"]
@@ -7,3 +7,5 @@ Module defining the qbraid envs namespace
7
7
  """
8
8
 
9
9
  from .app import envs_app
10
+
11
+ __all__ = ["envs_app"]
qbraid_cli/envs/app.py CHANGED
@@ -10,14 +10,19 @@ import shutil
10
10
  import subprocess
11
11
  import sys
12
12
  from pathlib import Path
13
- from typing import Any, Dict, Optional, Tuple
13
+ from typing import TYPE_CHECKING, Optional, Tuple
14
14
 
15
15
  import typer
16
16
  from rich.console import Console
17
17
 
18
- from qbraid_cli.envs.data_handling import installed_envs_data, request_delete_env, validate_env_name
18
+ from qbraid_cli.envs.create import create_qbraid_env_assets, create_venv
19
+ from qbraid_cli.envs.data_handling import get_envs_data as installed_envs_data
20
+ from qbraid_cli.envs.data_handling import validate_env_name
19
21
  from qbraid_cli.handlers import QbraidException, run_progress_task
20
22
 
23
+ if TYPE_CHECKING:
24
+ from qbraid_core.services.environments.client import EnvironmentManagerClient as EMC
25
+
21
26
  envs_app = typer.Typer(help="Manage qBraid environments.")
22
27
 
23
28
 
@@ -34,25 +39,14 @@ def envs_create( # pylint: disable=too-many-statements
34
39
  ),
35
40
  ) -> None:
36
41
  """Create a new qBraid environment."""
37
- from .create import create_qbraid_env_assets, create_venv
38
-
39
- def request_new_env(req_body: Dict[str, str]) -> Dict[str, Any]:
40
- """Send request to create new environment and return the slug."""
41
- from qbraid_core import QbraidSession, RequestsApiError
42
-
43
- session = QbraidSession()
44
-
45
- try:
46
- env_data = session.post("/environments/create", json=req_body).json()
47
- except RequestsApiError as err:
48
- raise QbraidException("Create environment request failed") from err
42
+ env_description = description or ""
49
43
 
50
- if env_data is None or len(env_data) == 0 or env_data.get("slug") is None:
51
- raise QbraidException(
52
- "Create environment request responsed with invalid environment data"
53
- )
44
+ def create_environment(*args, **kwargs) -> "Tuple[dict, EMC]":
45
+ """Create a qBraid environment."""
46
+ from qbraid_core.services.environments.client import EnvironmentManagerClient
54
47
 
55
- return env_data
48
+ client = EnvironmentManagerClient()
49
+ return client.create_environment(*args, **kwargs), client
56
50
 
57
51
  def gather_local_data() -> Tuple[Path, str]:
58
52
  """Gather environment data and return the slug."""
@@ -71,20 +65,10 @@ def envs_create( # pylint: disable=too-many-statements
71
65
 
72
66
  return env_path, python_version
73
67
 
74
- req_body = {
75
- "name": name,
76
- "description": description or "",
77
- "tags": "", # comma separated list of tags
78
- "code": "", # newline separated list of packages
79
- "visibility": "private",
80
- "kernelName": "",
81
- "prompt": "",
82
- "origin": "CLI",
83
- }
84
-
85
- environment = run_progress_task(
86
- request_new_env,
87
- req_body,
68
+ environment, emc = run_progress_task(
69
+ create_environment,
70
+ name,
71
+ env_description,
88
72
  description="Validating request...",
89
73
  error_message="Failed to create qBraid environment",
90
74
  )
@@ -94,7 +78,6 @@ def envs_create( # pylint: disable=too-many-statements
94
78
  description="Solving environment...",
95
79
  error_message="Failed to create qBraid environment",
96
80
  )
97
-
98
81
  slug = environment.get("slug")
99
82
  display_name = environment.get("displayName")
100
83
  prompt = environment.get("prompt")
@@ -120,7 +103,7 @@ def envs_create( # pylint: disable=too-many-statements
120
103
  user_confirmation = auto_confirm or typer.confirm("Proceed", default=True)
121
104
  typer.echo("")
122
105
  if not user_confirmation:
123
- request_delete_env(slug)
106
+ emc.delete_environment(slug)
124
107
  typer.echo("qBraidSystemExit: Exiting.")
125
108
  raise typer.Exit()
126
109
 
@@ -165,6 +148,13 @@ def envs_remove(
165
148
  ) -> None:
166
149
  """Delete a qBraid environment."""
167
150
 
151
+ def delete_environment(slug: str) -> None:
152
+ """Delete a qBraid environment."""
153
+ from qbraid_core.services.environments.client import EnvironmentManagerClient
154
+
155
+ emc = EnvironmentManagerClient()
156
+ emc.delete_environment(slug)
157
+
168
158
  def gather_local_data(env_name: str) -> Tuple[Path, str]:
169
159
  """Get environment path and slug from name (alias)."""
170
160
  installed, aliases = installed_envs_data()
@@ -190,7 +180,7 @@ def envs_remove(
190
180
  if auto_confirm or typer.confirm(confirmation_message, abort=True):
191
181
  typer.echo("")
192
182
  run_progress_task(
193
- request_delete_env,
183
+ delete_environment,
194
184
  slug,
195
185
  description="Deleting remote environment data...",
196
186
  error_message="Failed to delete qBraid environment",
qbraid_cli/envs/create.py CHANGED
@@ -5,93 +5,29 @@
5
5
  Module supporting 'qbraid envs create' command.
6
6
 
7
7
  """
8
-
9
8
  import json
10
9
  import os
11
10
  import shutil
12
- import subprocess
13
11
  import sys
14
- from typing import Optional
15
-
16
-
17
- def replace_str(target: str, replacement: str, file_path: str) -> None:
18
- """Replace all instances of string in file"""
19
- with open(file_path, "r", encoding="utf-8") as file:
20
- content = file.read()
21
-
22
- content = content.replace(target, replacement)
23
-
24
- with open(file_path, "w", encoding="utf-8") as file:
25
- file.write(content)
26
-
27
-
28
- def update_state_json(
29
- slug_path: str,
30
- install_complete: int,
31
- install_success: int,
32
- message: Optional[str] = None,
33
- env_name: Optional[str] = None,
34
- ) -> None:
35
- """Update environment's install status values in a JSON file.
36
- Truth table values: 0 = False, 1 = True, -1 = Unknown
37
- """
38
- # Set default message if none provided
39
- message = "" if message is None else message.replace("\n", " ")
40
-
41
- # File path for state.json
42
- state_json_path = os.path.join(slug_path, "state.json")
43
12
 
44
- # Read existing data or use default structure
45
- if os.path.exists(state_json_path):
46
- with open(state_json_path, "r", encoding="utf-8") as f:
47
- data = json.load(f)
48
- else:
49
- data = {"install": {}}
50
-
51
- # Update the data
52
- data["install"]["complete"] = install_complete
53
- data["install"]["success"] = install_success
54
- data["install"]["message"] = message
55
-
56
- if env_name is not None:
57
- data["name"] = env_name
58
-
59
- # Write updated data back to state.json
60
- with open(state_json_path, "w", encoding="utf-8") as f:
61
- json.dump(data, f, indent=4)
62
13
 
14
+ def create_venv(*args, **kwargs) -> None:
15
+ """Create a python virtual environment for the qBraid environment."""
16
+ from qbraid_core.services.environments import create_local_venv
63
17
 
64
- def create_venv(slug_path: str, prompt: str) -> None:
65
- """Create virtual environment and swap PS1 display name."""
66
- venv_path = os.path.join(slug_path, "pyenv")
67
- subprocess.run([sys.executable, "-m", "venv", venv_path], check=True)
18
+ return create_local_venv(*args, **kwargs)
68
19
 
69
- # Determine the correct directory for activation scripts based on the operating system
70
- if sys.platform == "win32":
71
- scripts_path = os.path.join(venv_path, "Scripts")
72
- activate_files = ["activate.bat", "Activate.ps1"]
73
- else:
74
- scripts_path = os.path.join(venv_path, "bin")
75
- activate_files = ["activate", "activate.csh", "activate.fish"]
76
20
 
77
- for file in activate_files:
78
- file_path = os.path.join(scripts_path, file)
79
- if os.path.isfile(file_path):
80
- replace_str("(pyenv)", f"({prompt})", file_path)
21
+ def update_state_json(*ags, **kwargs) -> None:
22
+ """Update the state.json file for the qBraid environment."""
23
+ from qbraid_core.services.environments.state import update_install_status
81
24
 
82
- replace_str(
83
- "include-system-site-packages = false",
84
- "include-system-site-packages = true",
85
- os.path.join(venv_path, "pyvenv.cfg"),
86
- )
87
-
88
- update_state_json(slug_path, 1, 1)
25
+ return update_install_status(*ags, **kwargs)
89
26
 
90
27
 
91
28
  def create_qbraid_env_assets(slug: str, alias: str, kernel_name: str, slug_path: str) -> None:
92
29
  """Create a qBraid environment including python venv, PS1 configs,
93
30
  kernel resource files, and qBraid state.json."""
94
- # pylint: disable-next=import-outside-toplevel
95
31
  from jupyter_client.kernelspec import KernelSpecManager
96
32
 
97
33
  local_resource_dir = os.path.join(slug_path, "kernels", f"python3_{slug}")
@@ -123,6 +59,3 @@ def create_qbraid_env_assets(slug: str, alias: str, kernel_name: str, slug_path:
123
59
  loc_path = os.path.join(local_resource_dir, file)
124
60
  if os.path.isfile(sys_path):
125
61
  shutil.copy(sys_path, loc_path)
126
-
127
- # create python venv
128
- create_venv(slug_path, alias)
@@ -6,85 +6,23 @@ Module for handling data related to qBraid environments.
6
6
 
7
7
  """
8
8
 
9
- import json
10
- import keyword
11
- import re
12
- from pathlib import Path
13
- from typing import Dict, List, Tuple
14
-
15
9
  import typer
16
10
 
17
11
  from qbraid_cli.handlers import QbraidException
18
12
 
19
13
 
20
- def is_valid_env_name(env_name: str) -> bool: # pylint: disable=too-many-return-statements
21
- """
22
- Validates a Python virtual environment name against best practices.
23
-
24
- This function checks if the given environment name is valid based on certain
25
- criteria, including length, use of special characters, reserved names, and
26
- operating system-specific restrictions.
27
-
28
- Args:
29
- env_name (str): The name of the Python virtual environment to validate.
30
-
31
- Returns:
32
- bool: True if the name is valid, False otherwise.
33
-
34
- Raises:
35
- ValueError: If the environment name is not a string or is empty.
36
- """
37
- # Basic checks for empty names or purely whitespace names
38
- if not env_name or env_name.isspace():
39
- return False
40
-
41
- # Check for invalid characters, including shell metacharacters and spaces
42
- if re.search(r'[<>:"/\\|?*\s&;()$[\]#~!{}]', env_name):
43
- return False
44
-
45
- if env_name.startswith("tmp"):
46
- return False
47
-
48
- # Reserved names for Windows (example list, can be expanded)
49
- reserved_names = [
50
- "CON",
51
- "PRN",
52
- "AUX",
53
- "NUL",
54
- "COM1",
55
- "COM2",
56
- "COM3",
57
- "COM4",
58
- "COM5",
59
- "COM6",
60
- "COM7",
61
- "COM8",
62
- "COM9",
63
- "LPT1",
64
- "LPT2",
65
- "LPT3",
66
- "LPT4",
67
- "LPT5",
68
- "LPT6",
69
- "LPT7",
70
- "LPT8",
71
- "LPT9",
72
- ]
73
- if env_name.upper() in reserved_names:
74
- return False
75
-
76
- if len(env_name) > 20:
77
- return False
78
-
79
- # Check against Python reserved words
80
- if keyword.iskeyword(env_name):
81
- return False
82
-
83
- # Check if it starts with a number, which is not a good practice
84
- if env_name[0].isdigit():
85
- return False
86
-
87
- return True
14
+ def get_envs_data(*args, **kwargs) -> dict:
15
+ """Get data for installed environments."""
16
+ from qbraid_core.services.environments.paths import installed_envs_data
17
+
18
+ return installed_envs_data(*args, **kwargs)
19
+
20
+
21
+ def is_valid_env_name(value: str) -> bool:
22
+ """Check if a given string is a valid Python environment name."""
23
+ from qbraid_core.services.environments.validate import is_valid_env_name as is_valid
24
+
25
+ return is_valid(value)
88
26
 
89
27
 
90
28
  def validate_env_name(value: str) -> str:
@@ -96,38 +34,6 @@ def validate_env_name(value: str) -> str:
96
34
  return value
97
35
 
98
36
 
99
- def installed_envs_data() -> Tuple[Dict[str, Path], Dict[str, str]]:
100
- """Gather paths and aliases for all installed qBraid environments."""
101
- from qbraid_core.services.environments.paths import get_default_envs_paths, is_valid_slug
102
-
103
- installed = {}
104
- aliases = {}
105
-
106
- qbraid_env_paths: List[Path] = get_default_envs_paths()
107
-
108
- for env_path in qbraid_env_paths:
109
- for entry in env_path.iterdir():
110
- if entry.is_dir() and is_valid_slug(entry.name):
111
- installed[entry.name] = entry
112
-
113
- if entry.name == "qbraid_000000":
114
- aliases["default"] = entry.name
115
- continue
116
-
117
- state_json_path = entry / "state.json"
118
- if state_json_path.exists():
119
- try:
120
- with open(state_json_path, "r", encoding="utf-8") as f:
121
- data = json.load(f)
122
- aliases[data.get("name", entry.name[:-7])] = entry.name
123
- # pylint: disable-next=broad-exception-caught
124
- except (json.JSONDecodeError, Exception):
125
- aliases[entry.name[:-7]] = entry.name
126
- else:
127
- aliases[entry.name[:-7]] = entry.name
128
- return installed, aliases
129
-
130
-
131
37
  def request_delete_env(slug: str) -> str:
132
38
  """Send request to delete environment given slug."""
133
39
  from qbraid_core import QbraidSession, RequestsApiError
@@ -7,3 +7,5 @@ Module defining the qbraid jobs namespace
7
7
  """
8
8
 
9
9
  from .app import jobs_app
10
+
11
+ __all__ = ["jobs_app"]
@@ -36,13 +36,10 @@ def get_package_data(package: str) -> Tuple[str, str, str, str]:
36
36
 
37
37
  """
38
38
  # pylint: disable=import-outside-toplevel
39
- from qbraid_core.system import (
40
- QbraidSystemError,
41
- get_active_python_path,
42
- get_active_site_packages_path,
43
- get_latest_package_version,
44
- get_local_package_version,
45
- )
39
+ from qbraid_core.system.exceptions import QbraidSystemError
40
+ from qbraid_core.system.executables import get_active_python_path
41
+ from qbraid_core.system.packages import get_active_site_packages_path
42
+ from qbraid_core.system.versions import get_latest_package_version, get_local_package_version
46
43
 
47
44
  try:
48
45
  python_pathlib = get_active_python_path()
@@ -7,3 +7,5 @@ Module defining the qbraid kernels namespace
7
7
  """
8
8
 
9
9
  from .app import kernels_app
10
+
11
+ __all__ = ["kernels_app"]
qbraid_cli/kernels/app.py CHANGED
@@ -12,7 +12,6 @@ import typer
12
12
  from jupyter_client.kernelspec import KernelSpecManager
13
13
  from rich.console import Console
14
14
 
15
- from qbraid_cli.envs.data_handling import installed_envs_data
16
15
  from qbraid_cli.handlers import handle_error
17
16
 
18
17
  kernels_app = typer.Typer(help="Manage qBraid kernels.")
@@ -20,6 +19,9 @@ kernels_app = typer.Typer(help="Manage qBraid kernels.")
20
19
 
21
20
  def _get_kernels_path(environment: str) -> Path:
22
21
  """Get the path to the kernels directory for the given environment."""
22
+ # pylint: disable-next=import-outside-toplevel
23
+ from qbraid_core.services.environments.paths import installed_envs_data
24
+
23
25
  slug_to_path, name_to_slug = installed_envs_data()
24
26
 
25
27
  if environment in name_to_slug:
qbraid_cli/main.py CHANGED
@@ -15,6 +15,7 @@ from qbraid_cli.devices.app import devices_app
15
15
  from qbraid_cli.envs.app import envs_app
16
16
  from qbraid_cli.jobs.app import jobs_app
17
17
  from qbraid_cli.kernels.app import kernels_app
18
+ from qbraid_cli.pip.app import pip_app
18
19
 
19
20
  app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
20
21
 
@@ -25,6 +26,7 @@ app.add_typer(devices_app, name="devices")
25
26
  app.add_typer(envs_app, name="envs")
26
27
  app.add_typer(jobs_app, name="jobs")
27
28
  app.add_typer(kernels_app, name="kernels")
29
+ app.add_typer(pip_app, name="pip")
28
30
 
29
31
 
30
32
  def version_callback(value: bool):
@@ -0,0 +1,11 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
4
+ """
5
+ Module defining the qbraid pip namespace
6
+
7
+ """
8
+
9
+ from .app import pip_app
10
+
11
+ __all__ = ["pip_app"]
qbraid_cli/pip/app.py ADDED
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
4
+ """
5
+ Module defining commands in the 'qbraid pip' namespace.
6
+
7
+ """
8
+ import subprocess
9
+ import sys
10
+
11
+ import typer
12
+ from qbraid_core.system.exceptions import QbraidSystemError
13
+ from qbraid_core.system.executables import get_active_python_path
14
+
15
+ from qbraid_cli.handlers import handle_error
16
+ from qbraid_cli.pip.hooks import get_env_cfg_path, safe_set_include_sys_packages
17
+
18
+ # disable pretty_exceptions_show_locals to avoid printing sensative information in the traceback
19
+ pip_app = typer.Typer(help="Run pip command in active qBraid environment.")
20
+
21
+
22
+ @pip_app.command(
23
+ "install", context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
24
+ )
25
+ def pip_install(ctx: typer.Context):
26
+ """
27
+ Perform pip install action with open-ended arguments and options.
28
+
29
+ """
30
+ try:
31
+ python_exe = get_active_python_path()
32
+ cfg_path = get_env_cfg_path(python_exe)
33
+ except QbraidSystemError:
34
+ python_exe = sys.executable
35
+ cfg_path = None
36
+
37
+ safe_set_include_sys_packages(False, cfg_path)
38
+
39
+ command = [str(python_exe), "-m", "pip", "install"] + ctx.args
40
+
41
+ try:
42
+ subprocess.check_call(command)
43
+ except (subprocess.CalledProcessError, FileNotFoundError):
44
+ handle_error(message="Failed carry-out pip command.")
45
+ finally:
46
+ safe_set_include_sys_packages(True, cfg_path)
47
+
48
+
49
+ if __name__ == "__main__":
50
+ pip_app()
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2024, qBraid Development Team
2
+ # All rights reserved.
3
+
4
+ """
5
+ Module defining pre- and post-command hooks for the 'qbraid pip' namespace.
6
+
7
+ """
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import Optional, Union
11
+
12
+ from qbraid_core.services.environments import get_default_envs_paths
13
+ from qbraid_core.system.executables import python_paths_equivalent
14
+ from qbraid_core.system.packages import (
15
+ extract_include_sys_site_pkgs_value,
16
+ set_include_sys_site_pkgs_value,
17
+ )
18
+
19
+
20
+ def safe_set_include_sys_packages(value: bool, file_path: Optional[Union[str, Path]]) -> None:
21
+ """Set include-system-site-packages value safely"""
22
+ if not file_path:
23
+ return None
24
+
25
+ try:
26
+ set_include_sys_site_pkgs_value(value, file_path)
27
+ except Exception: # pylint: disable=broad-exception-caught
28
+ pass
29
+
30
+ return None
31
+
32
+
33
+ def find_matching_prefix(python_executable: Path, path_list: list[Path]) -> Optional[Path]:
34
+ """
35
+ Finds and returns the first path in the list that is a prefix of the Python executable path.
36
+
37
+ Args:
38
+ python_executable (Path): The path to the Python executable.
39
+ path_list (List[Path]): A list of paths to check against the Python executable path.
40
+
41
+ Returns:
42
+ Optional[Path]: The first matching path that is a prefix of the Python executable path,
43
+ or None if no match is found.
44
+ """
45
+ python_executable_str = str(python_executable.resolve())
46
+ for path in path_list:
47
+ if python_executable_str.startswith(str(path.resolve())):
48
+ return path
49
+ return None
50
+
51
+
52
+ def get_env_cfg_path(python_exe: Path) -> Optional[Path]:
53
+ """Get the path to the pyvenv.cfg file."""
54
+ is_sys_python = python_paths_equivalent(python_exe, sys.executable)
55
+
56
+ if is_sys_python:
57
+ return None
58
+
59
+ all_envs_paths = get_default_envs_paths()
60
+
61
+ env_path = find_matching_prefix(python_exe, all_envs_paths)
62
+
63
+ if not env_path:
64
+ return None
65
+
66
+ cfg_path = env_path / "pyvenv.cfg"
67
+
68
+ should_flip = extract_include_sys_site_pkgs_value(cfg_path)
69
+
70
+ if should_flip:
71
+ return cfg_path
72
+
73
+ return None
qbraid_cli/py.typed ADDED
File without changes
@@ -0,0 +1,41 @@
1
+ qBraid Closed-Source Software License
2
+
3
+ Copyright (c) 2024, qBraid Development Team
4
+
5
+ All rights reserved.
6
+
7
+ This license agreement ("License") is between the qBraid Development Team ("Author") and you, the Licensee. By using or distributing the qBraid ("Software"), you agree to the following terms:
8
+
9
+ 1. Grant of License.
10
+
11
+ Subject to the terms of this License, the Author grants you a non-exclusive, non-transferable license to use the Software for personal, academic, and educational purposes. Use of the Software for commercial purposes is strictly prohibited unless express permission is granted by the Author.
12
+
13
+ 2. Distribution.
14
+
15
+ You may distribute the Software to others, provided that any such distribution is made under the same terms of this License. Modifications to the Software may not be distributed.
16
+
17
+ 3. Modification.
18
+
19
+ You are permitted to modify the Software for personal use. You may contribute improvements or bug fixes back to the Author or the community, but you may not distribute the modifications.
20
+
21
+ 4. Commercial Use.
22
+
23
+ The Software may not be used for commercial purposes without explicit, prior written permission from the Author. Permissions for commercial use will be considered on a case-by-case basis.
24
+
25
+ 5. Attribution
26
+
27
+ If the Software is used in a non-private setting, including but not limited to academic work, commercial settings, or published literature, attribution must be given to the "qBraid Jupyter Environment Manager authored by the qBraid Development Team."
28
+
29
+ 6. Disclaimer of Warranty.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
32
+
33
+ 7. Limitation of Liability.
34
+
35
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
+
37
+ 8. Termination.
38
+
39
+ This License is effective until terminated. Your rights under this License will terminate automatically without notice from the Author if you fail to comply with any term(s) of this License.
40
+
41
+ By using the Software, you agree to be bound by the terms of this License. Redistribution of the Software or use of the Software other than as specifically authorized under this License is prohibited and may result in severe civil and criminal penalties.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qbraid-cli
3
- Version: 0.8.1a0
3
+ Version: 0.8.2
4
4
  Summary: Command Line Interface for interacting with all parts of the qBraid platform.
5
5
  Author-email: qBraid Development Team <contact@qbraid.com>
6
6
  License: Proprietary
@@ -26,24 +26,17 @@ Classifier: Programming Language :: Python :: 3.11
26
26
  Classifier: Programming Language :: Python :: 3.12
27
27
  Requires-Python: >=3.9
28
28
  Description-Content-Type: text/markdown
29
+ License-File: LICENSE
29
30
  Requires-Dist: typer >=0.12.1
30
31
  Requires-Dist: rich >=10.11.0
31
32
  Requires-Dist: jupyter-client <9.0.0,>=7.0.0
32
33
  Requires-Dist: ipykernel
33
- Requires-Dist: qbraid-core >=0.1.4
34
+ Requires-Dist: qbraid-core >=0.1.13
34
35
  Provides-Extra: dev
35
- Requires-Dist: black ; extra == 'dev'
36
+ Requires-Dist: ruff ; extra == 'dev'
36
37
  Requires-Dist: isort ; extra == 'dev'
37
- Requires-Dist: pylint ; extra == 'dev'
38
+ Requires-Dist: black ; extra == 'dev'
38
39
  Requires-Dist: pytest ; extra == 'dev'
39
- Provides-Extra: docs
40
- Requires-Dist: sphinx <7.4.0,>=7.2.6 ; extra == 'docs'
41
- Requires-Dist: sphinx-rtd-theme <2.1,>=1.3 ; extra == 'docs'
42
- Requires-Dist: docutils <0.22 ; extra == 'docs'
43
- Requires-Dist: toml ; extra == 'docs'
44
- Requires-Dist: build ; extra == 'docs'
45
- Requires-Dist: m2r ; extra == 'docs'
46
- Requires-Dist: typer ; extra == 'docs'
47
40
  Provides-Extra: jobs
48
41
  Requires-Dist: amazon-braket-sdk >=1.48.1 ; extra == 'jobs'
49
42
 
@@ -54,7 +47,6 @@ Requires-Dist: amazon-braket-sdk >=1.48.1 ; extra == 'jobs'
54
47
  [![Python verions](https://img.shields.io/pypi/pyversions/qbraid-cli.svg?color=blue)](https://pypi.org/project/qbraid-cli/)
55
48
  [![Downloads](https://static.pepy.tech/badge/qbraid-cli)](https://pepy.tech/project/qbraid-cli)
56
49
  [![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/qBraid/qBraid-Lab/issues)
57
- [![Discord](https://img.shields.io/discord/771898982564626445.svg?color=pink)](https://discord.gg/KugF6Cnncm)
58
50
 
59
51
  Command Line Interface for interacting with all parts of the qBraid platform.
60
52
 
@@ -71,7 +63,7 @@ For help, see qBraid Lab User Guide: [Getting Started](https://docs.qbraid.com/p
71
63
 
72
64
  You can also install the qBraid-CLI from PyPI with:
73
65
 
74
- ```shell
66
+ ```bash
75
67
  pip install qbraid-cli
76
68
  ```
77
69
 
@@ -85,13 +77,13 @@ After installation, you must configure your account credentials to use the CLI l
85
77
  your [account page](https://account.qbraid.com/):
86
78
  3. Save your API key from step 2 in local configuration file `~/.qbraid/qbraidrc` using:
87
79
 
88
- ```shell
80
+ ```bash
89
81
  $ qbraid configure
90
82
  ```
91
83
 
92
84
  ## Basic Commands
93
85
 
94
- ```shell
86
+ ```bash
95
87
  $ qbraid
96
88
  ----------------------------------
97
89
  * Welcome to the qBraid CLI! *
@@ -114,19 +106,19 @@ Reference Docs: https://docs.qbraid.com/projects/cli/en/stable/guide/overview.ht
114
106
 
115
107
  A qBraid CLI command has the following structure:
116
108
 
117
- ```shell
109
+ ```bash
118
110
  $ qbraid <command> <subcommand> [options and parameters]
119
111
  ```
120
112
 
121
113
  For example, to list installed environments, the command would be:
122
114
 
123
- ```shell
115
+ ```bash
124
116
  $ qbraid envs list
125
117
  ```
126
118
 
127
119
  To view help documentation, use one of the following:
128
120
 
129
- ```shell
121
+ ```bash
130
122
  $ qbraid --help
131
123
  $ qbraid <command> --help
132
124
  $ qbraid <command> <subcommand> --help
@@ -134,7 +126,7 @@ $ qbraid <command> <subcommand> --help
134
126
 
135
127
  For example:
136
128
 
137
- ```shell
129
+ ```bash
138
130
  $ qbraid --help
139
131
 
140
132
  Usage: qbraid [OPTIONS] COMMAND [ARGS]...
@@ -158,7 +150,7 @@ Commands
158
150
 
159
151
  To get the version of the qBraid CLI:
160
152
 
161
- ```shell
153
+ ```bash
162
154
  $ qbraid --version
163
155
  ```
164
156
 
@@ -166,7 +158,7 @@ $ qbraid --version
166
158
 
167
159
  You can also access the CLI directly from within [Notebooks](https://docs.qbraid.com/projects/lab/en/latest/lab/notebooks.html) using IPython [magic commands](https://ipython.readthedocs.io/en/stable/interactive/magics.html). First, configure the qBraid magic commands extension using:
168
160
 
169
- ```shell
161
+ ```bash
170
162
  $ qbraid configure magic
171
163
  ```
172
164
 
@@ -0,0 +1,39 @@
1
+ qbraid_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ qbraid_cli/_version.py,sha256=t6tJJG56wlBKsg_0M1Q4l1ir09jgXRw1tolMbDalW9g,411
3
+ qbraid_cli/exceptions.py,sha256=KjlhYJhSHMVazaNiBjD_Ur06w4sekP8zRsFzBdyIpno,672
4
+ qbraid_cli/handlers.py,sha256=glxTEwxax3zKgYl9qsZ2evZXgrWQrseJS_OGyHTMFeA,7040
5
+ qbraid_cli/main.py,sha256=eRgBEYj9WPxHqTbSQvlV39yaDje-6yvZdrTnw5UQbQY,2638
6
+ qbraid_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ qbraid_cli/admin/__init__.py,sha256=qcWD5mQEUCtr49mrUpZmk7eGDe0L_Gtc8RwZmzIXSwo,175
8
+ qbraid_cli/admin/app.py,sha256=ZyTBkEvlAR-xK3fbC32yntsE3rywzL4WHjJzRTFTlzs,1454
9
+ qbraid_cli/admin/buildlogs.py,sha256=1i7CRpkIHIcKgGvHesPr9duCkyV7M-MESaHI5Z3ZdD0,3578
10
+ qbraid_cli/admin/headers.py,sha256=E6mE3odZL57VfHHZxYtRUkqMKmrmT4zuUoINzI7eJF8,6435
11
+ qbraid_cli/admin/validation.py,sha256=LkAVXlHtM0MhCa34MIWrfX59wGXMVlZmdVB4-AQ8fBk,1003
12
+ qbraid_cli/configure/__init__.py,sha256=YaJ74Ztz2vl3eYp8_jVBucWkXscxz7EZEIzr70OfuOM,187
13
+ qbraid_cli/configure/actions.py,sha256=3rrWHaCAsogyx0Ll-lcjbSzldD4kPuz1z6VQiWebSWw,3203
14
+ qbraid_cli/configure/app.py,sha256=1uRe2lkUA4TtYb5b4mbD4LH-cKCbsZGT3Wfk7fpNzX0,2414
15
+ qbraid_cli/credits/__init__.py,sha256=MJhgWgpFT1_886sB-_POlRs1y3SRy23HIrKVBkp0X-Y,181
16
+ qbraid_cli/credits/app.py,sha256=AY3qtveO50KeQ2XREiEVqUcTrESgRuoqt9pt2Z8t4Y0,866
17
+ qbraid_cli/devices/__init__.py,sha256=hiScO-px6jCL5cJj5Hbty55EUfNejTO4bmqUZuS3aqc,181
18
+ qbraid_cli/devices/app.py,sha256=zxSxrEQn7irkJoME4S_CBnRqWeB8cqPaBsIMfpdYFk0,2530
19
+ qbraid_cli/devices/validation.py,sha256=YhShyUufgrKnx2XjXOXF-PqFJYklJT9CgeqIwKcNam4,809
20
+ qbraid_cli/envs/__init__.py,sha256=1-cMvrATsddYxcetPJWxq6bEOqJWMktGdhoZ4qm8euA,172
21
+ qbraid_cli/envs/activate.py,sha256=VpvVYSfQDlcmlNWJOgkLIQ2p8YXPPLG8Jbl5t8GHUDw,2140
22
+ qbraid_cli/envs/app.py,sha256=PD7U-zdQeoWPXPRpmKC3nwDVOfa69dk5GCIsE3mpla8,8411
23
+ qbraid_cli/envs/create.py,sha256=HxNciItDoGC5jqiruHm0oUfNSqtuDfzE-ro4ztGUh5Q,2185
24
+ qbraid_cli/envs/data_handling.py,sha256=Ibnp2yJoUDpivb_sNqi0suYgJZNat_LmM6Ya0Ovez5s,1288
25
+ qbraid_cli/jobs/__init__.py,sha256=qVLRHYIzP4XHpx_QWP_vCzd3LsCscCORaEx-Vcbx29U,172
26
+ qbraid_cli/jobs/app.py,sha256=kmg9mYla3Nd7EdjQlFu7IOvm7sejLNfPPA6Qeet-IfE,4898
27
+ qbraid_cli/jobs/toggle_braket.py,sha256=QVW69MkFyhMZWg_Cl48GgScC084aAG3EgYbyy-PGkqI,6756
28
+ qbraid_cli/jobs/validation.py,sha256=xNbjUggMhUs4wzkuRm4PuFPi_wrElYicUgYXLznHz3U,2983
29
+ qbraid_cli/kernels/__init__.py,sha256=jORS9vV17s5laQyq8gSVB18EPBImgEIbMZ1wKC094DA,181
30
+ qbraid_cli/kernels/app.py,sha256=eELxcuYV_d0wNR5t3IYznEcjqGmRM1j7GeHqVgcvDqs,3439
31
+ qbraid_cli/pip/__init__.py,sha256=tJtU0rxn-ODogNh5Y4pp_BgDQXMN-3JY1QGj0OZHwjQ,169
32
+ qbraid_cli/pip/app.py,sha256=Cer_Tteo_k26bTNiLUX2k-XhdSU3wKuj9ZLubbGv7r4,1439
33
+ qbraid_cli/pip/hooks.py,sha256=KuDHmntPXVK8tSb4MLk9VANhL-eINswhLd8_g_25WMY,2123
34
+ qbraid_cli-0.8.2.dist-info/LICENSE,sha256=P1gi-ofB8lmkRt_mxDoJpcgQq9Ckq9WhRAS1oYk-G1s,2506
35
+ qbraid_cli-0.8.2.dist-info/METADATA,sha256=QEXfGgrGrx2CzzgSARRfrIEv-wogBV0EgYXO-50gLTg,6732
36
+ qbraid_cli-0.8.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
37
+ qbraid_cli-0.8.2.dist-info/entry_points.txt,sha256=c5ZJ7NjbxhDqMpou9q5F03_b_KG34HzFDijIDmEIwgQ,47
38
+ qbraid_cli-0.8.2.dist-info/top_level.txt,sha256=LTYJgeYSCHo9Il8vZu0yIPuGdGyNaIw6iRy6BeoZo8o,11
39
+ qbraid_cli-0.8.2.dist-info/RECORD,,
@@ -1,33 +0,0 @@
1
- qbraid_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- qbraid_cli/_version.py,sha256=uh6qRUKYp5CUuk-ID8cyEoLnsVpY7iGTUwo68466d6k,413
3
- qbraid_cli/exceptions.py,sha256=KjlhYJhSHMVazaNiBjD_Ur06w4sekP8zRsFzBdyIpno,672
4
- qbraid_cli/handlers.py,sha256=glxTEwxax3zKgYl9qsZ2evZXgrWQrseJS_OGyHTMFeA,7040
5
- qbraid_cli/main.py,sha256=R26PkxijuuCzcW_PVREHb11oNlNN2rWDcRY7BmiDV0Q,2564
6
- qbraid_cli/admin/__init__.py,sha256=Suo_L1_yBodCvLM_fpw8gRIhD4mVVOXKObtxeoMaBVo,150
7
- qbraid_cli/admin/app.py,sha256=__6lo-iFsbfz-ayD1-AS8X1z_gYhCad1NK17hnrL7HY,1451
8
- qbraid_cli/admin/headers.py,sha256=E6mE3odZL57VfHHZxYtRUkqMKmrmT4zuUoINzI7eJF8,6435
9
- qbraid_cli/admin/validation.py,sha256=LkAVXlHtM0MhCa34MIWrfX59wGXMVlZmdVB4-AQ8fBk,1003
10
- qbraid_cli/configure/__init__.py,sha256=6GU7vR6JYRGcMsmdrpFbwLO5VSUmnLgwSbtmGWMQND4,158
11
- qbraid_cli/configure/actions.py,sha256=3rrWHaCAsogyx0Ll-lcjbSzldD4kPuz1z6VQiWebSWw,3203
12
- qbraid_cli/configure/app.py,sha256=1uRe2lkUA4TtYb5b4mbD4LH-cKCbsZGT3Wfk7fpNzX0,2414
13
- qbraid_cli/credits/__init__.py,sha256=t-3XAJFAXiu_jI4sgjaIOuNne_AoSYaSEsi-SSRkvPw,154
14
- qbraid_cli/credits/app.py,sha256=AY3qtveO50KeQ2XREiEVqUcTrESgRuoqt9pt2Z8t4Y0,866
15
- qbraid_cli/devices/__init__.py,sha256=_PU3eMQRV4DkPw-oCmfCPh8EbVmgG76ieEKuNsY9Xqc,154
16
- qbraid_cli/devices/app.py,sha256=zxSxrEQn7irkJoME4S_CBnRqWeB8cqPaBsIMfpdYFk0,2530
17
- qbraid_cli/devices/validation.py,sha256=YhShyUufgrKnx2XjXOXF-PqFJYklJT9CgeqIwKcNam4,809
18
- qbraid_cli/envs/__init__.py,sha256=YgIoMWxfGqzmwfypO5JHYuCOu6BfFwb9NHgQel1IJM8,148
19
- qbraid_cli/envs/activate.py,sha256=VpvVYSfQDlcmlNWJOgkLIQ2p8YXPPLG8Jbl5t8GHUDw,2140
20
- qbraid_cli/envs/app.py,sha256=t6bRwJGy-M3PAu870ZsttsM8tpSB0OFasgCJiV9nTSA,8620
21
- qbraid_cli/envs/create.py,sha256=uCRex_TcFYw26jUOU06Ta5I8Mq5pRqLVaOE6MxrrExs,4337
22
- qbraid_cli/envs/data_handling.py,sha256=mTVzsj6KleeeYDKGhgD-IesF9KQQMSszKFSEo8Wrv9w,4001
23
- qbraid_cli/jobs/__init__.py,sha256=bj9XmZ4JL8OtMMZbHIu-DPhpOMXGLSB-W1b0wO7wKro,148
24
- qbraid_cli/jobs/app.py,sha256=kmg9mYla3Nd7EdjQlFu7IOvm7sejLNfPPA6Qeet-IfE,4898
25
- qbraid_cli/jobs/toggle_braket.py,sha256=d5C_Di80jWMFlh-77eH8YY9pjMKWXK5abenUDtPlE_I,6662
26
- qbraid_cli/jobs/validation.py,sha256=xNbjUggMhUs4wzkuRm4PuFPi_wrElYicUgYXLznHz3U,2983
27
- qbraid_cli/kernels/__init__.py,sha256=VhpBota_v7OoiGxrPCqJU4XBVcolf81mbCYGSxXzVhc,154
28
- qbraid_cli/kernels/app.py,sha256=ZJWVdKzCDfzGnA1pqp01vDbE7fh8p84jC-y6DDgWlxc,3373
29
- qbraid_cli-0.8.1a0.dist-info/METADATA,sha256=KVpOOlMih6hukKoS6rXu6ybRv0oN9NWsU2zb5ilxJHE,7170
30
- qbraid_cli-0.8.1a0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
31
- qbraid_cli-0.8.1a0.dist-info/entry_points.txt,sha256=c5ZJ7NjbxhDqMpou9q5F03_b_KG34HzFDijIDmEIwgQ,47
32
- qbraid_cli-0.8.1a0.dist-info/top_level.txt,sha256=LTYJgeYSCHo9Il8vZu0yIPuGdGyNaIw6iRy6BeoZo8o,11
33
- qbraid_cli-0.8.1a0.dist-info/RECORD,,