Skip to content

Commit 61a8845

Browse files
committed
config: mkdir -p $(basename)
1 parent a05ecf4 commit 61a8845

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

ocrd/ocrd/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
from yaml import safe_load, safe_dump
55

66
from ocrd_models import OcrdConfig
7-
from ocrd_utils import XDG_CONFIG_HOME, VERSION
7+
from ocrd_utils import VERSION
8+
import ocrd_utils
89
from ocrd_validators import OcrdConfigValidator
910
from ocrd_models.ocrd_config import DEFAULT_CONFIG
1011

11-
def load_config_file():
12+
def load_config_file(basedir=None):
1213
"""
1314
Load the configuration file
1415
"""
15-
fpath = Path(XDG_CONFIG_HOME, 'ocrd', 'config.yml')
16+
if not basedir:
17+
basedir = ocrd_utils.XDG_CONFIG_HOME
18+
fpath = Path(basedir, 'ocrd', 'config.yml')
1619
if not fpath.parent.exists():
17-
fpath.parent.mkdir()
20+
fpath.parent.mkdir(parents=True)
1821
obj = DEFAULT_CONFIG
1922
if not fpath.exists():
2023
with open(str(fpath), 'w', encoding='utf-8') as f_out:

tests/test_ocrd_config.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
from unittest import mock
33
from pathlib import Path
44

5-
import ocrd_utils
5+
from ocrd_utils import pushd_popd
6+
from ocrd.config import load_config_file
67

78
def test_config_loading():
8-
XDG_CONFIG_HOME_before = ocrd_utils.XDG_CONFIG_HOME
9-
with ocrd_utils.pushd_popd(tempdir=True) as tempdir:
10-
ocrd_utils.XDG_CONFIG_HOME = tempdir
9+
with pushd_popd(tempdir=True) as tempdir:
1110
Path('ocrd').mkdir()
1211
with open('ocrd/config.yml', 'w', encoding='utf-8') as f:
1312
f.write('resource_location: cache\n')
14-
from ocrd.config import load_config_file
15-
obj = load_config_file()
13+
obj = load_config_file(tempdir)
1614
assert obj.dump() == {'resource_location': 'cache'}
17-
ocrd_utils.XDG_CONFIG_HOME = XDG_CONFIG_HOME_before
1815

1916
if __name__ == '__main__':
2017
main(__file__)

0 commit comments

Comments
 (0)