diff --git a/app.py b/app.py index 3672fe02..400d73b6 100644 --- a/app.py +++ b/app.py @@ -29,6 +29,22 @@ ORIGINS = app.config.get("ORIGINS") SSL = app.config.get("SSL") + +def get_db_path_from_config(): + database_uri = app.config.get("SQLALCHEMY_DATABASE_URI", "") + if database_uri.startswith("sqlite:///"): + return database_uri.replace("sqlite:///", "") + return None + + +db_path = get_db_path_from_config() +if db_path: + db_dir = os.path.dirname(db_path) + if db_dir and not os.path.exists(db_dir): + os.makedirs(db_dir, exist_ok=True) + init_database(db_path) + print(f"Database initialized at: {db_path}") + flask_cors.CORS(app, origins=ORIGINS) app.register_blueprint( blueprint_routes.routes, @@ -58,6 +74,6 @@ def return_error(): # ''' Main ''' if __name__ == "__main__": - init_database(app) - print(f"Python is running in {FLASK_DEBUG} mode") + data_folder = app.config.get("DATA_FOLDER_PATH") + upload_folder = app.config.get("UPLOAD_FOLDER") app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL) diff --git a/requirements.in b/requirements.in index b9c6544f..14d45e01 100644 --- a/requirements.in +++ b/requirements.in @@ -7,5 +7,4 @@ geode-common==33.11.0 geode-viewables==3.3.0 Flask[async]==3.0.3 Flask-Cors==6.0.1 -werkzeug==3.0.3 -Flask-SQLAlchemy==3.1.1 \ No newline at end of file +werkzeug==3.0.3 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ba9756e8..d32a13d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,55 +2,34 @@ # This file is autogenerated by pip-compile with Python 3.12 # by the following command: # -# pip-compile --output-file=./requirements.txt --pre ./requirements-internal.in ./requirements.in +# pip-compile --output-file=./requirements.txt --pre ./requirements.in # asgiref~=3.0 # via flask blinker~=1.0 - # via - # flask - # opengeodeweb-microservice + # via flask click~=8.0 - # via - # flask - # opengeodeweb-microservice -fastjsonschema~=2.0 - # via opengeodeweb-microservice + # via flask flask[async]~=3.0 # via # -r requirements.in # flask # flask-cors - # flask-sqlalchemy - # opengeodeweb-microservice flask-cors~=6.0 # via -r requirements.in -flask-sqlalchemy~=3.0 - # via - # -r requirements.in - # opengeodeweb-microservice geode-common==33.11.0 # via # -r requirements.in # geode-viewables geode-viewables==3.3.0 # via -r requirements.in -greenlet~=3.0 - # via - # opengeodeweb-microservice - # sqlalchemy itsdangerous~=2.0 - # via - # flask - # opengeodeweb-microservice + # via flask jinja2~=3.0 - # via - # flask - # opengeodeweb-microservice + # via flask markupsafe~=3.0 # via # jinja2 - # opengeodeweb-microservice # werkzeug opengeode-core==15.27.4 # via @@ -75,19 +54,8 @@ opengeode-io==7.4.0 # -r requirements.in # geode-viewables # opengeode-geosciencesio -opengeodeweb-microservice~=1.0 - # via -r requirements-internal.in -sqlalchemy~=2.0 - # via - # flask-sqlalchemy - # opengeodeweb-microservice -typing-extensions~=4.0 - # via - # opengeodeweb-microservice - # sqlalchemy werkzeug==3.0.3 # via # -r requirements.in # flask # flask-cors - # opengeodeweb-microservice diff --git a/src/opengeodeweb_back/app_config.py b/src/opengeodeweb_back/app_config.py index 453a0eda..095b2754 100644 --- a/src/opengeodeweb_back/app_config.py +++ b/src/opengeodeweb_back/app_config.py @@ -4,9 +4,6 @@ # Third party imports # Local application imports -from opengeodeweb_microservice.database.connection import get_database - -DATABASE_FILENAME = "project.db" class Config(object): @@ -18,7 +15,7 @@ class Config(object): REQUEST_COUNTER = 0 LAST_REQUEST_TIME = time.time() LAST_PING_TIME = time.time() - SQLALCHEMY_TRACK_MODIFICATIONS = False + DATABASE_FILENAME = "project.db" class ProdConfig(Config): @@ -27,9 +24,6 @@ class ProdConfig(Config): MINUTES_BEFORE_TIMEOUT = "1" SECONDS_BETWEEN_SHUTDOWNS = "10" DATA_FOLDER_PATH = "/data" - SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.abspath( - os.path.join(DATA_FOLDER_PATH, DATABASE_FILENAME) - )}" class DevConfig(Config): @@ -39,6 +33,3 @@ class DevConfig(Config): SECONDS_BETWEEN_SHUTDOWNS = "10" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) DATA_FOLDER_PATH = os.path.join(BASE_DIR, "data") - SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.join( - BASE_DIR, DATA_FOLDER_PATH, DATABASE_FILENAME - )}" diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index ab3d05bf..92633d03 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -88,7 +88,6 @@ def validate_request(request: flask.Request, schema: dict[str, str]) -> None: if json_data is None: json_data = {} - try: validate = fastjsonschema.compile(schema) validate(json_data) @@ -259,10 +258,6 @@ def generate_native_viewable_and_light_viewable_from_file( data = geode_functions.load(geode_object, copied_full_path) - # Remplacer : - # database.session.delete(temp_data_entry) - # database.session.flush() - # Par : session = get_session() if session: session.delete(temp_data_entry) diff --git a/tests/conftest.py b/tests/conftest.py index e9b41626..2b4f9cc3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,10 +28,7 @@ def copy_data(): print("Current working directory:", os.getcwd()) print("Directory contents:", os.listdir(".")) - init_database(app) - # print(list(app.blueprints.keys())) - # for rule in app.url_map.iter_rules(): - # print(f"Route: {rule.rule} -> {rule.endpoint}") + init_database(db_path) @pytest.fixture