Skip to content
Closed
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
5 changes: 5 additions & 0 deletions python/pyspark/pipelines/init_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def example_python_materialized_view() -> DataFrame:
def init(name: str) -> None:
"""Generates a simple pipeline project."""
project_dir = Path.cwd() / name
if project_dir.exists():
raise FileExistsError(
f"Directory '{name}' already exists. "
"Please choose a different name or remove the existing directory."
)
project_dir.mkdir(parents=True, exist_ok=False)

# Create the storage directory
Expand Down
15 changes: 15 additions & 0 deletions python/pyspark/pipelines/tests/test_init_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def test_init(self):
Path("transformations") / "example_sql_materialized_view.sql",
)

def test_init_existing_directory(self):
with tempfile.TemporaryDirectory() as temp_dir:
project_name = "test_project"
with change_dir(Path(temp_dir)):
init(project_name)

with self.assertRaises(FileExistsError) as context:
init(project_name)

expected_message = (
f"Directory '{project_name}' already exists. "
"Please choose a different name or remove the existing directory."
)
self.assertEqual(str(context.exception), expected_message)


if __name__ == "__main__":
try:
Expand Down