Skip to content

Commit

Permalink
Supply a package_base_dir when instantiating UbkgAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckKollar committed Mar 26, 2024
1 parent 4688bba commit a3a18f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/ubkg_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@


class UbkgAPI:
def __init__(self, config):
def __init__(self, config, package_base_dir):
"""
If config is a string then it will be treated as a local file path from which to load a file, e.g.
ubkg_app = UbkgAPI('./app.cfg').app
ubkg_app = UbkgAPI('./app.cfg', package_bease_dir).app
If config is a Flask.config then it will be used directly, e.g.
config = Flask(__name__,
instance_path=path.join(path.abspath(path.dirname(__file__)), 'instance'),
instance_relative_config=True)\
.config.from_pyfile('app.cfg')
The 'package_base_dir' is the base directory of the package (e.g., the directory in which
the VERSION and BUILD files are located.
"""

self.app = Flask(__name__,
instance_path=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance'),
instance_relative_config=True)

self.app.package_base_dir = package_base_dir
logger.info(f"package_base_dir: {package_base_dir}")

self.app.register_blueprint(codes_blueprint)
self.app.register_blueprint(concepts_blueprint)
self.app.register_blueprint(semantics_blueprint)
Expand Down Expand Up @@ -101,7 +107,7 @@ def index():

if __name__ == "__main__":
try:
ubkg_app = UbkgAPI('./app.cfg').app
ubkg_app = UbkgAPI('./app.cfg', Path(__file__).absolute().parent.parent.parent).app
ubkg_app.run(host='0.0.0.0', port="5002")
except Exception as e:
print("Error during starting debug server.")
Expand Down
5 changes: 2 additions & 3 deletions src/ubkg_api/common_routes/status/status_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from flask import Blueprint, jsonify, current_app
from pathlib import Path

status_blueprint = Blueprint('status', __name__, url_prefix='/status')

Expand All @@ -16,12 +15,12 @@
def get_status():

try:
file_version_content = (Path(__file__).absolute().parent.parent.parent.parent.parent / 'VERSION').read_text().strip()
file_version_content = (current_app.package_base_dir / 'VERSION').read_text().strip()
except Exception as e:
file_version_content = str(e)

try:
file_build_content = (Path(__file__).absolute().parent.parent.parent.parent.parent / 'BUILD').read_text().strip()
file_build_content = (current_app.package_base_dir / 'BUILD').read_text().strip()
except Exception as e:
file_build_content = str(e)

Expand Down

0 comments on commit a3a18f6

Please sign in to comment.