From 294c12fe4cc2582c383264c186ecd86c0c4bba24 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 9 Feb 2026 16:30:40 +0000 Subject: [PATCH] handling env permissions for local vs test environments and debugging handling of primary roof --- backend/{.env.local => .env.test} | 0 backend/app/config.py | 22 +++++++++++++++++++--- backend/app/plan/utils.py | 2 +- recommendations/RoofRecommendations.py | 12 +++++++----- 4 files changed, 27 insertions(+), 9 deletions(-) rename backend/{.env.local => .env.test} (100%) diff --git a/backend/.env.local b/backend/.env.test similarity index 100% rename from backend/.env.local rename to backend/.env.test diff --git a/backend/app/config.py b/backend/app/config.py index b335c215..41552ae5 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -1,8 +1,22 @@ +import os from functools import lru_cache -from pydantic_settings import BaseSettings +from pydantic_settings import BaseSettings, SettingsConfigDict from typing import Optional +def resolve_env_file() -> Optional[str]: + env = os.getenv("ENVIRONMENT", "local") + + if env == "local": + return "backend/.env" + + if env == "test": + return "backend/.env.test" + + # prod = no env file + return None + + class Settings(BaseSettings): API_KEY: str API_KEY_NAME: str = "X-API-KEY" @@ -41,8 +55,10 @@ class Settings(BaseSettings): AWS_SECRET_KEY_ID: Optional[str] = None AWS_DEFAULT_REGION: Optional[str] = None - class Config: - env_file = "backend/.env.local" + model_config = SettingsConfigDict( + env_file=resolve_env_file(), + env_file_encoding="utf-8", + ) @lru_cache() diff --git a/backend/app/plan/utils.py b/backend/app/plan/utils.py index 33f391d4..10d7fb06 100644 --- a/backend/app/plan/utils.py +++ b/backend/app/plan/utils.py @@ -24,7 +24,7 @@ def get_cleaned(): cleaned = read_from_s3( s3_file_name="cleaned_epc_data/cleaned.bson", - bucket_name="retrofit-data-{environment}".format(environment=get_settings().ENVIRONMENT) + bucket_name=get_settings().DATA_BUCKET ) cleaned = msgpack.unpackb(cleaned, raw=False) diff --git a/recommendations/RoofRecommendations.py b/recommendations/RoofRecommendations.py index 71e47ba6..f88a672b 100644 --- a/recommendations/RoofRecommendations.py +++ b/recommendations/RoofRecommendations.py @@ -331,18 +331,18 @@ class RoofRecommendations: """ # Can a non-primary part satisfy loft insulation? - primary_needs_loft = component_needs[1]["needs_loft_insulation"] + primary_needs_loft = component_needs[0]["needs_loft_insulation"] secondary_needs_loft = any( - p['needs_loft_insulation'] for idx, p in component_needs.items() if idx != 1 + p['needs_loft_insulation'] for idx, p in component_needs.items() if idx != 0 ) if primary_needs_loft and not secondary_needs_loft: # Only option is loft return "loft" - primary_needs_sloping = component_needs[1]["needs_sloping_ceiling"] + primary_needs_sloping = component_needs[0]["needs_sloping_ceiling"] secondary_needs_sloping = any( - p['needs_sloping_ceiling'] for idx, p in component_needs.items() if idx != 1 + p['needs_sloping_ceiling'] for idx, p in component_needs.items() if idx != 0 ) if primary_needs_sloping and not secondary_needs_sloping: @@ -418,11 +418,13 @@ class RoofRecommendations: return needs_sloping, not needs_loft # Indicates that the property needs sloping ceiling as we only run # this in that case + roof_components = [x for x in find_my_epc_components if x["component_name"] == "Roof"] + extracted_roof_descriptions = { idx: { "description": component["description"], **RoofAttributes(component["description"]).process() - } for idx, component in enumerate(find_my_epc_components) if component["component_name"] == "Roof" + } for idx, component in enumerate(roof_components) } component_needs = {}