From e3b980a3a8025b2e72df5085844afe1a9ff0751c Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 18 Dec 2023 13:33:58 +0100 Subject: [PATCH 1/4] MANIFEST.in file --- MANIFEST.in | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..5be19fd --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +recursive-include conf * +recursive-include static * +recursive-include templates * +include logging.conf +include config \ No newline at end of file -- 2.30.2 From aaa07afd541c20702b44c44d71eae96db2c4aba8 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 18 Dec 2023 15:04:00 +0100 Subject: [PATCH 2/4] Moved static files into /static --- config => amarillo/static/config | 0 logging.conf => amarillo/static/logging.conf | 0 {static => amarillo/static/static}/css/docs.css | 0 {static => amarillo/static/static}/css/theme.css | 0 {static => amarillo/static/static}/img/cloud.png | Bin {static => amarillo/static/static}/img/favicon.ico | Bin .../static/templates}/home/index.html | 0 .../static/templates}/shared/layout.html | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename config => amarillo/static/config (100%) rename logging.conf => amarillo/static/logging.conf (100%) rename {static => amarillo/static/static}/css/docs.css (100%) rename {static => amarillo/static/static}/css/theme.css (100%) rename {static => amarillo/static/static}/img/cloud.png (100%) rename {static => amarillo/static/static}/img/favicon.ico (100%) rename {templates => amarillo/static/templates}/home/index.html (100%) rename {templates => amarillo/static/templates}/shared/layout.html (100%) diff --git a/config b/amarillo/static/config similarity index 100% rename from config rename to amarillo/static/config diff --git a/logging.conf b/amarillo/static/logging.conf similarity index 100% rename from logging.conf rename to amarillo/static/logging.conf diff --git a/static/css/docs.css b/amarillo/static/static/css/docs.css similarity index 100% rename from static/css/docs.css rename to amarillo/static/static/css/docs.css diff --git a/static/css/theme.css b/amarillo/static/static/css/theme.css similarity index 100% rename from static/css/theme.css rename to amarillo/static/static/css/theme.css diff --git a/static/img/cloud.png b/amarillo/static/static/img/cloud.png similarity index 100% rename from static/img/cloud.png rename to amarillo/static/static/img/cloud.png diff --git a/static/img/favicon.ico b/amarillo/static/static/img/favicon.ico similarity index 100% rename from static/img/favicon.ico rename to amarillo/static/static/img/favicon.ico diff --git a/templates/home/index.html b/amarillo/static/templates/home/index.html similarity index 100% rename from templates/home/index.html rename to amarillo/static/templates/home/index.html diff --git a/templates/shared/layout.html b/amarillo/static/templates/shared/layout.html similarity index 100% rename from templates/shared/layout.html rename to amarillo/static/templates/shared/layout.html -- 2.30.2 From f02fb0cbd82a61d0f20adae608d979eac7d20fdc Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 18 Dec 2023 15:13:05 +0100 Subject: [PATCH 3/4] Update MANIFEST.in --- MANIFEST.in | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 5be19fd..5aae476 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1 @@ -recursive-include conf * -recursive-include static * -recursive-include templates * -include logging.conf -include config \ No newline at end of file +recursive-include amarillo/static/ * \ No newline at end of file -- 2.30.2 From f00692904c13af2fbd99f7a01e734fb83a335b95 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 18 Dec 2023 15:43:17 +0100 Subject: [PATCH 4/4] Copy static files to working directory --- .gitignore | 9 ++++++++- amarillo/app/main.py | 9 +++++++-- amarillo/app/utils/utils.py | 32 +++++++++++++++++++++++++++++++- pyproject.toml | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d9e645d..ebb9386 100644 --- a/.gitignore +++ b/.gitignore @@ -171,4 +171,11 @@ data/failed/ data/trash/ data/gtfs/ data/tmp/ -data/agencyconf \ No newline at end of file +data/agencyconf + + +#these files are under app/static but they get copied to the outside directory on startup +logging.conf +config +static/* +templates/* \ No newline at end of file diff --git a/amarillo/app/main.py b/amarillo/app/main.py index 746ece7..dd38764 100644 --- a/amarillo/app/main.py +++ b/amarillo/app/main.py @@ -6,14 +6,19 @@ import uvicorn import mimetypes from starlette.staticfiles import StaticFiles +logging.config.fileConfig('logging.conf', disable_existing_loggers=False) +logger = logging.getLogger("main") + +from amarillo.app.utils.utils import copy_static_files +#this has to run before app.configuration is imported, otherwise we get validation error for config because the config file is not copied yet +copy_static_files(["conf", "static", "templates", "logging.conf", "config"]) + import amarillo.plugins from amarillo.app.configuration import configure_services, configure_admin_token from amarillo.app.routers import carpool, agency, agencyconf, region from fastapi import FastAPI from amarillo.app.views import home -logging.config.fileConfig('logging.conf', disable_existing_loggers=False) -logger = logging.getLogger("main") # https://pydantic-docs.helpmanual.io/usage/settings/ # from amarillo.app.views import home diff --git a/amarillo/app/utils/utils.py b/amarillo/app/utils/utils.py index 51a48e6..1e6bde3 100644 --- a/amarillo/app/utils/utils.py +++ b/amarillo/app/utils/utils.py @@ -1,8 +1,15 @@ import os import re +import os +import shutil +from pathlib import Path +import logging + from datetime import datetime, date, timedelta from pyproj import Geod +logger = logging.getLogger(__name__) + def assert_folder_exists(foldername): if not os.path.isdir(foldername): os.makedirs(foldername) @@ -37,4 +44,27 @@ def geodesic_distance_in_m(coord1, coord2): geod = Geod(ellps="WGS84") lons = [coord1[0], coord2[0]] lats = [coord1[1], coord2[1]] - return geod.line_lengths(lons, lats)[0] \ No newline at end of file + return geod.line_lengths(lons, lats)[0] + + +def copy_static_files(files_and_dirs_to_copy): + amarillo_dir = Path(__file__).parents[2] + source_dir = os.path.join(amarillo_dir, "static") + + destination_dir = os.getcwd() + + for item in files_and_dirs_to_copy: + source_path = os.path.join(source_dir, item) + destination_path = os.path.join(destination_dir, item) + + if os.path.exists(destination_path): + # logger.info(f"{item} already exists") + continue + + if os.path.isfile(source_path): + shutil.copy2(source_path, destination_path) + logger.info(f"Copied {item} to {destination_path}") + + if os.path.isdir(source_path): + shutil.copytree(source_path, destination_path) + logger.info(f"Copied directory {item} and its contents to {destination_path}") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 87eb960..984a8eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amarillo-core" -version = "0.0.7" +version = "0.0.8" dependencies = [ "fastapi[all]==0.104.0", "geopandas==0.14", -- 2.30.2