Skip to content

Commit a920b72

Browse files
authored
Make key in TOML env file consistent (#43)
Some keys in the config are named as `..._path` and some as `..._dir`. This is not good to remember that ("was it path or dir at the end?"). This commit changes that and makes all consistent. We have now the latter name with `..._dir`.
1 parent ce463f7 commit a920b72

7 files changed

Lines changed: 55 additions & 46 deletions

File tree

changelog.d/43.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make keys in TOML env file consistent

etc/docbuild/env.example.toml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,35 @@ canonical_url_domain = "https://docs.example.com"
2929
[paths]
3030
# Section "paths": Defines several paths
3131
# Paths can hold placeholders in brackets.
32-
config_dir = "/etc/docbuild"
32+
root_config_dir = "/etc/docbuild"
33+
jinja_dir = "{root_config_dir}/jinja-doc-suse-com"
34+
config_dir = "{root_config_dir}/config.d"
35+
server_rootfiles_dir = "{root_config_dir}/server-root-files-doc-suse-com"
36+
#
37+
base_cache_dir = "/var/cache/docserv"
38+
base_server_cache_dir = "{base_cache_dir}/{server.name}"
39+
base_tmp_dir = "/var/tmp/docbuild"
3340
repo_dir = "/data/docserv/repos/permanent-full/"
3441
temp_repo_dir = "/data/docserv/repos/temporary-branches/"
35-
base_cache_dir = "/var/cache/docserv"
36-
cache_dir = "{base_cache_dir}/{server.name}"
37-
meta_cache_dir = "{base_cache_dir}/meta"
42+
# cache_dir = "{base_cache_dir}/{server.name}"
43+
meta_cache_dir = "{base_cache_dir}/{server.name}/meta"
3844

3945
[paths.tmp]
4046
# Section "paths.tmp": Definies temporary paths
4147
# Paths can hold placeholders in brackets.
42-
tmp_base_path = "/tmp/docbuild"
43-
tmp_path = "{tmp_base_path}/doc-example-com"
44-
tmp_deliverable_path = "{paths.tmp.tmp_path}/deliverable/"
45-
tmp_build_dir = "{tmp_path}/build/{{product}}-{{docset}}-{{lang}}"
46-
tmp_out_path = "{tmp_path}/out/"
47-
log_path = "{tmp_path}/log/"
48+
tmp_base_dir = "{paths.base_tmp_dir}"
49+
tmp_dir = "{tmp_base_dir}/doc-example-com"
50+
tmp_metadata_dir = "{tmp_dir}/metadata"
51+
tmp_deliverable_dir = "{paths.tmp.tmp_dir}/deliverable/"
52+
tmp_build_dir = "{tmp_dir}/build/{{product}}-{{docset}}-{{lang}}"
53+
tmp_out_dir = "{tmp_dir}/out/"
54+
log_dir = "{tmp_dir}/log/"
4855
tmp_deliverable_name = "{{product}}_{{docset}}_{{lang}}_XXXXXX"
4956

5057
[paths.target]
5158
# Section "paths.target": Definies target paths
52-
target_path = "[email protected]:/srv/docs"
53-
backup_path = "/data/docbuild/external-builds/"
59+
target_dir = "[email protected]:/srv/docs"
60+
backup_dir = "/data/docbuild/external-builds/"
5461

5562

5663
[build]

src/docbuild/cli/defaults.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
'temp_repo_dir': '/data/docserv/repos/temporary-branches/',
1919
},
2020
'paths.tmp': {
21-
'tmp_base_path': '/tmp',
22-
'tmp_path': '{tmp_base_path}/doc-example-com',
21+
'tmp_base_dir': '/tmp',
22+
'tmp_dir': '{tmp_base_dir}/doc-example-com',
2323
},
2424
}
2525
"""Default configuration for the application."""
@@ -32,8 +32,8 @@
3232
'temp_repo_dir': '/data/docserv/repos/temporary-branches/',
3333
},
3434
'paths.tmp': {
35-
'tmp_base_path': f'/var/tmp/{APP_NAME}',
36-
'tmp_path': '{tmp_base_path}/doc-example-com',
35+
'tmp_base_dir': f'/var/tmp/{APP_NAME}',
36+
'tmp_dir': '{tmp_base_dir}/doc-example-com',
3737
},
3838
}
3939
"""Default configuration for the environment."""

tests/cli/config/sample-env.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ meta_cache_dir = "{base_cache_dir}/meta"
3939
[paths.tmp]
4040
# Section "paths.tmp": Definies temporary paths
4141
# Paths can hold placeholders in brackets.
42-
tmp_base_path = "/tmp/docbuild"
43-
tmp_path = "{tmp_base_path}/doc-example-com"
44-
tmp_deliverable_path = "{paths.tmp.tmp_path}/deliverable/"
45-
tmp_build_dir = "{tmp_path}/build/{{product}}-{{docset}}-{{lang}}"
46-
tmp_out_path = "{tmp_path}/out/"
47-
log_path = "{tmp_path}/log/"
42+
tmp_base_dir = "/tmp/docbuild"
43+
tmp_dir = "{tmp_base_dir}/doc-example-com"
44+
tmp_deliverable_dir = "{paths.tmp.tmp_dir}/deliverable/"
45+
tmp_build_dir = "{tmp_dir}/build/{{product}}-{{docset}}-{{lang}}"
46+
tmp_out_dir = "{tmp_dir}/out/"
47+
log_path = "{tmp_dir}/log/"
4848
tmp_deliverable_name = "{{product}}_{{docset}}_{{lang}}_XXXXXX"
4949

5050
[paths.target]
5151
# Section "paths.target": Definies target paths
52-
target_path = "[email protected]:/srv/docs"
53-
backup_path = "/data/docbuild/external-builds/"
52+
target_dir = "[email protected]:/srv/docs"
53+
backup_dir = "/data/docbuild/external-builds/"
5454

5555

5656
[build]

tests/cli/config/test_environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_showconfig_env_role_option(
6767
'repo_dir': '/data/docserv/repos/permanent-full/',
6868
'temp_repo_dir': '/data/docserv/repos/temporary-branches/',
6969
'tmp': {
70-
'tmp_base_path': '/tmp',
71-
'tmp_path': '/tmp/doc-example-com',
70+
'tmp_base_dir': '/tmp',
71+
'tmp_dir': '/tmp/doc-example-com',
7272
},
7373
},
7474
}

tests/config/app/test_app_replace_placeholders.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Any
12
import re
23

34
import pytest
@@ -15,27 +16,27 @@ def test_replace_placeholders():
1516
'server': {'name': 'example.com', 'url': 'https://{server.name}'},
1617
'paths': {
1718
'config_dir': '/etc/myapp',
18-
'tmp': {'tmp_base_path': '/tmp/myapp'},
19-
'full_tmp_path': '{paths.tmp.tmp_base_path}/session',
19+
'tmp': {'tmp_base_dir': '/tmp/myapp'},
20+
'full_tmp_path': '{paths.tmp.tmp_base_dir}/session',
2021
},
2122
'logging': {
2223
'log_dir': '{paths.config_dir}/logs',
23-
'tmp_base_path': '/var/tmp',
24+
'tmp_base_dir': '/var/tmp',
2425
# Should resolve within this section if key exists:
25-
'temp_dir': '{tmp_base_path}',
26+
'temp_dir': '{tmp_base_dir}',
2627
},
2728
}
2829

2930
expected = {
3031
'server': {'name': 'example.com', 'url': 'https://example.com'},
3132
'paths': {
3233
'config_dir': '/etc/myapp',
33-
'tmp': {'tmp_base_path': '/tmp/myapp'},
34+
'tmp': {'tmp_base_dir': '/tmp/myapp'},
3435
'full_tmp_path': '/tmp/myapp/session',
3536
},
3637
'logging': {
3738
'log_dir': '/etc/myapp/logs',
38-
'tmp_base_path': '/var/tmp',
39+
'tmp_base_dir': '/var/tmp',
3940
'temp_dir': '/var/tmp',
4041
},
4142
}
@@ -69,7 +70,7 @@ def test_unresolved_key_in_config():
6970
'server': {'name': 'example.com', 'url': 'https://{server.name}'},
7071
'paths': {
7172
'config_dir': '/etc/myapp',
72-
'tmp': {'tmp_base_path': '/tmp/myapp'},
73+
'tmp': {'tmp_base_dir': '/tmp/myapp'},
7374
# 'session' is missing in this section
7475
'full_tmp_path': '{paths.tmp.session}/session',
7576
},
@@ -148,18 +149,18 @@ def test_chained_placeholder_resolution():
148149
data = {
149150
'paths': {
150151
'tmp': {
151-
'tmp_base_path': '/tmp/docbuild',
152-
'tmp_path': '{tmp_base_path}/doc-example-com',
153-
'tmp_deliverable_path': '{tmp_path}/deliverable/',
152+
'tmp_base_dir': '/tmp/docbuild',
153+
'tmp_dir': '{tmp_base_dir}/doc-example-com',
154+
'tmp_deliverable_dir': '{tmp_dir}/deliverable/',
154155
},
155156
},
156157
}
157158

158-
result = replace_placeholders(data)
159+
result: dict[str, Any] = replace_placeholders(data)
159160
tmp = result['paths']['tmp']
160-
assert tmp['tmp_base_path'] == '/tmp/docbuild'
161-
assert tmp['tmp_path'] == '/tmp/docbuild/doc-example-com'
162-
assert tmp['tmp_deliverable_path'] == '/tmp/docbuild/doc-example-com/deliverable/'
161+
assert tmp['tmp_base_dir'] == '/tmp/docbuild'
162+
assert tmp['tmp_dir'] == '/tmp/docbuild/doc-example-com'
163+
assert tmp['tmp_deliverable_dir'] == '/tmp/docbuild/doc-example-com/deliverable/'
163164

164165

165166
def test_too_many_nested_placeholder_expansions():
@@ -178,12 +179,12 @@ def test_too_many_nested_placeholder_expansions():
178179
def test_chained_cross_section_placeholders():
179180
config = {
180181
'build': {
181-
'output': '{paths.tmp_deliverable_path}',
182+
'output': '{paths.tmp_deliverable_dir}',
182183
},
183184
'paths': {
184-
'tmp_base_path': '/tmp/docbuild',
185-
'tmp_path': '{tmp_base_path}/doc-example-com',
186-
'tmp_deliverable_path': '{paths.tmp_path}/deliverable/',
185+
'tmp_base_dir': '/tmp/docbuild',
186+
'tmp_dir': '{tmp_base_dir}/doc-example-com',
187+
'tmp_deliverable_dir': '{paths.tmp_dir}/deliverable/',
187188
},
188189
}
189190

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def env_content(default_env_config_filename: Path) -> Path:
4949
temp_repo_dir = "/data/docserv/repos/temporary-branches/"
5050
5151
[paths.tmp]
52-
tmp_base_path = "/tmp"
53-
tmp_path = "{tmp_base_path}/doc-example-com"
52+
tmp_base_dir = "/tmp"
53+
tmp_path = "{tmp_base_dir}/doc-example-com"
5454
"""
5555
default_env_config_filename.write_text(content)
5656
return default_env_config_filename

0 commit comments

Comments
 (0)