Skip to content

Commit ff3dca6

Browse files
committed
refactor: standardize string quotes and improve code consistency
1 parent e9d3f71 commit ff3dca6

File tree

3 files changed

+45
-41
lines changed

3 files changed

+45
-41
lines changed

src/datapilot/cli/main.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
def load_config_from_file():
1414
"""Load configuration from ~/.altimate/altimate.json if it exists."""
1515
config_path = Path.home() / ".altimate" / "altimate.json"
16-
16+
1717
if not config_path.exists():
1818
return {}
19-
19+
2020
try:
21-
with open(config_path, 'r') as f:
21+
with open(config_path) as f:
2222
config = json.load(f)
2323
return config
24-
except (json.JSONDecodeError, IOError) as e:
24+
except (OSError, json.JSONDecodeError) as e:
2525
click.echo(f"Warning: Failed to load config from {config_path}: {e}", err=True)
2626
return {}
2727

@@ -30,14 +30,14 @@ def substitute_env_vars(value):
3030
"""Replace ${env:ENV_VARIABLE} patterns with actual environment variable values."""
3131
if not isinstance(value, str):
3232
return value
33-
33+
3434
# Pattern to match ${env:VARIABLE_NAME}
35-
pattern = r'\$\{env:([^}]+)\}'
36-
35+
pattern = r"\$\{env:([^}]+)\}"
36+
3737
def replacer(match):
3838
env_var = match.group(1)
3939
return os.environ.get(env_var, match.group(0))
40-
40+
4141
return re.sub(pattern, replacer, value)
4242

4343

@@ -58,38 +58,34 @@ def datapilot(ctx, token, instance_name, backend_url):
5858
"""Altimate CLI for DBT project management."""
5959
# Load .env file from current directory if it exists
6060
load_dotenv()
61-
61+
6262
# Load configuration from file
6363
file_config = load_config_from_file()
6464
file_config = process_config(file_config)
65-
65+
6666
# Map config file keys to CLI option names
67-
config_mapping = {
68-
'altimateApiKey': 'token',
69-
'altimateInstanceName': 'instance_name',
70-
'altimateUrl': 'backend_url'
71-
}
72-
67+
config_mapping = {"altimateApiKey": "token", "altimateInstanceName": "instance_name", "altimateUrl": "backend_url"}
68+
7369
# Store common options in context, with CLI args taking precedence
7470
ctx.ensure_object(dict)
75-
71+
7672
# Apply file config first
7773
for file_key, cli_key in config_mapping.items():
7874
if file_key in file_config:
7975
ctx.obj[cli_key] = file_config[file_key]
80-
76+
8177
# Override with CLI arguments if provided
8278
if token is not None:
83-
ctx.obj['token'] = token
79+
ctx.obj["token"] = token
8480
if instance_name is not None:
85-
ctx.obj['instance_name'] = instance_name
81+
ctx.obj["instance_name"] = instance_name
8682
if backend_url != "https://api.myaltimate.com": # Only override if not default
87-
ctx.obj['backend_url'] = backend_url
88-
83+
ctx.obj["backend_url"] = backend_url
84+
8985
# Set defaults if nothing was provided
90-
ctx.obj.setdefault('token', None)
91-
ctx.obj.setdefault('instance_name', None)
92-
ctx.obj.setdefault('backend_url', 'https://api.myaltimate.com')
86+
ctx.obj.setdefault("token", None)
87+
ctx.obj.setdefault("instance_name", None)
88+
ctx.obj.setdefault("backend_url", "https://api.myaltimate.com")
9389

9490

9591
datapilot.add_command(dbt)

src/datapilot/core/platforms/dbt/cli/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def project_health(
7272
:param manifest_path: Path to the DBT manifest file.
7373
"""
7474
# Get common options from parent context
75-
token = ctx.parent.obj.get('token')
76-
instance_name = ctx.parent.obj.get('instance_name')
77-
backend_url = ctx.parent.obj.get('backend_url')
78-
75+
token = ctx.parent.obj.get("token")
76+
instance_name = ctx.parent.obj.get("instance_name")
77+
backend_url = ctx.parent.obj.get("backend_url")
78+
7979
config = None
8080
if config_path:
8181
config = load_config(config_path)
@@ -151,16 +151,16 @@ def onboard(
151151
):
152152
"""Onboard a manifest file to DBT."""
153153
# Get common options from parent context
154-
token = ctx.parent.obj.get('token')
155-
instance_name = ctx.parent.obj.get('instance_name')
156-
backend_url = ctx.parent.obj.get('backend_url')
157-
154+
token = ctx.parent.obj.get("token")
155+
instance_name = ctx.parent.obj.get("instance_name")
156+
backend_url = ctx.parent.obj.get("backend_url")
157+
158158
# For onboard command, token and instance_name are required
159159
if not token:
160160
token = click.prompt("API Token")
161161
if not instance_name:
162162
instance_name = click.prompt("Instance Name")
163-
163+
164164
check_token_and_instance(token, instance_name)
165165

166166
if not validate_credentials(token, backend_url, instance_name):

tests/core/platform/dbt/test_cli.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# test_app.py
22
from click.testing import CliRunner
33

4-
from datapilot.core.platforms.dbt.cli.cli import project_health
4+
from datapilot.cli.main import datapilot
55

66

77
def test_project_health_with_required_and_optional_args():
@@ -11,7 +11,9 @@ def test_project_health_with_required_and_optional_args():
1111
config_path = "tests/data/config.yml"
1212

1313
# Simulate command invocation
14-
result = runner.invoke(project_health, ["--manifest-path", manifest_path, "--catalog-path", catalog_path, "--config-path", config_path])
14+
result = runner.invoke(
15+
datapilot, ["project-health", "--manifest-path", manifest_path, "--catalog-path", catalog_path, "--config-path", config_path]
16+
)
1517

1618
assert result.exit_code == 0 # Ensure the command executed successfully
1719
# Add more assertions here to validate the behavior of your command,
@@ -25,8 +27,9 @@ def test_project_health_with_only_required_arg():
2527

2628
# Simulate command invocation without optional arguments
2729
result = runner.invoke(
28-
project_health,
30+
datapilot,
2931
[
32+
"project-health",
3033
"--manifest-path",
3134
manifest_path,
3235
],
@@ -43,8 +46,9 @@ def test_project_health_with_only_required_arg_version1_6():
4346

4447
# Simulate command invocation without optional arguments
4548
result = runner.invoke(
46-
project_health,
49+
datapilot,
4750
[
51+
"project-health",
4852
"--manifest-path",
4953
manifest_path,
5054
],
@@ -61,8 +65,9 @@ def test_project_health_with_macro_args():
6165

6266
# Simulate command invocation without optional arguments
6367
result = runner.invoke(
64-
project_health,
68+
datapilot,
6569
[
70+
"project-health",
6671
"--manifest-path",
6772
manifest_path,
6873
],
@@ -76,8 +81,9 @@ def test_project_health_with_macro_args():
7681

7782
# Simulate command invocation without optional arguments
7883
result = runner.invoke(
79-
project_health,
84+
datapilot,
8085
[
86+
"project-health",
8187
"--manifest-path",
8288
manifest_path,
8389
],
@@ -95,7 +101,9 @@ def test_project_health_with_required_and_optional_args_v12():
95101
config_path = "tests/data/config.yml"
96102

97103
# Simulate command invocation
98-
result = runner.invoke(project_health, ["--manifest-path", manifest_path, "--catalog-path", catalog_path, "--config-path", config_path])
104+
result = runner.invoke(
105+
datapilot, ["project-health", "--manifest-path", manifest_path, "--catalog-path", catalog_path, "--config-path", config_path]
106+
)
99107

100108
assert result.exit_code == 0 # Ensure the command executed successfully
101109
# Add more assertions here to validate the behavior of your command,

0 commit comments

Comments
 (0)