Skip to content

Commit 0e2a2f1

Browse files
committed
finally working
1 parent 9b64711 commit 0e2a2f1

5 files changed

Lines changed: 62 additions & 13 deletions

File tree

src/datacustomcode/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from datacustomcode.credentials import AuthType, Credentials
1818
from datacustomcode.io.reader.query_api import QueryAPIDataCloudReader
1919
from datacustomcode.io.writer.print import PrintDataCloudWriter
20-
from datacustomcode.proxy.client.client import LocalProxyClientProvider
20+
from datacustomcode.proxy.client.LocalProxyClientProvider import (
21+
LocalProxyClientProvider,
22+
)
2123

2224
__all__ = [
2325
"AuthType",

src/datacustomcode/client.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ def __new__(
120120
spark_provider: Optional["BaseSparkSessionProvider"] = None,
121121
code_type: str = "script",
122122
) -> Client:
123-
print(f"Chuy client new client: {code_type}")
124123
if "function" in code_type:
125-
print("Chuy111 client new function client")
126124
return cls._new_function_client()
127125

128126
if cls._instance is None:
@@ -180,11 +178,19 @@ def __new__(
180178

181179
@classmethod
182180
def _new_function_client(cls) -> Client:
183-
print(f"Chuy config: {config}")
184-
185-
importlib.import_module(
186-
"datacustomcoderemote.proxy.client.client.ProxyClientProvider"
187-
)
181+
for dependency in config.dependencies:
182+
try:
183+
importlib.import_module(dependency)
184+
except ModuleNotFoundError as exc:
185+
try:
186+
if "." in dependency:
187+
module_name, object_name = dependency.rsplit(".", 1)
188+
module = importlib.import_module(module_name)
189+
getattr(module, object_name)
190+
else:
191+
raise exc
192+
except AttributeError as inner_exc:
193+
raise inner_exc from exc
188194

189195
cls._instance = super().__new__(cls)
190196
cls._instance._proxy = (

src/datacustomcode/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class ClientConfig(BaseModel):
133133
spark_provider_config: Union[
134134
SparkProviderConfig[BaseSparkSessionProvider], None
135135
] = None
136+
dependencies: list[str] = Field(
137+
default_factory=list,
138+
description="""
139+
Extra modules to import before running the entrypoint
140+
(merged with --dependencies from CLI).
141+
""",
142+
)
136143

137144
def update(self, other: ClientConfig) -> ClientConfig:
138145
"""Merge this ClientConfig with another, respecting force flags.
@@ -161,6 +168,7 @@ def merge(
161168
self.spark_provider_config = merge(
162169
self.spark_provider_config, other.spark_provider_config
163170
)
171+
self.dependencies = list(dict.fromkeys(self.dependencies + other.dependencies))
164172
return self
165173

166174
def load(self, config_path: str) -> ClientConfig:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2025, Salesforce, Inc.
2+
# SPDX-License-Identifier: Apache-2
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
from __future__ import annotations
16+
17+
from datacustomcode.proxy.client.base import BaseProxyClient
18+
19+
20+
class LocalProxyClientProvider(BaseProxyClient):
21+
"""Default proxy client provider."""
22+
23+
CONFIG_NAME = "LocalProxyClientProvider"
24+
25+
def __init__(self, credentials_profile: str = "default", **kwargs: object) -> None:
26+
super().__init__()
27+
self.credentials_profile = credentials_profile
28+
29+
def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str:
30+
return f"Hello, thanks for using {llmModelId}. So many tokens: {maxTokens}"

src/datacustomcode/run.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def run_entrypoint(
5252
"""
5353
add_py_folder(entrypoint)
5454

55+
# Load config file (so we can merge config.dependencies with CLI deps)
56+
if config_file:
57+
config.load(config_file)
58+
59+
# Merge dependencies from config and CLI (config first, then CLI, deduped)
60+
merged_dependencies = list(dict.fromkeys(config.dependencies + list(dependencies)))
61+
5562
# Read dataspace from config.json (required)
5663
entrypoint_dir = os.path.dirname(entrypoint)
5764
config_json_path = os.path.join(entrypoint_dir, "config.json")
@@ -81,18 +88,14 @@ def run_entrypoint(
8188
f"Please ensure config.json contains a 'dataspace' field."
8289
)
8390

84-
# Load config file first
85-
if config_file:
86-
config.load(config_file)
87-
8891
# Add dataspace to reader and writer config options
8992
_set_config_option(config.reader_config, "dataspace", dataspace)
9093
_set_config_option(config.writer_config, "dataspace", dataspace)
9194

9295
if profile != "default":
9396
_set_config_option(config.reader_config, "credentials_profile", profile)
9497
_set_config_option(config.writer_config, "credentials_profile", profile)
95-
for dependency in dependencies:
98+
for dependency in merged_dependencies:
9699
try:
97100
importlib.import_module(dependency)
98101
except ModuleNotFoundError as exc:

0 commit comments

Comments
 (0)