Skip to content

Commit

Permalink
fixed a bug where we tamper with python path before retrieving it, ca…
Browse files Browse the repository at this point in the history
…using invalid python path
  • Loading branch information
ssb-jnk committed Aug 11, 2023
1 parent 94efdfa commit 0b38a73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/ssb_project_cli/ssb_project/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def ipykernel_attach_bashrc(project_name: str) -> None:
with open(kernel_json_file, encoding="utf-8") as f:
content_as_json = json.loads(f.read())

python_executable_path = _get_python_executable_path(content_as_json["argv"])
if python_executable_path is None:
print(
f":x:\tCould not mount .bashrc, cannot find python executable path in {kernel_json_file}"
) # noqa: B907
exit(1)

content_as_json["argv"] = [
f"{project_kernel_path}/python.sh",
"-m",
Expand All @@ -136,13 +143,6 @@ def ipykernel_attach_bashrc(project_name: str) -> None:

start_script_path = f"{project_kernel_path}/python.sh"

python_executable_path = _get_python_executable_path(content_as_json["argv"])
if python_executable_path is None:
print(
f":x:\tCould not mount .bashrc, cannot find python executable path in {kernel_json_file}"
) # noqa: B907
exit(1)

_write_start_script(start_script_path, python_executable_path)

# set rx to everyone, required for jupyterlab to get permission to call start script
Expand Down
10 changes: 2 additions & 8 deletions tests/unit/build_test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,14 @@ def test_ipykernel_attach_bashrc_kernel_json_file_not_exist(
]
},
)
@patch(
f"{BUILD}.json.dumps",
return_value='{"argv": ["/bin/python3", "-m", "ipykernel_launcher", "-f", "{connection_file}"]}',
)
@patch(f"{BUILD}._get_python_executable_path", return_value=None)
@patch(f"{BUILD}.print")
def test_ipykernel_attach_bashrc_python_executable_path_not_found(
mock_print: Mock,
mock_python_executable_path: Mock,
mock_json_dumps: Mock,
mock_json_loads: Mock,
mock_exists: Mock,
mock_file_open: Mock,
mock_exists: Mock,
mock_get_kernels_dict: Mock,
) -> None:
project_name = "existing_project"
Expand All @@ -244,9 +239,8 @@ def test_ipykernel_attach_bashrc_python_executable_path_not_found(

assert mock_get_kernels_dict.call_count == 1
assert mock_exists.call_count == 2
assert mock_file_open.call_count == 2
assert mock_file_open.call_count == 1
assert mock_json_loads.call_count == 1
assert mock_json_dumps.call_count == 1
assert mock_python_executable_path.call_count == 1
assert mock_print.call_args[0][0] == expected_print_message
assert cm.exception.code == expected_exit_code
Expand Down

0 comments on commit 0b38a73

Please sign in to comment.