Skip to content

Commit

Permalink
Remove recursive search for snowflake.yml (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-turbaszek authored Jan 31, 2024
1 parent dc814a9 commit e4e83cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/snowflake/cli/api/project/definition_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class DefinitionManager:
_project_config_paths: List[Path]

def __init__(self, project_arg: Optional[str] = None) -> None:
search_path = os.getcwd()
if project_arg:
search_path = os.path.abspath(project_arg)
project_root = DefinitionManager.find_project_root(Path(search_path))
if not project_root:
project_root = Path(
os.path.abspath(project_arg) if project_arg else os.getcwd()
)
if not self._base_definition_file_if_available(project_root):
raise MissingConfiguration(
f"Cannot find project definition (snowflake.yml). Please provide a path to the project or run this command in a valid project directory."
)
Expand Down
20 changes: 7 additions & 13 deletions tests/project/test_definition_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest import TestCase, mock
from unittest.mock import patch

from snowflake.cli.api.exceptions import MissingConfiguration
from snowflake.cli.api.project.definition_manager import DefinitionManager

from tests.project.fixtures import *
Expand Down Expand Up @@ -40,29 +41,22 @@ def test_finds_local_project_definition(self, mock_getcwd):
@mock.patch("os.path.abspath", return_value="/hello/world/test")
def test_double_dash_project_parameter_provided(self, mock_abs):
with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file:
definition_manager = DefinitionManager("/hello/world/test")
assert definition_manager._project_config_paths == [
Path("/hello/world/snowflake.yml")
]
with pytest.raises(MissingConfiguration):
DefinitionManager("/hello/world/test")

@mock.patch("os.path.abspath", return_value="/hello/world/test/again")
def test_dash_p_parameter_provided(self, mock_abs):
with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file:
definition_manager = DefinitionManager("/hello/world/test/again")
assert definition_manager._project_config_paths == [
Path("/hello/world/snowflake.yml")
]
with pytest.raises(MissingConfiguration):
DefinitionManager("/hello/world/test/again")

@mock.patch("os.getcwd", return_value="/hello/world")
@mock.patch("os.path.abspath", return_value="/hello/world/relative")
def test_dash_p_with_relative_parameter_provided(self, mock_abs, mock_getcwd):
with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file:
mock_getcwd.return_value = "/hello/world"
definition_manager = DefinitionManager("./relative")
mock_abs.assert_called_with("./relative")
assert definition_manager._project_config_paths == [
Path("/hello/world/snowflake.yml")
]
with pytest.raises(MissingConfiguration):
DefinitionManager("./relative")

@mock.patch("os.path.abspath", return_value="/tmp")
def test_find_definition_files_reached_root(self, mock_abs):
Expand Down

0 comments on commit e4e83cd

Please sign in to comment.