Skip to content

Commit

Permalink
move deployment class back to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPesce committed Sep 24, 2024
1 parent d0a3fde commit 235bb35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
31 changes: 1 addition & 30 deletions backend/app/internal/flowsheet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,14 @@
import tinydb # JSON single-file 'database'

# package-local
from app.internal.settings import AppSettings
from app.internal.settings import Deployment, AppSettings
from watertap.ui.fsapi import FlowsheetInterface
import idaes.logger as idaeslog

_log = idaeslog.getLogger(__name__)
_log.setLevel(idaeslog.DEBUG)
VERSION = 3

class Deployment:
"""Values related to the deployment context of the UI,
e.g., NAWI WaterTAP, PROMMIS, or IDAES.
"""
# env var for project name
PROJECT_ENV = "PSE_PROJECT"
# projects and their associated packages
PROJ = {
"nawi": ("watertap",),
"idaes": ("idaes",),
"prommis": ("prommis",)
}
DEFAULT_PROJ = "nawi"

def __init__(self, project=DEFAULT_PROJ):
_log.info(f"Deploy for project={project}")
if project not in self.PROJ.keys():
valid_projects = ", ".join((str(x) for x in self.PROJ))
raise ValueError(f"project '{project}' not in ({valid_projects})")
self.project = project
self.package = self.PROJ[project]
self.data_basedir = Path.home() / f".{self.project}"
try:
self.data_basedir.mkdir(parents=True, exist_ok=True)
except (FileNotFoundError, OSError) as err:
_log.error(f"error creating project data directory '{self.data_basedir}'")
raise
_log.info(f"Deployment: project={self.project} package={self.package} data_basedir={self.data_basedir}")


class FlowsheetInfo(BaseModel):
"""Information about a flowsheet."""
Expand Down
29 changes: 29 additions & 0 deletions backend/app/internal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@
_log.addHandler(h)
_log.setLevel(logging.WARNING)

class Deployment:
"""Values related to the deployment context of the UI,
e.g., NAWI WaterTAP, PROMMIS, or IDAES.
"""
# env var for project name
PROJECT_ENV = "PSE_PROJECT"
# projects and their associated packages
PROJ = {
"nawi": ("watertap",),
"idaes": ("idaes",),
"prommis": ("prommis",)
}
DEFAULT_PROJ = "nawi"

def __init__(self, project=DEFAULT_PROJ):
_log.info(f"Deploy for project={project}")
if project not in self.PROJ.keys():
valid_projects = ", ".join((str(x) for x in self.PROJ))
raise ValueError(f"project '{project}' not in ({valid_projects})")
self.project = project
self.package = self.PROJ[project]
self.data_basedir = Path.home() / f".{self.project}"
try:
self.data_basedir.mkdir(parents=True, exist_ok=True)
except (FileNotFoundError, OSError) as err:
_log.error(f"error creating project data directory '{self.data_basedir}'")
raise
_log.info(f"Deployment: project={self.project} package={self.package} data_basedir={self.data_basedir}")

class AppSettings(BaseSettings):
#: List of package names in which to look for flowsheets
packages: List[str]
Expand Down

0 comments on commit 235bb35

Please sign in to comment.