From f1f19fefc98e0a19ef55381fea6833e1c3e1dcf4 Mon Sep 17 00:00:00 2001 From: srh-sloan Date: Wed, 16 Oct 2024 11:40:08 +0000 Subject: [PATCH] Updating temp file location to use config --- .devcontainer/devcontainer.json | 18 ++++++++++++++++++ app/blueprints/fund_builder/routes.py | 4 ++-- app/export_config/helpers.py | 17 +++++++++-------- config/envs/default.py | 2 ++ config/envs/development.py | 2 ++ config/envs/unit_test.py | 2 ++ tests/test_config_export.py | 3 ++- tests/test_integration.py | 4 +++- 8 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4b21160 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,18 @@ +{ + "dockerComposeFile": [ + "../docker-compose.yml", + "../compose.override.yml" + ], + "service": "fab", + "shutdownAction": "none", + "workspaceFolder": "/fab", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.debugpy", + "ms-python.vscode-pylance", + "mikoz.black-py" + ] + } + }, +} \ No newline at end of file diff --git a/app/blueprints/fund_builder/routes.py b/app/blueprints/fund_builder/routes.py index 1f755a1..e7286ca 100644 --- a/app/blueprints/fund_builder/routes.py +++ b/app/blueprints/fund_builder/routes.py @@ -531,9 +531,9 @@ def create_export_files(round_id): round_short_name = get_round_by_id(round_id).short_name # Directory to zip - directory_to_zip = f"app/export_config/output/{round_short_name}/" + directory_to_zip = Config.TEMP_FILE_PATH / "round_short_name" # Output zip file path (temporary) - output_zip_path = f"app/export_config/output/{round_short_name}.zip" + output_zip_path = Config.TEMP_FILE_PATH / f"{round_short_name}.zip" # Create a zip archive of the directory shutil.make_archive(output_zip_path.replace(".zip", ""), "zip", directory_to_zip) diff --git a/app/export_config/helpers.py b/app/export_config/helpers.py index 0dc9139..a5733c1 100644 --- a/app/export_config/helpers.py +++ b/app/export_config/helpers.py @@ -7,29 +7,30 @@ from app.blueprints.self_serve.routes import human_to_kebab_case from app.blueprints.self_serve.routes import human_to_snake_case from app.shared.helpers import convert_to_dict +from config import Config def write_config(config, filename, round_short_name, config_type): # Get the directory of the current file - current_dir = os.path.dirname(__file__) + # Construct the path to the output directory relative to this file's location - base_output_dir = os.path.join(current_dir, f"output/{round_short_name}/") + base_output_dir = Config.TEMP_FILE_PATH / round_short_name if config_type == "form_json": - output_dir = os.path.join(base_output_dir, "form_runner/") + output_dir = base_output_dir/ "form_runner" content_to_write = config - file_path = os.path.join(output_dir, f"{human_to_kebab_case(filename)}.json") + file_path = output_dir/ f"{human_to_kebab_case(filename)}.json" elif config_type == "python_file": - output_dir = os.path.join(base_output_dir, "fund_store/") + output_dir = base_output_dir/ "fund_store" config_dict = convert_to_dict(config) # Convert config to dict for non-JSON types content_to_write = "LOADER_CONFIG=" content_to_write += str(config_dict) - file_path = os.path.join(output_dir, f"{human_to_snake_case(filename)}.py") + file_path = output_dir/ f"{human_to_snake_case(filename)}.py" elif config_type == "html": - output_dir = os.path.join(base_output_dir, "html/") + output_dir = base_output_dir/"html" content_to_write = config - file_path = os.path.join(output_dir, f"{filename}_all_questions_en.html") + file_path = output_dir/f"{filename}_all_questions_en.html" # Ensure the output directory exists os.makedirs(output_dir, exist_ok=True) diff --git a/config/envs/default.py b/config/envs/default.py index 5b8f08a..1d93e22 100644 --- a/config/envs/default.py +++ b/config/envs/default.py @@ -18,3 +18,5 @@ class DefaultConfig(object): FORM_RUNNER_URL = getenv("FORM_RUNNER_INTERNAL_HOST", "http://form-runner:3009") FORM_RUNNER_URL_REDIRECT = getenv("FORM_RUNNER_EXTERNAL_HOST", "http://localhost:3009") SQLALCHEMY_DATABASE_URI = environ.get("DATABASE_URL") + + TEMP_FILE_PATH="/tmp" \ No newline at end of file diff --git a/config/envs/development.py b/config/envs/development.py index ac75f01..607c9a8 100644 --- a/config/envs/development.py +++ b/config/envs/development.py @@ -1,5 +1,6 @@ import logging from os import getenv +from pathlib import Path from fsd_utils import configclass @@ -16,3 +17,4 @@ class DevelopmentConfig(Config): "DATABASE_URL", "postgresql://postgres:password@fab-db:5432/fab", # pragma: allowlist secret ) + TEMP_FILE_PATH=Path("app") / "export_config" / "output" diff --git a/config/envs/unit_test.py b/config/envs/unit_test.py index 911bdcc..d4bda3b 100644 --- a/config/envs/unit_test.py +++ b/config/envs/unit_test.py @@ -1,5 +1,6 @@ import logging from os import getenv +from pathlib import Path from fsd_utils import configclass @@ -18,3 +19,4 @@ class UnitTestConfig(Config): "DATABASE_URL_UNIT_TEST", "postgresql://postgres:postgres@127.0.0.1:5432/fab_unit_test", # pragma: allowlist secret ) + TEMP_FILE_PATH=Path("app") / "export_config" / "output" \ No newline at end of file diff --git a/tests/test_config_export.py b/tests/test_config_export.py index 48dcf74..b831834 100644 --- a/tests/test_config_export.py +++ b/tests/test_config_export.py @@ -13,8 +13,9 @@ from app.export_config.generate_fund_round_html import frontend_html_suffix from app.export_config.generate_fund_round_html import generate_all_round_html from app.export_config.helpers import validate_json +from config import Config -output_base_path = Path("app") / "export_config" / "output" +output_base_path = Config.TEMP_FILE_PATH def read_data_from_output_file(file): diff --git a/tests/test_integration.py b/tests/test_integration.py index 8b4d381..57c5890 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -28,6 +28,8 @@ from tasks.test_data import BASIC_FUND_INFO from tasks.test_data import BASIC_ROUND_INFO +from config import Config + def test_build_form_json_no_conditions(seed_dynamic_data): @@ -283,7 +285,7 @@ def test_list_relationship(seed_dynamic_data): assert result.lizt.name == "classifications_list" -output_base_path = Path("app") / "export_config" / "output" +output_base_path = Config.TEMP_FILE_PATH # add files in /test_data t orun the below test against each file