From f60790290a00e0ffc4191dcd7300d97f08ce03e2 Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Thu, 2 Nov 2023 22:54:56 +0000 Subject: [PATCH] add contrib package --- atciss/app/tasks/ac_data.py | 13 +++++++++---- atciss/config/application.py | 1 + docker-compose.yml | 1 + flake.nix | 5 +++++ nixos/module.nix | 2 ++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/atciss/app/tasks/ac_data.py b/atciss/app/tasks/ac_data.py index 7f986a6a..bc83a787 100644 --- a/atciss/app/tasks/ac_data.py +++ b/atciss/app/tasks/ac_data.py @@ -1,5 +1,6 @@ from typing import Any, Dict, Optional, Sequence from uuid import UUID +import os.path from loguru import logger from pydantic import TypeAdapter @@ -199,20 +200,24 @@ def get_recat( return "A" +def contrib_ac_path(*pa: Sequence[str]) -> str: + return os.path.join(settings.CONTRIB_PATH, "ac-data", *pa) + + def read_manufacturers() -> Sequence[AcdbManufacturer]: - with open("contrib/ac-data/aircraft-db/manufacturers.json", "rb") as mf: + with open(contrib_ac_path("aircraft-db", "manufacturers.json"), "rb") as mf: return TypeAdapter(Sequence[AcdbManufacturer]).validate_json(mf.read()) def read_ac_types() -> Sequence[AcdbAcType]: - with open("contrib/ac-data/aircraft-db/aircraft-types.json", "rb") as tf: + with open(contrib_ac_path("aircraft-db", "aircraft-types.json"), "rb") as tf: return TypeAdapter(Sequence[AcdbAcType]).validate_json(tf.read()) def read_wtc_overrides() -> dict[str, Sequence[str]]: data = {} - with open("contrib/ac-data/wtc-overrides.txt", "r", encoding="utf-8") as of: + with open(contrib_ac_path("wtc-overrides.txt"), "r", encoding="utf-8") as of: for line in of.readlines(): [icao, wtc, recat] = line.split(",") data[icao] = [wtc.strip(), recat.strip()] @@ -221,7 +226,7 @@ def read_wtc_overrides() -> dict[str, Sequence[str]]: def read_own_types() -> Sequence[AircraftPerformanceData]: - with open("contrib/ac-data/ac-data.json", "rb") as df: + with open(contrib_ac_path("ac-data.json"), "rb") as df: return TypeAdapter(Sequence[AircraftPerformanceData]).validate_json(df.read()) diff --git a/atciss/config/application.py b/atciss/config/application.py index f0b5d562..9da07679 100644 --- a/atciss/config/application.py +++ b/atciss/config/application.py @@ -14,6 +14,7 @@ class Application(BaseSettings): LOG_LEVEL: str = "INFO" PROJECT_NAME: str = "atciss" VERSION: str = __version__ + CONTRIB_PATH: str = "./contrib" DOCS_URL: str = "/" BASE_URL: str = "http://localhost:8000" SECRET_KEY: str = "dc3101ed2074e87e3bf2b158fd0934cc538a5d667a96e0d400d8b4f6f572c33d" diff --git a/docker-compose.yml b/docker-compose.yml index b85e761a..7a83991a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,7 @@ services: ATCISS_REDIS_HOST: redis volumes: - ./atciss:/code/atciss + - ./contrib:/code/contrib depends_on: - redis diff --git a/flake.nix b/flake.nix index 9b59c634..b02c5522 100644 --- a/flake.nix +++ b/flake.nix @@ -133,6 +133,10 @@ ''; }; + atciss-contrib = final.runCommand "atciss-contrib" {} '' + cp -r ${self}/contrib $out + ''; + poetry = prev.poetry.override (_: { inherit python; }); @@ -153,6 +157,7 @@ packages = { default = pkgs.atciss; backend = pkgs.atciss; + contrib = pkgs.atciss-contrib; frontend = pkgs.atciss-frontend; image = pkgs.dockerTools.buildImage { diff --git a/nixos/module.nix b/nixos/module.nix index c916844f..f5829b25 100644 --- a/nixos/module.nix +++ b/nixos/module.nix @@ -72,6 +72,7 @@ in { inherit ATCISS_DEBUG; ATCISS_BASE_URL = "https://${cfg.host}"; ATCISS_DATABASE_DSN = "postgresql+asyncpg://localhost/atciss?host=/run/postgresql"; + ATCISS_CONTRIB_PATH = pkgs.atciss-contrib; }; serviceConfig = { @@ -92,6 +93,7 @@ in { environment = { inherit ATCISS_DEBUG; ATCISS_DATABASE_DSN = "postgresql+asyncpg://localhost/atciss?host=/run/postgresql"; + ATCISS_CONTRIB_PATH = pkgs.atciss-contrib; }; serviceConfig = {