Skip to content

Commit 3d79f27

Browse files
committed
Remove extra pip install, and create archives folder if needed
1 parent 108a0f1 commit 3d79f27

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/datacustomcode/deploy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ def prepare_dependency_archive(directory: str) -> None:
164164
cmd = (
165165
f"{PLATFORM_ENV_VAR} docker run --rm "
166166
f"-v {temp_dir}:/workspace "
167-
f"{DOCKER_IMAGE_NAME} "
168-
f'/bin/bash -c "./build_native_dependencies.sh"'
167+
f"{DOCKER_IMAGE_NAME}"
169168
)
170169
cmd_output(cmd)
171170
archives_temp_path = os.path.join(temp_dir, DEPENDENCIES_ARCHIVE_FULL_NAME)
171+
os.makedirs(os.path.dirname(DEPENDENCIES_ARCHIVE_PATH), exist_ok=True)
172172
shutil.copy(archives_temp_path, DEPENDENCIES_ARCHIVE_PATH)
173173

174174
logger.info(f"Dependencies archived to {DEPENDENCIES_ARCHIVE_PATH}")

src/datacustomcode/templates/build_native_dependencies.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
# Description: build native dependencies
44

5-
pip3.11 install venv-pack
6-
75
python3.11 -m venv --copies .venv
86
source .venv/bin/activate
97
pip install -r requirements.txt

tests/test_deploy.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class TestPrepareDependencyArchive:
4646
EXPECTED_DOCKER_RUN_CMD = (
4747
"DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm "
4848
"-v /tmp/test_dir:/workspace "
49-
"datacloud-custom-code-dependency-builder "
50-
'/bin/bash -c "./build_native_dependencies.sh"'
49+
"datacloud-custom-code-dependency-builder"
5150
)
5251

5352
@patch("datacustomcode.deploy.cmd_output")
5453
@patch("datacustomcode.deploy.shutil.copy")
5554
@patch("datacustomcode.deploy.tempfile.TemporaryDirectory")
5655
@patch("datacustomcode.deploy.os.path.join")
56+
@patch("datacustomcode.deploy.os.makedirs")
5757
def test_prepare_dependency_archive_image_exists(
58-
self, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
58+
self, mock_makedirs, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
5959
):
6060
"""Test prepare_dependency_archive when Docker image already exists."""
6161
# Mock the temporary directory context manager
@@ -85,15 +85,19 @@ def test_prepare_dependency_archive_image_exists(
8585
# Verify docker run command was called
8686
mock_cmd_output.assert_any_call(self.EXPECTED_DOCKER_RUN_CMD)
8787

88+
# Verify archives directory was created
89+
mock_makedirs.assert_called_once_with("payload/archives", exist_ok=True)
90+
8891
# Verify archive was copied back
8992
mock_copy.assert_any_call("/tmp/test_dir/native_dependencies.tar.gz", "payload/archives/native_dependencies.tar.gz")
9093

9194
@patch("datacustomcode.deploy.cmd_output")
9295
@patch("datacustomcode.deploy.shutil.copy")
9396
@patch("datacustomcode.deploy.tempfile.TemporaryDirectory")
9497
@patch("datacustomcode.deploy.os.path.join")
98+
@patch("datacustomcode.deploy.os.makedirs")
9599
def test_prepare_dependency_archive_build_image(
96-
self, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
100+
self, mock_makedirs, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
97101
):
98102
"""Test prepare_dependency_archive when Docker image needs to be built."""
99103
# Mock the temporary directory context manager
@@ -124,15 +128,19 @@ def test_prepare_dependency_archive_build_image(
124128
# Verify docker run command was called
125129
mock_cmd_output.assert_any_call(self.EXPECTED_DOCKER_RUN_CMD)
126130

131+
# Verify archives directory was created
132+
mock_makedirs.assert_called_once_with("payload/archives", exist_ok=True)
133+
127134
# Verify archive was copied back
128135
mock_copy.assert_any_call("/tmp/test_dir/native_dependencies.tar.gz", "payload/archives/native_dependencies.tar.gz")
129136

130137
@patch("datacustomcode.deploy.cmd_output")
131138
@patch("datacustomcode.deploy.shutil.copy")
132139
@patch("datacustomcode.deploy.tempfile.TemporaryDirectory")
133140
@patch("datacustomcode.deploy.os.path.join")
141+
@patch("datacustomcode.deploy.os.makedirs")
134142
def test_prepare_dependency_archive_docker_build_failure(
135-
self, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
143+
self, mock_makedirs, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
136144
):
137145
"""Test prepare_dependency_archive when Docker build fails."""
138146
# Mock the temporary directory context manager
@@ -161,8 +169,9 @@ def test_prepare_dependency_archive_docker_build_failure(
161169
@patch("datacustomcode.deploy.shutil.copy")
162170
@patch("datacustomcode.deploy.tempfile.TemporaryDirectory")
163171
@patch("datacustomcode.deploy.os.path.join")
172+
@patch("datacustomcode.deploy.os.makedirs")
164173
def test_prepare_dependency_archive_docker_run_failure(
165-
self, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
174+
self, mock_makedirs, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
166175
):
167176
"""Test prepare_dependency_archive when Docker run fails."""
168177
# Mock the temporary directory context manager
@@ -195,8 +204,9 @@ def test_prepare_dependency_archive_docker_run_failure(
195204
@patch("datacustomcode.deploy.shutil.copy")
196205
@patch("datacustomcode.deploy.tempfile.TemporaryDirectory")
197206
@patch("datacustomcode.deploy.os.path.join")
207+
@patch("datacustomcode.deploy.os.makedirs")
198208
def test_prepare_dependency_archive_file_copy_failure(
199-
self, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
209+
self, mock_makedirs, mock_join, mock_temp_dir, mock_copy, mock_cmd_output
200210
):
201211
"""Test prepare_dependency_archive when file copy fails."""
202212
# Mock the temporary directory context manager

0 commit comments

Comments
 (0)