Skip to content

Commit

Permalink
TLDR-369 change version saving
Browse files Browse the repository at this point in the history
  • Loading branch information
NastyBoget committed Jul 31, 2023
1 parent 6febe3e commit 1fc0371
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 31 deletions.
6 changes: 3 additions & 3 deletions dedoc/api/dedoc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse

import dedoc
from dedoc.api.api_args import QueryParameters
from dedoc.api.api_utils import json2html, json2tree, json2collapsed_tree
from dedoc.common.exceptions.dedoc_exception import DedocException
from dedoc.common.exceptions.missing_file_exception import MissingFileException
from dedoc.config import get_config
from dedoc.dedoc_manager import DedocManager
from dedoc.utils.utils import save_upload_file
from dedoc.utils.version_utils import get_dedoc_version

config = get_config()
PORT = config["api_port"]
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_static_file(request: Request) -> Response:

@app.get('/version')
def get_version() -> Response:
return PlainTextResponse(get_dedoc_version())
return PlainTextResponse(dedoc.__version__)


def _get_static_file_path(request: Request) -> str:
Expand All @@ -65,7 +65,7 @@ async def upload(file: UploadFile = File(...), query_params: QueryParameters = D
parameters = query_params.dict(by_alias=True)

if not file or file.filename == "":
raise MissingFileException("Error: Missing content in request_post file parameter", version=get_dedoc_version())
raise MissingFileException("Error: Missing content in request_post file parameter", version=dedoc.__version__)
# check if the post request_post has the file part

logger.info(f"Get file {file.filename} with parameters {parameters}")
Expand Down
4 changes: 2 additions & 2 deletions dedoc/common/exceptions/dedoc_exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from dedoc.utils.version_utils import get_dedoc_version
import dedoc


class DedocException(Exception):
Expand All @@ -14,7 +14,7 @@ def __init__(self,
self.msg = msg
self.msg_api = msg if msg_api is None else msg_api
self.filename = filename
self.version = version if version is not None else get_dedoc_version()
self.version = version if version is not None else dedoc.__version__
self.metadata = metadata

def __str__(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions dedoc/data_structures/parsed_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from flask_restx import fields, Api, Model

import dedoc
from dedoc.data_structures.document_content import DocumentContent
from dedoc.data_structures.document_metadata import DocumentMetadata
from dedoc.data_structures.serializable import Serializable
from dedoc.utils.version_utils import get_dedoc_version


class ParsedDocument(Serializable):
Expand All @@ -27,7 +27,7 @@ def __init__(self,
self.metadata = metadata
self.content = content
self.attachments = [] if attachments is None else attachments
self.version = get_dedoc_version()
self.version = dedoc.__version__
self.warnings = warnings if warnings is not None else []

def add_attachments(self, new_attachment: List["ParsedDocument"]) -> None:
Expand Down
1 change: 1 addition & 0 deletions dedoc/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def get_unique_name(filename: str) -> str:

def save_upload_file(upload_file: UploadFile, output_dir: str) -> str:
file_name = upload_file.filename.split("/")[-1]
file_name = check_filename_length(file_name)
file_path = os.path.join(output_dir, file_name)
try:
with open(file_path, "wb") as buffer:
Expand Down
21 changes: 0 additions & 21 deletions dedoc/utils/version_utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN mkdir /dedoc_root
ADD dedoc /dedoc_root/dedoc
ADD VERSION /dedoc_root

RUN python3 /dedoc_root/dedoc/utils/version_utils.py
RUN echo "__version__ = \"$(cat /dedoc_root/VERSION)\"" > /dedoc_root/dedoc/version.py
RUN python3 /dedoc_root/dedoc/download_models.py

ADD tests /dedoc_root/tests
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import os

from setuptools import setup

from dedoc.utils.version_utils import get_dedoc_version

if __name__ == "__main__":
setup(name="dedoc", version=get_dedoc_version())
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "VERSION"), "r") as f:
version = f.read()

# Dynamically set the __version__ attribute
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "dedoc", "version.py"), "w", encoding="utf-8") as f:
f.write(f'__version__ = "{version}"\n')
setup(name="dedoc", version=version)

0 comments on commit 1fc0371

Please sign in to comment.