handling env permissions for local vs test environments and debugging handling of primary roof

This commit is contained in:
Khalim Conn-Kowlessar 2026-02-09 16:30:40 +00:00
parent 812df5a782
commit 294c12fe4c
4 changed files with 27 additions and 9 deletions

View file

@ -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()

View file

@ -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)

View file

@ -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 = {}