Skip to content

Commit

Permalink
refactor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lunakv committed Oct 1, 2023
1 parent 7d195cc commit 2bd1526
Show file tree
Hide file tree
Showing 46 changed files with 292 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/static/raw_docs
.env
.idea/
venv/
dist/
114 changes: 103 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ skip_gitignore = true
name = "academyruins-api"
version = "0.5.0"
description = ""
authors = ["Your Name <you@example.com>"]
authors = ["Václav Luňák < >"]
readme = "README.md"

[tool.poetry.scripts]
academyruins = "src.cli_scripts.run:app"

[tool.poetry.dependencies]
python = "^3.10"
fastapi = { extras = ["all"], version = "^0.103.2" }
logging = "^0.4.9.6"
APScheduler = "^3.9.1"
boto3 = "^1.24.84"
pydantic = "^2.4.2"
Expand Down
12 changes: 6 additions & 6 deletions src/admin/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Response
from sqlalchemy.orm import Session

from admin import service
from db import get_db
from extractor.cr.refresh_cr import refresh_cr
from extractor.ipg.refresh_ipg import refresh_ipg
from extractor.mtr.refresh_mtr import refresh_mtr
from schemas import ResponseModel
from src.admin import service
from src.db import get_db
from src.extractor.cr.refresh_cr import refresh_cr
from src.extractor.ipg.refresh_ipg import refresh_ipg
from src.extractor.mtr.refresh_mtr import refresh_mtr
from src.schemas import ResponseModel

router = APIRouter(include_in_schema=False)

Expand Down
10 changes: 5 additions & 5 deletions src/admin/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sqlalchemy import select
from sqlalchemy.orm import Session

from cr.models import Cr, PendingCr
from diffs.models import CrDiff, CrDiffItem, MtrDiff, PendingCrDiff, PendingMtrDiff
from link.models import PendingRedirect, Redirect
from mtr.models import Mtr, PendingMtr
from mtr.service import get_pending_mtr
from src.cr.models import Cr, PendingCr
from src.diffs.models import CrDiff, CrDiffItem, MtrDiff, PendingCrDiff, PendingMtrDiff
from src.link.models import PendingRedirect, Redirect
from src.mtr.models import Mtr, PendingMtr
from src.mtr.service import get_pending_mtr


def apply_pending_redirect(db: Session, resource: str) -> str | None:
Expand Down
20 changes: 10 additions & 10 deletions create_cr_and_diff.py → src/cli_scripts/create_cr_and_diff.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import os

from difftool.diffmaker import CRDiffMaker
from extractor.cr import extract_cr
from extractor.formatter import CRFormatterFactory
from src.difftool.diffmaker import CRDiffMaker
from src.extractor.cr import extract_cr
from src.extractor.formatter import CRFormatterFactory


def diff(old_txt, new_txt, old_set_code=None, new_set_code=None, forced_matches=None):
Expand Down Expand Up @@ -67,13 +67,13 @@ def diffall():
diff_save(old, new)


cr_in_dir = "src/static/raw_docs/cr"
cr_out_dir = "./gen/cr"
diff_dir = "./gen/diff_unchecked"
maps_dir = "./gen/map"
gloss_dir = "./gen/gloss"
key_dir = "./gen/keywords"
toc_dir = "./gen/toc"
cr_in_dir = "../static/raw_docs/cr"
cr_out_dir = "../../gen/cr"
diff_dir = "../../gen/diff_unchecked"
maps_dir = "../../gen/map"
gloss_dir = "../../gen/gloss"
key_dir = "../../gen/keywords"
toc_dir = "../../gen/toc"

if __name__ == "__main__":
# diffall()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from dotenv import load_dotenv

from difftool.diffmaker import MtrDiffMaker
from extractor.mtr.extract_mtr import extract
from src.difftool.diffmaker import MtrDiffMaker
from src.extractor.mtr.extract_mtr import extract

load_dotenv()

Expand Down Expand Up @@ -47,8 +47,8 @@ def diff_save(old: str, new: str):
file.write(mtr_to_text(new_date, new_sections))


mtr_out_dir = Path(".") / "gen" / "mtr"
mtr_diff_dir = Path(".") / "gen" / "mtr-diff"
mtr_out_dir = Path("../..") / "gen" / "mtr"
mtr_diff_dir = Path("../..") / "gen" / "mtr-diff"

batch_input = [
# "2023-03-29",
Expand All @@ -66,7 +66,7 @@ def diff_save(old: str, new: str):


def diff_batch():
mtrdir = Path("mtr")
mtrdir = Path("../../mtr")
for i in range(1, len(batch_input)):
old = mtrdir / ("mtr-" + batch_input[i] + ".pdf")
new = mtrdir / ("mtr-" + batch_input[i - 1] + ".pdf")
Expand Down
35 changes: 35 additions & 0 deletions src/cli_scripts/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Annotated, Union

import typer
import uvicorn
from dotenv import load_dotenv

app = typer.Typer()


@app.command()
def run(
port: int = 8000,
host: str = "localhost",
reload: Annotated[
bool, typer.Option(help="Whether the server should automatically restart on file change.")
] = False,
):
"""
Start the API web server.
"""
uvicorn.run("src.main:app", port=port, host=host, reload=reload)


@app.callback()
def options(
envfile: Annotated[
Union[str, None], typer.Option(help="Optional location of a .env file that should be loaded")
] = None
):
if envfile:
load_dotenv(dotenv_path=envfile)


if __name__ == "__main__":
app()
2 changes: 1 addition & 1 deletion src/cr/keyword_def.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from cr import service as cr_service
from src.cr import service as cr_service

keyword_regex = r"702.(?:[2-9]|\d\d+)"
keyword_action_regex = r"701.(?:[2-9]|\d\d+)"
Expand Down
2 changes: 1 addition & 1 deletion src/cr/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import Column, Date, Integer, String, Text
from sqlalchemy.dialects.postgresql import JSONB

from models import Base
from src.models import Base


class Cr(Base):
Expand Down
16 changes: 8 additions & 8 deletions src/cr/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from sqlalchemy.orm import Session
from thefuzz import fuzz, process

from cr import schemas, service
from cr.keyword_def import get_best_rule
from db import get_db
from openapi.no422 import no422
from openapi.strings import crTag, filesTag
from resources import static_paths as paths
from resources.cache import GlossaryCache
from schemas import Error, FileFormat
from src.cr import schemas, service
from src.cr.keyword_def import get_best_rule
from src.db import get_db
from src.openapi.no422 import no422
from src.openapi.strings import crTag, filesTag
from src.resources import static_paths as paths
from src.resources.cache import GlossaryCache
from src.schemas import Error, FileFormat

router = APIRouter()
glossary = GlossaryCache()
Expand Down
6 changes: 3 additions & 3 deletions src/cr/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pydantic import Field

from diffs.schemas import CrDiffMetadata
from schemas import Error, ResponseModel
from src.diffs.schemas import CrDiffMetadata
from src.schemas import Error, ResponseModel


class RuleError(Error):
Expand Down Expand Up @@ -72,6 +72,6 @@ class TraceDiffRule(ResponseModel):

class TraceItem(ResponseModel):
action: TraceItemAction
old: TraceDiffRule | None
old: TraceDiffRule | None = None
new: TraceDiffRule
diff: CrDiffMetadata
Loading

0 comments on commit 2bd1526

Please sign in to comment.