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

sc-12637 create output dir if it doesn't exist #14

Merged
merged 3 commits into from
Apr 17, 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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ repos:
additional_dependencies: [types-all]
args: [--explicit-package-bases, --ignore-missing-imports]
exclude: ^dynamic_importer/samples/|^files/
- repo: https://github.com/leoll2/copyright_notice_precommit
rev: 0.1.1
- repo: https://github.com/sbrunner/hooks
rev: 1.0.0
hooks:
- id: copyright-notice
args: [--notice=copyright.txt]
- id: copyright
- id: copyright-required
4 changes: 0 additions & 4 deletions copyright.txt

This file was deleted.

10 changes: 10 additions & 0 deletions src/dynamic_importer/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024 CloudTruth, Inc.
# All Rights Reserved
#
from __future__ import annotations

import json
Expand Down Expand Up @@ -72,6 +77,10 @@ def process_configs(file_type, default_values, env_values, output_dir, project):
raise click.UsageError(
"At least one of --default-values and --env-values must be provided"
)

if not os.path.exists(output_dir):
os.makedirs(output_dir)

input_files = {}
if default_values:
click.echo(f"Using default values from: {default_values}")
Expand Down Expand Up @@ -130,6 +139,7 @@ def regenerate_template(default_values, env_values, file_type, data_file):
raise click.UsageError(
"At least one of --default-values and --env-values must be provided"
)

output_dir = os.path.dirname(data_file) or "."
input_files = {}
if default_values:
Expand Down
36 changes: 36 additions & 0 deletions src/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024 CloudTruth, Inc.
# All Rights Reserved
#
from __future__ import annotations

import os
import pathlib
import shutil
import uuid
from tempfile import gettempdir
from unittest import mock
from unittest import TestCase

Expand Down Expand Up @@ -224,3 +233,30 @@ def test_cli_import_data_json(mock_get, mock_post, tmp_path):
catch_exceptions=False,
)
assert result.exit_code == 0


def test_cli_process_configs_missing_outputdir():
runner = CliRunner()
current_dir = pathlib.Path(__file__).parent.resolve()
dest_dir = os.path.join(gettempdir(), f"testproj-{uuid.uuid4()}")
try:
result = runner.invoke(
import_config,
[
"process-configs",
"-t",
"dotenv",
"-p",
"testproj",
"--default-values",
f"{current_dir}/../../samples/.env.sample",
"--output-dir",
dest_dir,
],
catch_exceptions=False,
)
assert result.exit_code == 0

finally:
if os.path.exists(dest_dir):
shutil.rmtree(dest_dir)
Loading