Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global config #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ poetry run kci-dev

## Configuration

kci-dev uses a configuration file .kci-dev.toml in the program directory.
kci-dev uses a configuration file .kci-dev.toml in the current program directory
or global configuration directory, in user's home directory/.config/kci-dev.toml.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about to use something like "$HOME/.config/kci-dev/kci-dev.toml"
so that we can have a subdirectory under .config for kci-dev

Copy link
Member

@aliceinwire aliceinwire Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this is not a global configuration but a USER configuration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global configurations are under /etc/ in most OS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current program directory configuration ".kci-dev.toml" is per SITE configuration

Copy link
Member

@aliceinwire aliceinwire Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and loading order is generally

  • Global
  • User
  • Site
  • kci-dev settings options

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i will update. About loading order, do you mean "site" for example override previous ones or global have highest priority and will be used as highest priority (if available)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each file read overrides any values read from previous files

site for example override previous ones

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also added the kci-dev settings options in the list


```toml
default_instance="local"

Expand Down
10 changes: 10 additions & 0 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

import toml


def load_toml(settings):
if not settings:
if os.path.exists(".kci-dev.toml"):
settings = ".kci-dev.toml"
else:
homedir = os.path.expanduser("~")
settings = os.path.join(homedir, ".config", "kci-dev.toml")
if not os.path.exists(settings):
raise FileNotFoundError(f"Settings file {settings} not found")
with open(settings) as fp:
config = toml.load(fp)
return config
2 changes: 1 addition & 1 deletion kcidev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
help="Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel changes on a enabled KernelCI server"
)
@click.version_option("0.1.0", prog_name="kci-dev")
@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file")
@click.option("--settings", default=None, help="path of toml setting file")
@click.option("--instance", help="API instance to use", required=False)
@click.pass_context
def cli(ctx, settings, instance):
Expand Down
Loading