Skip to content

Commit

Permalink
Fix initialize CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyschools committed May 7, 2024
1 parent 558f029 commit d55cf86
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
43 changes: 29 additions & 14 deletions dltflow/cli/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import os
import warnings
import configparser

import click
Expand Down Expand Up @@ -53,7 +54,7 @@ def _parse_databricks_cfg(): # pragma: no cover


def _environments_from_databricks_profile(
username, project_name, shared
username, project_name, shared
): # pragma: no cover
"""Get the environments from the databricks profile."""
config = _parse_databricks_cfg()
Expand Down Expand Up @@ -113,14 +114,14 @@ def _environments_from_databricks_profile(
show_default=True,
)
def init(
profile: str,
project_name: str = "my_project",
config_path: str = "conf",
workflows_path: str = "workflows",
build_template: bool = False,
overwrite: bool = True,
dbfs_location: str = None,
shared: bool = True,
profile: str,
project_name: str = "my_project",
config_path: str = "conf",
workflows_path: str = "workflows",
build_template: bool = False,
overwrite: bool = True,
dbfs_location: str = None,
shared: bool = True,
): # pragma: no cover
"""
Initialize a new dltflow project.
Expand Down Expand Up @@ -179,8 +180,17 @@ def init(
"""
dbx_echo(f"Initializing dltflow project configuration.")

client = WorkspaceClient(profile=profile.upper())
user_name = client.current_user.me().user_name
_dbx_configured: bool = os.path.exists(_get_path())

if not _dbx_configured:
import getpass
user_name = getpass.getuser()
warnings.warn("Databricks CLI is not configured. `dltflow` can get setup, but deployments cannot "
"happen without it. Please run `databricks configure` and then re-init dltflow later if "
"you want to proceed now.")
else:
client = WorkspaceClient(profile=profile.upper())
user_name = client.current_user.me().user_name

try:
cfg = get_config()
Expand All @@ -202,6 +212,8 @@ def init(
_build = click.confirm(
"Do you want to overwrite the existing `dltflow` config file?"
)
else:
cfg = ProjectConfig().dict()

if _build:
project_name = click.prompt(
Expand Down Expand Up @@ -241,9 +253,12 @@ def init(
workflows=PathName(name=workflows_path),
)
shared = True if shared == "shared" else False
targets = dict(
_environments_from_databricks_profile(user_name, project_name, shared)
)
if _dbx_configured:
targets = dict(
_environments_from_databricks_profile(user_name, project_name, shared)
)
else:
targets = None
project_config = ProjectConfig(
dltflow=project_info, include=project_elements, targets=targets
)
Expand Down
8 changes: 4 additions & 4 deletions dltflow/cli/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProjectInfo(BaseModel):
Pydantic model for the project information.
"""

name: str = Field(..., description="Name of the project")
name: str = Field(default='my_project', description="Name of the project")


class PathName(BaseModel):
Expand Down Expand Up @@ -83,9 +83,9 @@ class ProjectConfig(BaseModel):
Pydantic model for the project configuration.
"""

dltflow: ProjectInfo
include: ProjectElements
targets: Mapping[str, Environment]
dltflow: ProjectInfo = Field(default_factory=ProjectInfo)
include: ProjectElements = Field(default_factory=ProjectElements)
targets: Mapping[str, Environment] = Field(default=None)


# if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions dltflow/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
from typing import Union
import subprocess

import yaml

Expand Down

0 comments on commit d55cf86

Please sign in to comment.