Skip to content

Commit

Permalink
Updating temp file location to use config
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Oct 16, 2024
1 parent 7ad0bc8 commit f1f19fe
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
},
}
4 changes: 2 additions & 2 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions app/export_config/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions config/envs/development.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from os import getenv
from pathlib import Path

from fsd_utils import configclass

Expand All @@ -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"
2 changes: 2 additions & 0 deletions config/envs/unit_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from os import getenv
from pathlib import Path

from fsd_utils import configclass

Expand All @@ -18,3 +19,4 @@ class UnitTestConfig(Config):
"DATABASE_URL_UNIT_TEST",
"postgresql://postgres:[email protected]:5432/fab_unit_test", # pragma: allowlist secret
)
TEMP_FILE_PATH=Path("app") / "export_config" / "output"
3 changes: 2 additions & 1 deletion tests/test_config_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1f19fe

Please sign in to comment.