Skip to content

Commit 90a9799

Browse files
authored
Merge pull request #7 from forcedotcom/sdkVersion-config
Add sdkVersion to config.json as part of deploy
2 parents 9a34c35 + c521ff6 commit 90a9799

3 files changed

Lines changed: 58 additions & 22 deletions

File tree

src/datacustomcode/deploy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
from datacustomcode.cmd import cmd_output
3838
from datacustomcode.scan import scan_file
39+
from datacustomcode.version import get_version
3940

4041
if TYPE_CHECKING:
4142
from datacustomcode.credentials import Credentials
@@ -284,6 +285,7 @@ class DataTransformConfig(BaseModel):
284285
"entryPoint": "entrypoint.py",
285286
"dataspace": "default",
286287
"permissions": {"read": {"dlo": ""}, "write": {"dlo": ""}},
288+
"sdkVersion": get_version(),
287289
}
288290

289291

src/datacustomcode/version.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
"""Version information for the Data Cloud Custom Code SDK."""
16+
17+
import importlib.metadata
18+
19+
20+
def get_version() -> str:
21+
"""Get the current version of the SDK.
22+
23+
Returns:
24+
str: The version string from package metadata.
25+
"""
26+
# First try to get version from installed package metadata
27+
return importlib.metadata.version("salesforce-data-customcode")

tests/test_deploy.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010
import requests
1111

1212
from datacustomcode.credentials import Credentials
13-
from datacustomcode.deploy import (
14-
AccessTokenResponse,
15-
CreateDeploymentResponse,
16-
DataTransformConfig,
17-
DeploymentsResponse,
18-
TransformationJobMetadata,
19-
_make_api_call,
20-
_retrieve_access_token,
21-
create_data_transform,
22-
create_data_transform_config,
23-
create_deployment,
24-
deploy_full,
25-
get_data_transform_config,
26-
get_deployments,
27-
run_data_transform,
28-
wait_for_deployment,
29-
zip_and_upload_directory,
30-
)
13+
14+
# Patch get_version before importing deploy module
15+
with patch("datacustomcode.version.get_version", return_value="1.2.3"):
16+
from datacustomcode.deploy import (
17+
AccessTokenResponse,
18+
CreateDeploymentResponse,
19+
DataTransformConfig,
20+
DeploymentsResponse,
21+
TransformationJobMetadata,
22+
_make_api_call,
23+
_retrieve_access_token,
24+
create_data_transform,
25+
create_data_transform_config,
26+
create_deployment,
27+
deploy_full,
28+
get_data_transform_config,
29+
get_deployments,
30+
run_data_transform,
31+
wait_for_deployment,
32+
zip_and_upload_directory,
33+
)
3134

3235

3336
class TestMakeApiCall:
@@ -248,10 +251,14 @@ def test_create_data_transform_config(
248251
mock_get_config.assert_called_once_with("/test/dir")
249252
mock_file.assert_called_once_with("/test/dir/config.json", "w")
250253
mock_json_dump.assert_called_once()
251-
# Check permissions in config
252-
config = mock_json_dump.call_args[0][0]
253-
assert config["permissions"]["read"]["dlo"] == "input_dlo"
254-
assert config["permissions"]["write"]["dlo"] == "output_dlo"
254+
255+
# Verify the config contains all required fields including sdkVersion
256+
config_data = mock_json_dump.call_args[0][0]
257+
assert config_data["entryPoint"] == "entrypoint.py"
258+
assert config_data["dataspace"] == "default"
259+
assert config_data["permissions"]["read"]["dlo"] == "input_dlo"
260+
assert config_data["permissions"]["write"]["dlo"] == "output_dlo"
261+
assert config_data["sdkVersion"] == "1.2.3"
255262

256263

257264
class TestCreateDataTransform:

0 commit comments

Comments
 (0)