From a4811f8efc6e9e2cc8c25f8b25a8960969ad848b Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Tue, 30 Jan 2024 10:07:23 +0100 Subject: [PATCH 1/2] Remove recursive search for snowflake.yml --- .../cli/api/project/definition_manager.py | 8 ++------ tests/project/test_definition_manager.py | 20 +++++++------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/snowflake/cli/api/project/definition_manager.py b/src/snowflake/cli/api/project/definition_manager.py index d0cae66812..9c178e217e 100644 --- a/src/snowflake/cli/api/project/definition_manager.py +++ b/src/snowflake/cli/api/project/definition_manager.py @@ -1,7 +1,6 @@ from __future__ import annotations import functools -import os from pathlib import Path from typing import List, Optional @@ -26,11 +25,8 @@ 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(project_arg).absolute() if project_arg else Path.cwd() + 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." ) diff --git a/tests/project/test_definition_manager.py b/tests/project/test_definition_manager.py index 385dec20d1..165b701ea0 100644 --- a/tests/project/test_definition_manager.py +++ b/tests/project/test_definition_manager.py @@ -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 * @@ -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): From 172610153547a1a727c64f3821f15ab270f7fc08 Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Tue, 30 Jan 2024 12:51:56 +0100 Subject: [PATCH 2/2] fixup! Remove recursive search for snowflake.yml --- src/snowflake/cli/api/project/definition_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/snowflake/cli/api/project/definition_manager.py b/src/snowflake/cli/api/project/definition_manager.py index 9c178e217e..663e581563 100644 --- a/src/snowflake/cli/api/project/definition_manager.py +++ b/src/snowflake/cli/api/project/definition_manager.py @@ -1,6 +1,7 @@ from __future__ import annotations import functools +import os from pathlib import Path from typing import List, Optional @@ -25,7 +26,9 @@ class DefinitionManager: _project_config_paths: List[Path] def __init__(self, project_arg: Optional[str] = None) -> None: - project_root = Path(project_arg).absolute() if project_arg else Path.cwd() + 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."