annif.datadir.DatadirMixin.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 4
1
"""Mixin class for types that need a data directory"""
2
3
from __future__ import annotations
4
5
import os
6
import os.path
7
8
9
class DatadirMixin:
10
    """Mixin class for types that need a data directory for storing files"""
11
12
    def __init__(self, datadir: str, typename: str, identifier: str) -> None:
13
        self._datadir_path = os.path.join(datadir, typename, identifier)
14
15
    @property
16
    def datadir(self) -> str:
17
        if not os.path.exists(self._datadir_path):
18
            try:
19
                os.makedirs(self._datadir_path)
20
            except FileExistsError:
21
                # apparently the datadir was created by another thread!
22
                pass
23
        return self._datadir_path
24