From a3a18f695baec4990473a5a6f29f6bed4f3cb133 Mon Sep 17 00:00:00 2001 From: ChuckKollar Date: Tue, 26 Mar 2024 16:42:59 -0400 Subject: [PATCH] Supply a package_base_dir when instantiating UbkgAPI --- src/ubkg_api/app.py | 12 +++++++++--- .../common_routes/status/status_controller.py | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ubkg_api/app.py b/src/ubkg_api/app.py index 78ef73f..b0b5175 100644 --- a/src/ubkg_api/app.py +++ b/src/ubkg_api/app.py @@ -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) @@ -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.") diff --git a/src/ubkg_api/common_routes/status/status_controller.py b/src/ubkg_api/common_routes/status/status_controller.py index ea98e42..b190329 100644 --- a/src/ubkg_api/common_routes/status/status_controller.py +++ b/src/ubkg_api/common_routes/status/status_controller.py @@ -1,5 +1,4 @@ from flask import Blueprint, jsonify, current_app -from pathlib import Path status_blueprint = Blueprint('status', __name__, url_prefix='/status') @@ -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)