Skip to content

Commit

Permalink
Merge pull request #71 from aliceinwire/example_config
Browse files Browse the repository at this point in the history
libs/common: When no configuration is found using example configuration
  • Loading branch information
aliceinwire authored Dec 25, 2024
2 parents 1e9b6ae + d46ddf0 commit 236f507
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
37 changes: 32 additions & 5 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,47 @@ def load_toml(settings):
fname = "kci-dev.toml"
config = None

global_path = os.path.join("/", "etc", fname)
if os.path.exists(global_path):
with open(global_path, "r") as f:
if os.path.exists(settings):
with open(settings, "r") as f:
config = toml.load(f)
return config

home_dir = os.path.expanduser("~")
user_path = os.path.join(home_dir, ".config", "kci-dev", fname)
if os.path.exists(user_path):
with open(user_path, "r") as f:
config = toml.load(f)
return config

if os.path.exists(settings):
with open(settings, "r") as f:
global_path = os.path.join("/", "etc", fname)
if os.path.exists(global_path):
with open(global_path, "r") as f:
config = toml.load(f)
return config

example_configuration = ".kci-dev.toml.example"
# Installed with Poetry
poetry_example_configuration = os.path.join(
os.path.dirname(__file__), "../..", example_configuration
)
if os.path.exists(poetry_example_configuration):
kci_err(
f"Using Poetry example configuration in: " + poetry_example_configuration
)
with open(poetry_example_configuration, "r") as f:
config = toml.load(f)
return config

# Installed with PyPI
kci_err(f"Configuration not found")
pypi_example_configuration = os.path.join(
os.path.dirname(__file__), "..", example_configuration
)
if os.path.exists(pypi_example_configuration):
kci_err(f"Using PyPI example configuration in: " + pypi_example_configuration)
with open(pypi_example_configuration, "r") as f:
config = toml.load(f)
return config

if not config:
kci_err(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages = [
{include = "kcidev"},
{include = "subcommands", from="kcidev"},
{include = "libs", from="kcidev"},
{include = ".kci-dev.toml.example", to="kcidev"},
]
repository = "https://github.com/kernelci/kci-dev"
classifiers = [
Expand Down

0 comments on commit 236f507

Please sign in to comment.