Skip to content

Commit

Permalink
fixup! fixup! fixup! Added better error when docker is not installed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-turbaszek committed Jun 12, 2024
1 parent bd5b50f commit 667553d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/snowflake/cli/plugins/stage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from contextlib import nullcontext
from dataclasses import dataclass
from os import path
from pathlib import Path, PosixPath
from pathlib import Path
from tempfile import TemporaryDirectory
from textwrap import dedent
from typing import Dict, List, Optional, Union
Expand Down Expand Up @@ -400,15 +400,15 @@ def _check_for_requirements_file(
return []

# Construct all possible path for requirements file for this context
# We don't use os.path or pathlib to preserve compatibility on Windows
req_file_name = "requirements.txt"
current_file = PosixPath(stage_path_parts.path) / req_file_name
path_parts = stage_path_parts.path.split("/")
possible_req_files = []

while (
current_file.parent != current_file
): # At some point .parent will return same root value
possible_req_files.append(str(current_file.parent / req_file_name))
current_file = current_file.parent
while path_parts:
current_file = "/".join([*path_parts, req_file_name])
possible_req_files.append(str(current_file))
path_parts = path_parts[:-1]

# Now for every possible path check if the file exists on stage,
# if yes break, we use the first possible file
Expand Down
11 changes: 7 additions & 4 deletions tests/stage/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,12 @@ def test_command_aliases(mock_connector, runner, mock_ctx, command, parameters):
),
],
)
def test_stage_manager_check_for_requirements_file(files, selected, packages):
@pytest.mark.parametrize(
"input_path", ["@db.schema.my_stage/dir/files", "@db.schema.my_stage/dir/files/"]
)
def test_stage_manager_check_for_requirements_file(
files, selected, packages, input_path
):
class _MockGetter:
def __init__(self):
self.download_file = None
Expand All @@ -1009,9 +1014,7 @@ def __call__(self, file_on_stage, target_dir):
):
with mock.patch.object(StageManager, "get", get_mock) as get_mock:
result = sm._check_for_requirements_file( # noqa: SLF001
stage_path_parts=sm._split_stage_path( # noqa: SLF001
"@db.schema.my_stage/dir/files"
)
stage_path_parts=sm._split_stage_path(input_path) # noqa: SLF001
)

assert result == packages
Expand Down

0 comments on commit 667553d

Please sign in to comment.