Skip to content

Commit

Permalink
Switch to ENV config
Browse files Browse the repository at this point in the history
  • Loading branch information
anergictcell committed Jul 28, 2023
1 parent 15c7d4e commit 7f53918
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
20 changes: 14 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ The easiest way to install PyHPO-API is via pip
pip install pyhpoapi
.. note::

**PyHPO-API** ships with ``pyhpo`` as the underlying Ontology by default. it is also possible to use `hpo3 <https://pypi.org/project/hpo3/>`_ instead. ``hpo3`` is a drop-in replacement of ``pyhpo`` written in Rust and is much faster. It is not 100% feature complete, so use it with caution. To switch to ``hpo3`` unintstall pyhpo and then install hpo3

.. code:: bash
pip uninstall -y pyhpo
pip install hpo3
Usage
=====

Expand Down Expand Up @@ -53,13 +63,11 @@ you can run PyHPO-API with multiple workers

CORS
----
If you need to allow cross-origin requests, you can simply create
a ``config.ini`` file in your working directory and specify CORS settings::
If you need to allow cross-origin requests, you specify CORS settings through environment variables::

[default]
cors-origins = *
cors-methods = GET,POST
cors-headers = *
export PYHPOAPI_CORS_ORIGINS="*"
export PYHPOAPI_CORS_METHODS="GET,POST"
export PYHPOAPI_CORS_HEADERS="*"


Dev
Expand Down
22 changes: 7 additions & 15 deletions pyhpoapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import os
import configparser
from typing import Any, List


Expand All @@ -15,27 +14,20 @@ def config_item_list(value: str, convert=str) -> List[Any]:
return [convert(x) for x in value.split(',')]


local_config = os.path.join(
os.getcwd(),
'config.ini'
)
VERSION = "2.0.0"


config = configparser.ConfigParser()
if os.path.exists(local_config):
config.read(local_config)


VERSION = config.get('default', 'version', fallback='1.2.2')
MASTER_DATA = os.environ.get("PYHPOAPI_DATA_DIR", "")

CORS_ORIGINS = config_item_list(
config.get('default', 'cors-origins', fallback='')
os.environ.get("PYHPOAPI_CORS_ORIGINS", "")
)

CORS_METHODS = config_item_list(
config.get('default', 'cors-methods', fallback='')
os.environ.get("PYHPOAPI_CORS_METHODS", "")
)

CORS_HEADERS = config_item_list(
config.get('default', 'cors-headers', fallback='')
os.environ.get("PYHPOAPI_CORS_HEADERS", "")
)

OPENAPI_TAGS = [
Expand Down
11 changes: 8 additions & 3 deletions pyhpoapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ def custom_openapi():


def initialize_ontology() -> None:
data_dir = os.environ.get("PYHPOAPI_DATA_DIR", "")
logger.debug(f"Loading Ontology from {data_dir}")
data_dir = config.MASTER_DATA

if data_dir == "":
logger.debug("Using builtin standard ontology")
_ = Ontology()
else:
logger.info(f"Loading Ontology from {data_dir}")
_ = Ontology(data_dir)

_ = Ontology(data_dir)
terms.gene_model = EnrichmentModel('gene')
terms.omim_model = EnrichmentModel('omim')
terms.hpo_model_genes = HPOEnrichment('gene')
Expand Down

0 comments on commit 7f53918

Please sign in to comment.