Skip to content

Commit 236f507

Browse files
authored
Merge pull request #71 from aliceinwire/example_config
libs/common: When no configuration is found using example configuration
2 parents 1e9b6ae + d46ddf0 commit 236f507

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

kcidev/libs/common.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,47 @@ def load_toml(settings):
1111
fname = "kci-dev.toml"
1212
config = None
1313

14-
global_path = os.path.join("/", "etc", fname)
15-
if os.path.exists(global_path):
16-
with open(global_path, "r") as f:
14+
if os.path.exists(settings):
15+
with open(settings, "r") as f:
1716
config = toml.load(f)
17+
return config
1818

1919
home_dir = os.path.expanduser("~")
2020
user_path = os.path.join(home_dir, ".config", "kci-dev", fname)
2121
if os.path.exists(user_path):
2222
with open(user_path, "r") as f:
2323
config = toml.load(f)
24+
return config
2425

25-
if os.path.exists(settings):
26-
with open(settings, "r") as f:
26+
global_path = os.path.join("/", "etc", fname)
27+
if os.path.exists(global_path):
28+
with open(global_path, "r") as f:
29+
config = toml.load(f)
30+
return config
31+
32+
example_configuration = ".kci-dev.toml.example"
33+
# Installed with Poetry
34+
poetry_example_configuration = os.path.join(
35+
os.path.dirname(__file__), "../..", example_configuration
36+
)
37+
if os.path.exists(poetry_example_configuration):
38+
kci_err(
39+
f"Using Poetry example configuration in: " + poetry_example_configuration
40+
)
41+
with open(poetry_example_configuration, "r") as f:
42+
config = toml.load(f)
43+
return config
44+
45+
# Installed with PyPI
46+
kci_err(f"Configuration not found")
47+
pypi_example_configuration = os.path.join(
48+
os.path.dirname(__file__), "..", example_configuration
49+
)
50+
if os.path.exists(pypi_example_configuration):
51+
kci_err(f"Using PyPI example configuration in: " + pypi_example_configuration)
52+
with open(pypi_example_configuration, "r") as f:
2753
config = toml.load(f)
54+
return config
2855

2956
if not config:
3057
kci_err(

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ packages = [
99
{include = "kcidev"},
1010
{include = "subcommands", from="kcidev"},
1111
{include = "libs", from="kcidev"},
12+
{include = ".kci-dev.toml.example", to="kcidev"},
1213
]
1314
repository = "https://github.com/kernelci/kci-dev"
1415
classifiers = [

0 commit comments

Comments
 (0)