Skip to content

Commit

Permalink
add contrib package
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz committed Nov 2, 2023
1 parent d7f92c2 commit f607902
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
13 changes: 9 additions & 4 deletions atciss/app/tasks/ac_data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()]
Expand All @@ -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())


Expand Down
1 change: 1 addition & 0 deletions atciss/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ services:
ATCISS_REDIS_HOST: redis
volumes:
- ./atciss:/code/atciss
- ./contrib:/code/contrib
depends_on:
- redis

Expand Down
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
'';
};

atciss-contrib = final.runCommand "atciss-contrib" {} ''
cp -r ${self}/contrib $out
'';

poetry = prev.poetry.override (_: {
inherit python;
});
Expand All @@ -153,6 +157,7 @@
packages = {
default = pkgs.atciss;
backend = pkgs.atciss;
contrib = pkgs.atciss-contrib;
frontend = pkgs.atciss-frontend;

image = pkgs.dockerTools.buildImage {
Expand Down
2 changes: 2 additions & 0 deletions nixos/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down

0 comments on commit f607902

Please sign in to comment.