Skip to content

Commit

Permalink
eliminate cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
nsheff committed Jul 6, 2024
1 parent 0218bfb commit 74b2511
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
5 changes: 3 additions & 2 deletions deployment/seqcolapi.databio.org/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM databio/seqcolapi
COPY seqcolapi.yaml /seqcolapi_config.yaml
ENV SEQCOLAPI_CONFIG /seqcolapi_config.yaml
# COPY seqcolapi.yaml /seqcolapi_config.yaml
# ENV SEQCOLAPI_CONFIG /seqcolapi_config.yaml
# pass -- config no longer needed.
87 changes: 43 additions & 44 deletions seqcolapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,28 @@ async def service_info():
app.mount(f"/", StaticFiles(directory=STATIC_PATH), name=STATIC_DIRNAME)


def create_globals(scconf: yacman.YAMLConfigManager):
"""
Create global variables for the app to use.
"""
print(scconf)
_LOGGER.info(f"Connecting to database... {scconf.exp['database']['host']}")
global schenge

pgdb = RDBDict(
db_name=scconf.exp["database"]["name"],
db_user=scconf.exp["database"]["user"],
db_password=scconf.exp["database"]["password"],
db_host=scconf.exp["database"]["host"],
db_port=scconf.exp["database"]["port"],
db_table=scconf.exp["database"]["table"],
)
_LOGGER.info(f"Using schema: {scconf['schemas']}")
schenge = SeqColHenge(
database=pgdb,
schemas=scconf["schemas"],
)
return schenge
# def create_globals(scconf: yacman.YAMLConfigManager):
# """
# Create global variables for the app to use.
# """
# print(scconf)
# _LOGGER.info(f"Connecting to database... {scconf.exp['database']['host']}")
# global schenge

# pgdb = RDBDict(
# db_name=scconf.exp["database"]["name"],
# db_user=scconf.exp["database"]["user"],
# db_password=scconf.exp["database"]["password"],
# db_host=scconf.exp["database"]["host"],
# db_port=scconf.exp["database"]["port"],
# db_table=scconf.exp["database"]["table"],
# )
# _LOGGER.info(f"Using schema: {scconf['schemas']}")
# schenge = SeqColHenge(
# database=pgdb,
# schemas=scconf["schemas"],
# )
# return schenge


def create_global_dbagent():
Expand All @@ -146,29 +146,28 @@ def main(injected_args=None):

# _LOGGER = logmuse.logger_via_cli(args, make_root=True)
_LOGGER.info(f"args: {args}")
if "config" in args and args.config is not None:
scconf = SeqColConf.from_yaml_file(args.config)
create_globals(scconf)
app.state.schenge = schenge
app.state.dbagent = dbagent
port = args.port or scconf.exp["server"]["port"]
_LOGGER.info(f"Running on port {port}")
uvicorn.run(app, host=scconf.exp["server"]["host"], port=port)
else:
create_global_dbagent()
app.state.dbagent = dbagent
_LOGGER.error("Configure by passing -c SEQCOLAPI_CONFIG ")
# if "config" in args and args.config is not None:
# scconf = SeqColConf.from_yaml_file(args.config)
# create_globals(scconf)
# app.state.schenge = schenge
# app.state.dbagent = dbagent
# port = args.port or scconf.exp["server"]["port"]
# _LOGGER.info(f"Running on port {port}")
# uvicorn.run(app, host=scconf.exp["server"]["host"], port=port)
# else:
create_global_dbagent()
app.state.dbagent = dbagent


if __name__ != "__main__":
# Entrypoint for running through uvicorn CLI (dev)
if os.environ.get("SEQCOLAPI_CONFIG") is not None:
_LOGGER.info(f"Loading config from SEQCOLAPI_CONFIG: {os.environ.get('SEQCOLAPI_CONFIG')}")
scconf = SeqColConf.from_yaml_file(os.environ.get("SEQCOLAPI_CONFIG"))
create_globals(scconf)
app.state.schenge = schenge
app.state.dbagent = dbagent
else:
create_global_dbagent()
app.state.dbagent = dbagent
_LOGGER.error("Configure by setting SEQCOLAPI_CONFIG env var")
# if os.environ.get("SEQCOLAPI_CONFIG") is not None:
# _LOGGER.info(f"Loading config from SEQCOLAPI_CONFIG: {os.environ.get('SEQCOLAPI_CONFIG')}")
# scconf = SeqColConf.from_yaml_file(os.environ.get("SEQCOLAPI_CONFIG"))
# create_globals(scconf)
# app.state.schenge = schenge
# app.state.dbagent = dbagent
# else:
create_global_dbagent()
app.state.dbagent = dbagent
_LOGGER.error("Configure by setting SEQCOLAPI_CONFIG env var")

0 comments on commit 74b2511

Please sign in to comment.