Skip to content

Commit 83afa36

Browse files
fix: update git utils temp file (#2057)
Co-authored-by: Ahsan Z Khan <[email protected]>
1 parent 3471f9e commit 83afa36

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/sagemaker/git_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ def _run_clone_command(repo_url, dest_dir):
282282
write_pipe = open(sshnoprompt.name, "w")
283283
write_pipe.write("ssh -oBatchMode=yes $@")
284284
write_pipe.close()
285-
# 511 in decimal is same as 777 in octal
286-
os.chmod(sshnoprompt.name, 511)
285+
os.chmod(sshnoprompt.name, 0o511)
287286
my_env["GIT_SSH"] = sshnoprompt.name
288287
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env)
289288

tests/unit/test_git_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import pytest
1616
import os
1717
import subprocess
18-
from mock import patch
18+
from mock import patch, ANY
1919

2020
from sagemaker import git_utils
2121

@@ -180,7 +180,7 @@ def test_git_clone_repo_dependencies_not_exist(exists, isdir, isfile, mkdtemp, c
180180
@patch("subprocess.check_call")
181181
@patch("tempfile.mkdtemp", return_value=REPO_DIR)
182182
@patch("os.path.isfile", return_value=True)
183-
def test_git_clone_repo_with_username_password_no_2fa(sfile, mkdtemp, check_call):
183+
def test_git_clone_repo_with_username_password_no_2fa(isfile, mkdtemp, check_call):
184184
git_config = {
185185
"repo": PRIVATE_GIT_REPO,
186186
"branch": PRIVATE_BRANCH,
@@ -262,12 +262,14 @@ def test_git_clone_repo_with_token_2fa(isfile, mkdtemp, check_call):
262262

263263

264264
@patch("subprocess.check_call")
265+
@patch("os.chmod")
265266
@patch("tempfile.mkdtemp", return_value=REPO_DIR)
266267
@patch("os.path.isfile", return_value=True)
267-
def test_git_clone_repo_ssh(isfile, mkdtemp, check_call):
268+
def test_git_clone_repo_ssh(isfile, mkdtemp, chmod, check_call):
268269
git_config = {"repo": PRIVATE_GIT_REPO_SSH, "branch": PRIVATE_BRANCH, "commit": PRIVATE_COMMIT}
269270
entry_point = "entry_point"
270271
ret = git_utils.git_clone_repo(git_config, entry_point)
272+
chmod.assert_any_call(ANY, 0o511)
271273
assert ret["entry_point"] == "/tmp/repo_dir/entry_point"
272274
assert ret["source_dir"] is None
273275
assert ret["dependencies"] is None

0 commit comments

Comments
 (0)