Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appstruct #436

Merged
merged 13 commits into from
Jul 26, 2024
37 changes: 37 additions & 0 deletions pepsico/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import flask
import importlib
import os

from globals_ import FLASK, GLOBAL_CONFIG
import homepage
import pingrid

for name, config in GLOBAL_CONFIG['maprooms'].items():
if config is not None:
module = importlib.import_module(name)
if isinstance(config, list):
for c in config:
module.register(FLASK, c)


@FLASK.route(f"{GLOBAL_CONFIG['url_path_prefix']}/health")
def health_endpoint():
return flask.jsonify({'status': 'healthy', 'name': 'python_maproom'})


if __name__ == "__main__":
if GLOBAL_CONFIG["mode"] != "prod":
import warnings
warnings.simplefilter("error")
debug = True
else:
debug = False

FLASK.run(
GLOBAL_CONFIG["dev_server_interface"],
GLOBAL_CONFIG["dev_server_port"],
debug=debug,
extra_files=os.environ["CONFIG"].split(":"),
processes=GLOBAL_CONFIG["dev_processes"],
threaded=False,
)
17 changes: 17 additions & 0 deletions pepsico/config-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
url_path_prefix: /python_maproom

# DB configuration for the production docker environment. Override in
# development environment.
db:
host: postgres
port: 5432
user: ingrid
dbname: iridb

maprooms:

projections:

# App set up
core_path: projections
title: Projections
10 changes: 10 additions & 0 deletions pepsico/config-dev-sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Configuration overrides for development. Copy this file to config-dev.yaml and edit as needed.

mode: debug # debug, devel or prod
dev_server_interface: 127.0.0.1
dev_server_port: 8050
dev_processes: 4
loglevel: info
aaron-kaplan marked this conversation as resolved.
Show resolved Hide resolved
db:
host: localhost # at IRI, set this to dlcomputemon1.iri.columbia.edu
password: null # at IRI, get the password from another developer
1 change: 1 addition & 0 deletions pepsico/controls.py
22 changes: 22 additions & 0 deletions pepsico/globals_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import flask
import pingrid
import os

defaultconfig = pingrid.load_config("config-defaults.yaml")
appconfig = pingrid.load_config(os.environ["CONFIG"])
GLOBAL_CONFIG = pingrid.deep_merge(
{k: v for k, v in defaultconfig.items() if k != "maprooms"},
{k: v for k, v in appconfig.items() if k != "maprooms"},
)
GLOBAL_CONFIG['maprooms'] = {}
for k, v in appconfig['maprooms'].items():
if isinstance(v, list):
GLOBAL_CONFIG['maprooms'][k] = [pingrid.deep_merge(defaultconfig['maprooms'][k], v[i]) for i in range(len(v))]
elif v is not None:
GLOBAL_CONFIG['maprooms'][k] = pingrid.deep_merge(defaultconfig['maprooms'][k], v)


FLASK = flask.Flask(
"pepsicomaprooms",
static_url_path=f'{GLOBAL_CONFIG["url_path_prefix"]}/static',
)
aaron-kaplan marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions pepsico/homepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import flask
import os

from globals_ import FLASK, GLOBAL_CONFIG
import pingrid

template = '''
{% for item in maprooms %}
<a href="{{item["path"]}}">{{item["title"]}}</a><br>
{% endfor %}
'''

maprooms = []

for name, config in GLOBAL_CONFIG["maprooms"].items():
if config is not None:
if not isinstance(config, list):
config = [config]
for c in config:
try:
one_config = {
"title": c['title'],
"path": f'{GLOBAL_CONFIG["url_path_prefix"]}/{c["core_path"]}',
}
except KeyError as e:
raise Exception(f'configuration of maproom "{name}" is incomplete') from e
maprooms.append(one_config)


@FLASK.route(GLOBAL_CONFIG["url_path_prefix"] + "/")
def homepage():
return flask.render_template_string(template, maprooms=maprooms)
1 change: 1 addition & 0 deletions pepsico/pingrid
1 change: 1 addition & 0 deletions pepsico/projections/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .maproom import register
Loading