Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove recursive search for snowflake.yml #705

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfc-gh-turbaszek can we remove the find_project_root as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NADE commands are using it for checking if project is not within another project

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