beamlit 0.0.52__py3-none-any.whl → 0.0.53rc99__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.
Files changed (36) hide show
  1. beamlit/agents/chain.py +50 -3
  2. beamlit/agents/chat.py +92 -7
  3. beamlit/agents/decorator.py +43 -9
  4. beamlit/agents/thread.py +14 -0
  5. beamlit/agents/voice/openai.py +5 -7
  6. beamlit/authentication/apikey.py +30 -0
  7. beamlit/authentication/authentication.py +64 -0
  8. beamlit/authentication/clientcredentials.py +51 -1
  9. beamlit/authentication/credentials.py +117 -0
  10. beamlit/authentication/device_mode.py +78 -0
  11. beamlit/common/error.py +18 -0
  12. beamlit/common/instrumentation.py +38 -12
  13. beamlit/common/logger.py +29 -0
  14. beamlit/common/secrets.py +28 -0
  15. beamlit/common/settings.py +39 -1
  16. beamlit/common/slugify.py +16 -0
  17. beamlit/common/utils.py +19 -0
  18. beamlit/deploy/__init__.py +5 -0
  19. beamlit/deploy/deploy.py +30 -14
  20. beamlit/deploy/format.py +39 -8
  21. beamlit/deploy/parser.py +16 -0
  22. beamlit/functions/__init__.py +2 -1
  23. beamlit/functions/common.py +57 -8
  24. beamlit/functions/decorator.py +21 -2
  25. beamlit/functions/mcp/mcp.py +15 -2
  26. beamlit/functions/remote/remote.py +29 -4
  27. beamlit/run.py +45 -0
  28. beamlit/serve/app.py +23 -5
  29. beamlit/serve/middlewares/__init__.py +6 -0
  30. beamlit/serve/middlewares/accesslog.py +16 -0
  31. beamlit/serve/middlewares/processtime.py +16 -0
  32. {beamlit-0.0.52.dist-info → beamlit-0.0.53rc99.dist-info}/METADATA +1 -1
  33. {beamlit-0.0.52.dist-info → beamlit-0.0.53rc99.dist-info}/RECORD +36 -35
  34. beamlit-0.0.53rc99.dist-info/entry_points.txt +2 -0
  35. {beamlit-0.0.52.dist-info → beamlit-0.0.53rc99.dist-info}/WHEEL +0 -0
  36. {beamlit-0.0.52.dist-info → beamlit-0.0.53rc99.dist-info}/licenses/LICENSE +0 -0
@@ -1,3 +1,9 @@
1
+ """
2
+ This module provides classes and functions for managing credentials and workspace configurations.
3
+ It includes functionalities to load, save, and manage authentication credentials, as well as to handle
4
+ workspace contexts and configurations.
5
+ """
6
+
1
7
  from dataclasses import dataclass
2
8
  from logging import getLogger
3
9
  from pathlib import Path
@@ -12,6 +18,17 @@ logger = getLogger(__name__)
12
18
 
13
19
  @dataclass
14
20
  class Credentials:
21
+ """
22
+ A dataclass representing user credentials for authentication.
23
+
24
+ Attributes:
25
+ apiKey (str): The API key.
26
+ access_token (str): The access token.
27
+ refresh_token (str): The refresh token.
28
+ expires_in (int): Token expiration time in seconds.
29
+ device_code (str): The device code for device authentication.
30
+ client_credentials (str): The client credentials for authentication.
31
+ """
15
32
  apiKey: str = ""
16
33
  access_token: str = ""
17
34
  refresh_token: str = ""
@@ -22,28 +39,58 @@ class Credentials:
22
39
 
23
40
  @dataclass
24
41
  class WorkspaceConfig:
42
+ """
43
+ A dataclass representing the configuration for a workspace.
44
+
45
+ Attributes:
46
+ name (str): The name of the workspace.
47
+ credentials (Credentials): The credentials associated with the workspace.
48
+ """
25
49
  name: str
26
50
  credentials: Credentials
27
51
 
28
52
 
29
53
  @dataclass
30
54
  class ContextConfig:
55
+ """
56
+ A dataclass representing the current context configuration.
57
+
58
+ Attributes:
59
+ workspace (str): The name of the current workspace.
60
+ environment (str): The current environment (e.g., development, production).
61
+ """
31
62
  workspace: str = ""
32
63
  environment: str = ""
33
64
 
34
65
 
35
66
  @dataclass
36
67
  class Config:
68
+ """
69
+ A dataclass representing the overall configuration, including workspaces and context.
70
+
71
+ Attributes:
72
+ workspaces (List[WorkspaceConfig]): A list of workspace configurations.
73
+ context (ContextConfig): The current context configuration.
74
+ """
37
75
  workspaces: List[WorkspaceConfig] = None
38
76
  context: ContextConfig = None
39
77
 
40
78
  def __post_init__(self):
79
+ """
80
+ Post-initialization to ensure workspaces and context are initialized.
81
+ """
41
82
  if self.workspaces is None:
42
83
  self.workspaces = []
43
84
  if self.context is None:
44
85
  self.context = ContextConfig()
45
86
 
46
87
  def to_json(self) -> dict:
88
+ """
89
+ Converts the Config dataclass to a JSON-compatible dictionary.
90
+
91
+ Returns:
92
+ dict: The JSON representation of the configuration.
93
+ """
47
94
  return {
48
95
  "workspaces": [
49
96
  {
@@ -67,6 +114,12 @@ class Config:
67
114
 
68
115
 
69
116
  def load_config() -> Config:
117
+ """
118
+ Loads the configuration from the user's home directory.
119
+
120
+ Returns:
121
+ Config: The loaded configuration.
122
+ """
70
123
  config = Config()
71
124
  home_dir = Path.home()
72
125
  if home_dir:
@@ -90,6 +143,15 @@ def load_config() -> Config:
90
143
 
91
144
 
92
145
  def save_config(config: Config):
146
+ """
147
+ Saves the provided configuration to the user's home directory.
148
+
149
+ Parameters:
150
+ config (Config): The configuration to save.
151
+
152
+ Raises:
153
+ RuntimeError: If the home directory cannot be determined.
154
+ """
93
155
  home_dir = Path.home()
94
156
  if not home_dir:
95
157
  raise RuntimeError("Could not determine home directory")
@@ -103,16 +165,35 @@ def save_config(config: Config):
103
165
 
104
166
 
105
167
  def list_workspaces() -> List[str]:
168
+ """
169
+ Lists all available workspace names from the configuration.
170
+
171
+ Returns:
172
+ List[str]: A list of workspace names.
173
+ """
106
174
  config = load_config()
107
175
  return [workspace.name for workspace in config.workspaces]
108
176
 
109
177
 
110
178
  def current_context() -> ContextConfig:
179
+ """
180
+ Retrieves the current context configuration.
181
+
182
+ Returns:
183
+ ContextConfig: The current context configuration.
184
+ """
111
185
  config = load_config()
112
186
  return config.context
113
187
 
114
188
 
115
189
  def set_current_workspace(workspace_name: str, environment: str):
190
+ """
191
+ Sets the current workspace and environment in the configuration.
192
+
193
+ Parameters:
194
+ workspace_name (str): The name of the workspace to set as current.
195
+ environment (str): The environment to set for the workspace.
196
+ """
116
197
  config = load_config()
117
198
  config.context.workspace = workspace_name
118
199
  config.context.environment = environment
@@ -120,6 +201,15 @@ def set_current_workspace(workspace_name: str, environment: str):
120
201
 
121
202
 
122
203
  def load_credentials(workspace_name: str) -> Credentials:
204
+ """
205
+ Loads credentials for the specified workspace.
206
+
207
+ Parameters:
208
+ workspace_name (str): The name of the workspace whose credentials are to be loaded.
209
+
210
+ Returns:
211
+ Credentials: The credentials associated with the workspace. Returns empty credentials if not found.
212
+ """
123
213
  config = load_config()
124
214
  for workspace in config.workspaces:
125
215
  if workspace.name == workspace_name:
@@ -128,6 +218,15 @@ def load_credentials(workspace_name: str) -> Credentials:
128
218
 
129
219
 
130
220
  def load_credentials_from_settings(settings: Settings) -> Credentials:
221
+ """
222
+ Loads credentials from the provided settings.
223
+
224
+ Parameters:
225
+ settings (Settings): The settings containing authentication information.
226
+
227
+ Returns:
228
+ Credentials: The loaded credentials from settings.
229
+ """
131
230
  return Credentials(
132
231
  apiKey=settings.authentication.apiKey,
133
232
  client_credentials=settings.authentication.client.credentials,
@@ -135,6 +234,11 @@ def load_credentials_from_settings(settings: Settings) -> Credentials:
135
234
 
136
235
 
137
236
  def create_home_dir_if_missing():
237
+ """
238
+ Creates the Beamlit home directory if it does not exist.
239
+
240
+ Logs a warning if credentials already exist or an error if directory creation fails.
241
+ """
138
242
  home_dir = Path.home()
139
243
  if not home_dir:
140
244
  logger.error("Error getting home directory")
@@ -153,6 +257,13 @@ def create_home_dir_if_missing():
153
257
 
154
258
 
155
259
  def save_credentials(workspace_name: str, credentials: Credentials):
260
+ """
261
+ Saves the provided credentials for the specified workspace.
262
+
263
+ Parameters:
264
+ workspace_name (str): The name of the workspace.
265
+ credentials (Credentials): The credentials to save.
266
+ """
156
267
  create_home_dir_if_missing()
157
268
  if not credentials.access_token and not credentials.apiKey:
158
269
  logger.info("No credentials to save, error")
@@ -174,6 +285,12 @@ def save_credentials(workspace_name: str, credentials: Credentials):
174
285
 
175
286
 
176
287
  def clear_credentials(workspace_name: str):
288
+ """
289
+ Clears the credentials for the specified workspace.
290
+
291
+ Parameters:
292
+ workspace_name (str): The name of the workspace whose credentials are to be cleared.
293
+ """
177
294
  config = load_config()
178
295
  config.workspaces = [ws for ws in config.workspaces if ws.name != workspace_name]
179
296
 
@@ -1,3 +1,9 @@
1
+ """
2
+ This module provides classes for handling device-based authentication,
3
+ including device login processes and bearer token management. It facilitates token refreshing
4
+ and authentication flows using device codes and bearer tokens.
5
+ """
6
+
1
7
  import base64
2
8
  import json
3
9
  from dataclasses import dataclass
@@ -9,12 +15,31 @@ from httpx import Auth, Request, Response, post
9
15
 
10
16
  @dataclass
11
17
  class DeviceLogin:
18
+ """
19
+ A dataclass representing a device login request.
20
+
21
+ Attributes:
22
+ client_id (str): The client ID for the device.
23
+ scope (str): The scope of the authentication.
24
+ """
12
25
  client_id: str
13
26
  scope: str
14
27
 
15
28
 
16
29
  @dataclass
17
30
  class DeviceLoginResponse:
31
+ """
32
+ A dataclass representing the response from a device login request.
33
+
34
+ Attributes:
35
+ client_id (str): The client ID associated with the device login.
36
+ device_code (str): The device code for authentication.
37
+ user_code (str): The user code for completing authentication.
38
+ expires_in (int): Time in seconds until the device code expires.
39
+ interval (int): Polling interval in seconds.
40
+ verification_uri (str): URI for user to verify device login.
41
+ verification_uri_complete (str): Complete URI including the user code for verification.
42
+ """
18
43
  client_id: str
19
44
  device_code: str
20
45
  user_code: str
@@ -26,6 +51,14 @@ class DeviceLoginResponse:
26
51
 
27
52
  @dataclass
28
53
  class DeviceLoginFinalizeRequest:
54
+ """
55
+ A dataclass representing a device login finalize request.
56
+
57
+ Attributes:
58
+ grant_type (str): The type of grant being requested.
59
+ client_id (str): The client ID for finalizing the device login.
60
+ device_code (str): The device code to finalize login.
61
+ """
29
62
  grant_type: str
30
63
  client_id: str
31
64
  device_code: str
@@ -40,12 +73,33 @@ class DeviceLoginFinalizeResponse:
40
73
 
41
74
 
42
75
  class BearerToken(Auth):
76
+ """
77
+ A provider that authenticates requests using a Bearer token.
78
+ """
79
+
43
80
  def __init__(self, credentials, workspace_name: str, base_url: str):
81
+ """
82
+ Initializes the BearerToken provider with the given credentials, workspace name, and base URL.
83
+
84
+ Parameters:
85
+ credentials: Credentials containing the Bearer token and refresh token.
86
+ workspace_name (str): The name of the workspace.
87
+ base_url (str): The base URL for authentication.
88
+ """
44
89
  self.credentials = credentials
45
90
  self.workspace_name = workspace_name
46
91
  self.base_url = base_url
47
92
 
48
93
  def get_headers(self) -> Dict[str, str]:
94
+ """
95
+ Retrieves the authentication headers containing the Bearer token and workspace information.
96
+
97
+ Returns:
98
+ Dict[str, str]: A dictionary of headers with Bearer token and workspace.
99
+
100
+ Raises:
101
+ Exception: If token refresh fails.
102
+ """
49
103
  err = self.refresh_if_needed()
50
104
  if err:
51
105
  raise err
@@ -55,6 +109,12 @@ class BearerToken(Auth):
55
109
  }
56
110
 
57
111
  def refresh_if_needed(self) -> Optional[Exception]:
112
+ """
113
+ Checks if the Bearer token needs to be refreshed and performs the refresh if necessary.
114
+
115
+ Returns:
116
+ Optional[Exception]: An exception if refreshing fails, otherwise None.
117
+ """
58
118
  # Need to refresh token if expires in less than 10 minutes
59
119
  parts = self.credentials.access_token.split(".")
60
120
  if len(parts) != 3:
@@ -74,6 +134,18 @@ class BearerToken(Auth):
74
134
  return None
75
135
 
76
136
  def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
137
+ """
138
+ Processes the authentication flow by ensuring the Bearer token is valid and adding necessary headers.
139
+
140
+ Parameters:
141
+ request (Request): The HTTP request to authenticate.
142
+
143
+ Yields:
144
+ Request: The authenticated request.
145
+
146
+ Raises:
147
+ Exception: If token refresh fails.
148
+ """
77
149
  err = self.refresh_if_needed()
78
150
  if err:
79
151
  return err
@@ -83,6 +155,12 @@ class BearerToken(Auth):
83
155
  yield request
84
156
 
85
157
  def do_refresh(self) -> Optional[Exception]:
158
+ """
159
+ Performs the token refresh using the refresh token.
160
+
161
+ Returns:
162
+ Optional[Exception]: An exception if refreshing fails, otherwise None.
163
+ """
86
164
  if not self.credentials.refresh_token:
87
165
  return Exception("No refresh token to refresh")
88
166
 
beamlit/common/error.py CHANGED
@@ -1,9 +1,27 @@
1
+ """
2
+ This module defines custom exception classes used for handling HTTP-related errors within Beamlit.
3
+ """
4
+
1
5
  class HTTPError(Exception):
6
+ """
7
+ A custom exception class for HTTP errors.
8
+
9
+ Attributes:
10
+ status_code (int): The HTTP status code associated with the error.
11
+ message (str): A descriptive message explaining the error.
12
+ """
13
+
2
14
  def __init__(self, status_code: int, message: str):
3
15
  self.status_code = status_code
4
16
  self.message = message
5
17
  super().__init__(self.message)
6
18
 
7
19
  def __str__(self):
20
+ """
21
+ Returns a string representation of the HTTPError.
22
+
23
+ Returns:
24
+ str: A string in the format "status_code message".
25
+ """
8
26
  return f"{self.status_code} {self.message}"
9
27
 
@@ -1,3 +1,8 @@
1
+ """
2
+ This module provides utilities for setting up and managing OpenTelemetry instrumentation within Beamlit.
3
+ It includes classes and functions for configuring tracers, meters, loggers, and integrating with FastAPI applications.
4
+ """
5
+
1
6
  import importlib
2
7
  import logging
3
8
  from typing import Any, Optional, Type
@@ -5,18 +10,10 @@ from typing import Any, Optional, Type
5
10
  from fastapi import FastAPI
6
11
  from opentelemetry import _logs, metrics, trace
7
12
  from opentelemetry._logs import set_logger_provider
8
- from opentelemetry.exporter.otlp.proto.http._log_exporter import (
9
- OTLPLogExporter,
10
- )
11
- from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
12
- OTLPMetricExporter,
13
- )
14
- from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
15
- OTLPSpanExporter,
16
- )
17
- from opentelemetry.instrumentation.fastapi import ( # type: ignore
18
- FastAPIInstrumentor,
19
- )
13
+ from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
14
+ from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
15
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
16
+ from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor # type: ignore
20
17
  from opentelemetry.metrics import NoOpMeterProvider
21
18
  from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
22
19
  from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
@@ -40,6 +37,12 @@ log = logging.getLogger(__name__)
40
37
 
41
38
 
42
39
  def auth_headers() -> Dict[str, str]:
40
+ """
41
+ Retrieves authentication headers based on the current settings.
42
+
43
+ Returns:
44
+ Dict[str, str]: A dictionary containing authentication headers.
45
+ """
43
46
  settings = get_settings()
44
47
  headers = get_authentication_headers(settings)
45
48
  return {
@@ -49,6 +52,15 @@ def auth_headers() -> Dict[str, str]:
49
52
 
50
53
 
51
54
  def get_logger() -> LoggerProvider:
55
+ """
56
+ Retrieves the current logger provider.
57
+
58
+ Returns:
59
+ LoggerProvider: The active logger provider.
60
+
61
+ Raises:
62
+ Exception: If the logger has not been initialized.
63
+ """
52
64
  if logger is None:
53
65
  raise Exception("Logger is not initialized")
54
66
  return logger
@@ -202,6 +214,15 @@ def _is_package_installed(package_name: str) -> bool:
202
214
 
203
215
 
204
216
  def instrument_app(app: FastAPI):
217
+ """
218
+ Instruments the given FastAPI application with OpenTelemetry.
219
+
220
+ This includes setting up tracer and meter providers, configuring exporters, and instrumenting
221
+ various modules based on available packages.
222
+
223
+ Parameters:
224
+ app (FastAPI): The FastAPI application to instrument.
225
+ """
205
226
  global tracer
206
227
  global meter
207
228
  settings = get_settings()
@@ -281,6 +302,11 @@ def instrument_app(app: FastAPI):
281
302
 
282
303
 
283
304
  def shutdown_instrumentation():
305
+ """
306
+ Shuts down the OpenTelemetry instrumentation providers gracefully.
307
+
308
+ This ensures that all spans and metrics are properly exported before the application exits.
309
+ """
284
310
  if tracer is not None:
285
311
  trace_provider = trace.get_tracer_provider()
286
312
  if isinstance(trace_provider, TracerProvider):
beamlit/common/logger.py CHANGED
@@ -1,7 +1,18 @@
1
+ """
2
+ This module provides a custom colored formatter for logging and an initialization function
3
+ to set up logging configurations for Beamlit applications.
4
+ """
5
+
1
6
  import logging
2
7
 
3
8
 
4
9
  class ColoredFormatter(logging.Formatter):
10
+ """
11
+ A custom logging formatter that adds ANSI color codes to log levels for enhanced readability.
12
+
13
+ Attributes:
14
+ COLORS (dict): A mapping of log level names to their corresponding ANSI color codes.
15
+ """
5
16
  COLORS = {
6
17
  "DEBUG": "\033[1;36m", # Cyan
7
18
  "INFO": "\033[1;32m", # Green
@@ -11,6 +22,15 @@ class ColoredFormatter(logging.Formatter):
11
22
  }
12
23
 
13
24
  def format(self, record):
25
+ """
26
+ Formats the log record by adding color codes based on the log level.
27
+
28
+ Parameters:
29
+ record (LogRecord): The log record to format.
30
+
31
+ Returns:
32
+ str: The formatted log message with appropriate color codes.
33
+ """
14
34
  n_spaces = len("CRITICAL") - len(record.levelname)
15
35
  tab = " " * n_spaces
16
36
  color = self.COLORS.get(record.levelname, "\033[0m")
@@ -19,6 +39,15 @@ class ColoredFormatter(logging.Formatter):
19
39
 
20
40
 
21
41
  def init(log_level: str):
42
+ """
43
+ Initializes the logging configuration for Beamlit.
44
+
45
+ This function clears existing handlers for specific loggers, sets up a colored formatter,
46
+ and configures the root logger with the specified log level.
47
+
48
+ Parameters:
49
+ log_level (str): The logging level to set (e.g., "DEBUG", "INFO").
50
+ """
22
51
  logging.getLogger("uvicorn.access").handlers.clear()
23
52
  logging.getLogger("uvicorn.access").propagate = False
24
53
  logging.getLogger("uvicorn.error").handlers.clear()
beamlit/common/secrets.py CHANGED
@@ -2,10 +2,38 @@ import os
2
2
 
3
3
 
4
4
  class Secret:
5
+ """
6
+ A utility class for managing environment secrets.
7
+
8
+ Provides static methods to retrieve and set secret values, supporting both standard and
9
+ prefixed environment variable naming conventions.
10
+ """
11
+
5
12
  @staticmethod
6
13
  def get(name: str):
14
+ """
15
+ Retrieves the value of a secret environment variable.
16
+
17
+ This method first attempts to get the value using the standard name. If not found,
18
+ it tries with a "bl_" prefix.
19
+
20
+ Parameters:
21
+ name (str): The name of the environment variable to retrieve.
22
+
23
+ Returns:
24
+ str: The value of the environment variable if found, otherwise an empty string.
25
+ """
7
26
  return os.getenv(name, os.getenv(f"bl_{name}"))
8
27
 
9
28
  @staticmethod
10
29
  def set(name: str, value: str):
30
+ """
31
+ Sets the value of a secret environment variable.
32
+
33
+ This method sets the value using the standard name, allowing for consistent secret management.
34
+
35
+ Parameters:
36
+ name (str): The name of the environment variable to set.
37
+ value (str): The value to assign to the environment variable.
38
+ """
11
39
  os.environ[name] = value
@@ -1,3 +1,9 @@
1
+ """
2
+ This module defines the configuration management system for Beamlit applications using Pydantic.
3
+ It includes dataclasses for various configuration aspects, such as agents, authentication, and server settings.
4
+ The module provides functions to initialize settings, load configurations from YAML files, and customize settings sources.
5
+ """
6
+
1
7
  import os
2
8
  from typing import Tuple, Type, Union
3
9
 
@@ -18,6 +24,18 @@ global SETTINGS
18
24
  SETTINGS = None
19
25
 
20
26
  class SettingsAgent(BaseSettings):
27
+ """
28
+ Configuration settings for agents within Beamlit.
29
+
30
+ Attributes:
31
+ agent (Union[None, CompiledGraph]): The compiled agent graph.
32
+ chain (Union[None, list[Agent]]): A list of agent chains.
33
+ model (Union[None, Model]): The model configuration.
34
+ functions (Union[None, list[Function]]): A list of functions available to agents.
35
+ functions_directory (str): The directory path where agent functions are located.
36
+ chat_model (Union[None, BaseChatModel]): The chat model used by agents.
37
+ module (str): The module path to the main application.
38
+ """
21
39
  agent: Union[None, CompiledGraph] = None
22
40
  chain: Union[None, list[Agent]] = None
23
41
  model: Union[None, Model] = None
@@ -28,6 +46,12 @@ class SettingsAgent(BaseSettings):
28
46
 
29
47
 
30
48
  class SettingsAuthenticationClient(BaseSettings):
49
+ """
50
+ Configuration settings for authentication clients.
51
+
52
+ Attributes:
53
+ credentials (Union[None, str]): Client credentials for authentication.
54
+ """
31
55
  credentials: Union[None, str] = None
32
56
 
33
57
 
@@ -92,10 +116,24 @@ class Settings(BaseSettings):
92
116
  )
93
117
 
94
118
  def get_settings() -> Settings:
119
+ """
120
+ Retrieves the current settings instance.
121
+
122
+ Returns:
123
+ Settings: The current settings configuration.
124
+ """
95
125
  return SETTINGS
96
126
 
97
127
  def init() -> Settings:
98
- """Parse the beamlit.yaml file to get configurations."""
128
+ """
129
+ Initializes the settings by parsing the `beamlit.yaml` file and setting up logging.
130
+
131
+ This function reads workspace and environment configurations from the current context,
132
+ initializes the global SETTINGS variable, and configures the logger based on the log level.
133
+
134
+ Returns:
135
+ Settings: The initialized settings configuration.
136
+ """
99
137
  from beamlit.authentication.credentials import current_context
100
138
 
101
139
  global SETTINGS
beamlit/common/slugify.py CHANGED
@@ -1,2 +1,18 @@
1
+ """
2
+ This module provides utility functions for string manipulation, including slugification.
3
+ The `slugify` function transforms a given string into a URL-friendly slug by replacing spaces and underscores with hyphens and converting the string to lowercase.
4
+ """
5
+
1
6
  def slugify(name: str) -> str:
7
+ """
8
+ Converts a given string into a URL-friendly slug.
9
+
10
+ This function transforms the input string by converting it to lowercase and replacing spaces and underscores with hyphens.
11
+
12
+ Parameters:
13
+ name (str): The string to slugify.
14
+
15
+ Returns:
16
+ str: The slugified version of the input string.
17
+ """
2
18
  return name.lower().replace(" ", "-").replace("_", "-")
beamlit/common/utils.py CHANGED
@@ -1,9 +1,28 @@
1
+ """
2
+ This module provides utility functions for file operations within Beamlit.
3
+ It includes functions to copy folders and synchronize directory contents efficiently.
4
+ """
5
+
1
6
  import filecmp
2
7
  import os
3
8
  import shutil
4
9
 
5
10
 
6
11
  def copy_folder(source_folder: str, destination_folder: str):
12
+ """
13
+ Copies the contents of the source folder to the destination folder.
14
+
15
+ This function recursively copies all files and subdirectories from the `source_folder` to the `destination_folder`.
16
+ It ensures that existing files are only overwritten if they differ from the source.
17
+
18
+ Parameters:
19
+ source_folder (str): The path to the source directory.
20
+ destination_folder (str): The path to the destination directory.
21
+
22
+ Raises:
23
+ FileNotFoundError: If the source folder does not exist.
24
+ PermissionError: If the program lacks permissions to read from the source or write to the destination.
25
+ """
7
26
  for file in os.listdir(source_folder):
8
27
  if os.path.isdir(f"{source_folder}/{file}"):
9
28
  if not os.path.exists(f"{destination_folder}/{file}"):
@@ -1,3 +1,8 @@
1
+ """
2
+ This module provides functions and classes to handle deployment processes within Beamlit.
3
+ It includes utilities to generate deployment configurations and manage deployment-related operations.
4
+ """
5
+
1
6
  from .deploy import generate_beamlit_deployment
2
7
 
3
8
  __all__ = ["generate_beamlit_deployment"]