diff --git a/server/migrations/env.py b/server/migrations/env.py index a2b335c7..f2f9e85d 100644 --- a/server/migrations/env.py +++ b/server/migrations/env.py @@ -7,7 +7,7 @@ from scimodom.database.database import Base import scimodom.database.models # noqa -from scimodom.config import get_config +from scimodom.config import set_config_from_environment, get_config # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -33,6 +33,7 @@ def get_database_url() -> str: + set_config_from_environment() return get_config().DATABASE_URI diff --git a/server/src/scimodom/config.py b/server/src/scimodom/config.py index 7ca8d240..929463d7 100644 --- a/server/src/scimodom/config.py +++ b/server/src/scimodom/config.py @@ -109,10 +109,10 @@ class _Config(Config): NOTIFICATION_ADDRESS = get_required_parameter("NOTIFICATION_ADDRESS") HTTP_PUBLIC_URL = get_required_parameter("HTTP_PUBLIC_URL") - FLASK_DEBUG = eval(os.getenv("FLASK_DEBUG", Config.FLASK_DEBUG)) + FLASK_DEBUG = eval(os.getenv("FLASK_DEBUG", str(Config.FLASK_DEBUG))) SESSION_COOKIE_SAMESITE = os.getenv("SESSION_COOKIE_SAMESITE") SESSION_COOKIE_SECURE = eval( - os.getenv("SESSION_COOKIE_SECURE", Config.SESSION_COOKIE_SECURE) + os.getenv("SESSION_COOKIE_SECURE", str(Config.SESSION_COOKIE_SECURE)) ) JWT_SECRET_KEY = SECRET_KEY diff --git a/server/src/scimodom/services/annotation/generic.py b/server/src/scimodom/services/annotation/generic.py index 3c35611f..3e48fa40 100644 --- a/server/src/scimodom/services/annotation/generic.py +++ b/server/src/scimodom/services/annotation/generic.py @@ -141,7 +141,7 @@ def get_release_path(self, annotation: Annotation) -> Path: ).scalar_one() organism_name = "_".join(organism_name.lower().split()).capitalize() assembly_name = self._assembly_service.get_name_for_version(annotation.taxa_id) - path = self._file_service.get_annotation_dir() + path = self._file_service.get_annotation_parent_dir() return Path(path, organism_name, assembly_name, str(annotation.release)) def _release_exists(self, annotation_id) -> bool: diff --git a/server/src/scimodom/services/annotation/gtrnadb.py b/server/src/scimodom/services/annotation/gtrnadb.py index abaae012..01781a99 100644 --- a/server/src/scimodom/services/annotation/gtrnadb.py +++ b/server/src/scimodom/services/annotation/gtrnadb.py @@ -151,7 +151,7 @@ def _patch_annotation(self, annotation_file: Path, seqids: list[str]): # TODO def _update_annotation(self, domain, fasta_file): - annotation_path = self._file_service.get_annotation_dir() + annotation_path = self._file_service.get_annotation_parent_dir() model_file = Path(annotation_path, domain).with_suffix(".cm").as_posix() sprinzl_file = Path(annotation_path, domain).with_suffix(".txt").as_posix() self._external_service.get_sprinzl_mapping(model_file, fasta_file, sprinzl_file) diff --git a/server/src/scimodom/services/file.py b/server/src/scimodom/services/file.py index cd054c52..67e4f4da 100644 --- a/server/src/scimodom/services/file.py +++ b/server/src/scimodom/services/file.py @@ -53,11 +53,16 @@ def __init__( self._import_path = import_path for path in [ + data_path, temp_path, upload_path, - self._get_gene_cache_dir(), - self.get_annotation_dir(), + import_path, self.get_project_metadata_dir(), + self._get_project_request_dir(), + self.get_annotation_parent_dir(), + self.get_assembly_parent_dir(), + self._get_gene_cache_dir(), + self.get_bam_files_parent_dir(), ]: makedirs(path, exist_ok=True) @@ -83,7 +88,7 @@ def open_import_file(self, name: str): # annotation - def get_annotation_dir(self) -> Path: + def get_annotation_parent_dir(self) -> Path: """Construct parent path to annotation files. :returns: Path to annotation @@ -190,6 +195,14 @@ def _get_project_request_dir(self): # Assembly + def get_assembly_parent_dir(self) -> Path: + """Construct parent path to assembly files. + + :returns: Path to assembly + :rtype: Path + """ + return Path(self._data_path, "assembly") + def get_assembly_file_path( self, taxa_id: int, @@ -301,8 +314,7 @@ def _get_dir_name_from_organism(organism) -> str: def _get_assembly_dir(self, taxa_id: int, assembly_name: str) -> Path: organism = self._get_organism_from_taxa_id(taxa_id) return Path( - self._data_path, - "assembly", + self.get_assembly_parent_dir(), self._get_dir_name_from_organism(organism), assembly_name, ) @@ -378,6 +390,14 @@ def get_temp_path(self) -> str: # BAM file + def get_bam_files_parent_dir(self): + """Construct parent path to BAM files. + + :returns: Path to BAM files + :rtype: Path + """ + return Path(self._data_path, "bam_files") + def create_or_update_bam_file( self, dataset: Dataset, @@ -419,11 +439,14 @@ def _update_bam_file(self, bam_file, data_stream, max_size): def _get_bam_file_tmp_path(self, bam_file): return join( - join(self._data_path, "bam_files"), f"tmp.{bam_file.storage_file_name}" + self.get_bam_files_parent_dir().as_posix(), + f"tmp.{bam_file.storage_file_name}", ) def _get_bam_file_path(self, bam_file): - return join(join(self._data_path, "bam_files"), bam_file.storage_file_name) + return join( + self.get_bam_files_parent_dir().as_posix(), bam_file.storage_file_name + ) @staticmethod def _handle_upload_error(exception, path): diff --git a/server/tests/integration/services/test_file_service.py b/server/tests/integration/services/test_file_service.py index cb111acb..34a58173 100644 --- a/server/tests/integration/services/test_file_service.py +++ b/server/tests/integration/services/test_file_service.py @@ -68,7 +68,7 @@ def test_count_lines(Session, tmp_path): def test_get_annotation_path(Session, tmp_path): service = _get_file_service(Session, tmp_path) - assert service.get_annotation_dir() == Path(tmp_path, "t_data", "annotation") + assert service.get_annotation_parent_dir() == Path(tmp_path, "t_data", "annotation") def test_update_gene_cache(Session, tmp_path): diff --git a/server/tests/unit/services/test_ensembl_annotation.py b/server/tests/unit/services/test_ensembl_annotation.py index b46d3270..1a4851a1 100644 --- a/server/tests/unit/services/test_ensembl_annotation.py +++ b/server/tests/unit/services/test_ensembl_annotation.py @@ -79,7 +79,7 @@ def get_assembly_file_path( return Path(f"/data/assembly/{taxa_id}/{file_type.value}") @staticmethod - def get_annotation_dir(): + def get_annotation_parent_dir(): return "/data/annotation"