diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a914c65..862d994 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/copyright.txt b/copyright.txt deleted file mode 100644 index d16743d..0000000 --- a/copyright.txt +++ /dev/null @@ -1,4 +0,0 @@ -# -# Copyright (C) 2024 CloudTruth, Inc. -# All Rights Reserved -# diff --git a/src/dynamic_importer/main.py b/src/dynamic_importer/main.py index f753a8b..ea63d2d 100644 --- a/src/dynamic_importer/main.py +++ b/src/dynamic_importer/main.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2024 CloudTruth, Inc. +# All Rights Reserved +# from __future__ import annotations import json @@ -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}") @@ -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: diff --git a/src/tests/test_cli.py b/src/tests/test_cli.py index 11d5dfe..7311436 100644 --- a/src/tests/test_cli.py +++ b/src/tests/test_cli.py @@ -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 @@ -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)