Skip to content

Commit

Permalink
sc-12637 create output dir if it doesn't exist (#14)
Browse files Browse the repository at this point in the history
* sc-12637 create output dir if it doesn't exist

---------

Co-authored-by: Matthew Warren <[email protected]>
  • Loading branch information
mattwwarren and Matthew Warren committed Apr 17, 2024
1 parent 41d1ec4 commit 502d6a5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
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)

0 comments on commit 502d6a5

Please sign in to comment.