annif.datadir   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A DatadirMixin.__init__() 0 2 1
A DatadirMixin.datadir() 0 9 3
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