Skip to content

Commit

Permalink
Fix new component
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarthik108 committed Aug 23, 2023
1 parent 18dcc5e commit 2cf8730
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "snowdev"
version = "0.1.11"
version = "0.1.12"
description = "snowdev: DevOps toolkit for Snowflake, facilitating seamless deployment of UDFs, stored procedures, and Streamlit apps using Snowpark's capabilities right from your local environment."
authors = ["kaarthik <[email protected]>"]
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion snowdev/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def init():
@click.option("--streamlit", type=str, help="The name of the streamlit app.")
def new(udf, sproc, streamlit):
"""Create a new component."""
SnowHelper.create_new_component(udf, sproc, streamlit)
args_dict = {"udf": udf, "sproc": sproc, "streamlit": streamlit}
SnowHelper.create_new_component(args_dict)


@cli.command()
Expand Down
1 change: 1 addition & 0 deletions snowdev/fillers/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["Your Name <[email protected]>"]

[tool.poetry.dependencies]
python = ">=3.10.0,<3.11.0"
"snowflake-snowpark-python" = { version = "1.5.1", extras = ["pandas"] }

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
41 changes: 21 additions & 20 deletions snowdev/functions/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def get_template_path(relative_path):

TEMPLATES = {
"udf": {
"py": get_template_path("fillers/udf/fill.py"),
"toml": get_template_path("fillers/udf/fill.toml"),
"py": "fillers/udf/fill.py",
"toml": "fillers/udf/fill.toml",
},
"sproc": {
"py": get_template_path("fillers/sproc/fill.py"),
"toml": get_template_path("fillers/sproc/fill.toml"),
"py": "fillers/sproc/fill.py",
"toml": "fillers/sproc/fill.toml",
},
"streamlit": {
"py": get_template_path("fillers/streamlit/fill.py"),
"yml": get_template_path("fillers/streamlit/fill.yml"),
"py": "fillers/streamlit/fill.py",
"yml": "fillers/streamlit/fill.yml",
},
}

Expand Down Expand Up @@ -149,41 +149,39 @@ def create_new_component(cls, args_dict):
return

os.makedirs(new_item_path, exist_ok=True)
creation_successful = True

# Handling the streamlit templates specifically
if item_type == "streamlit":
for template_ext, output_name in [
("py", "streamlit_app.py"),
("yml", "environment.yml"),
]:
for ext, template_name in cls.TEMPLATES[item_type].items():
output_name = "streamlit_app.py" if ext == "py" else "environment.yml"
try:
template_content = pkg_resources.resource_string(
"snowdev", f"fillers/streamlit/fill.{template_ext}"
"snowdev", template_name
).decode("utf-8")

with open(os.path.join(new_item_path, output_name), "w") as f:
f.write(template_content)
except FileNotFoundError:
creation_successful = False
print(
colored(
f"No template found for {item_type} with extension {template_ext}. Creating an empty {output_name}...",
f"No template found for {item_type} with extension {ext}. Creating an empty {output_name}...",
"yellow",
)
)
with open(os.path.join(new_item_path, output_name), "w") as f:
pass

else:
for ext, template_name in cls.TEMPLATES[item_type].items():
filename = "app.py" if ext == "py" else "app.toml"
try:
template_content = pkg_resources.resource_string(
"snowdev", template_name
).decode("utf-8")

filename = "app.py" if ext == "py" else "app.toml"
with open(os.path.join(new_item_path, filename), "w") as f:
f.write(template_content)
except FileNotFoundError:
filename = "app.py" if ext == "py" else "app.toml"
creation_successful = False
print(
colored(
f"No template found for {item_type} with extension {ext}. Creating an empty {filename}...",
Expand All @@ -193,6 +191,9 @@ def create_new_component(cls, args_dict):
with open(os.path.join(new_item_path, filename), "w") as f:
pass

print(
colored(f"{item_type} {item_name} has been successfully created!", "green")
)
if creation_successful:
print(
colored(
f"{item_type} {item_name} has been successfully created!", "green"
)
)
2 changes: 1 addition & 1 deletion tests/functions/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from snowdev import main as snowdev_main
from snowdev import deployment as snowdev_main


@pytest.fixture
Expand Down

0 comments on commit 2cf8730

Please sign in to comment.