Skip to content
Merged
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
45 changes: 13 additions & 32 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
# -*- coding: utf-8 -*-

import os
import sys

import click
import toml

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib


def load_toml(settings, subcommand):
Expand All @@ -13,8 +18,8 @@ def load_toml(settings, subcommand):

if os.path.exists(settings):
if os.path.isfile(settings):
with open(settings, "r") as f:
config = toml.load(f)
with open(settings, "rb") as f:
config = tomllib.load(f)
else:
kci_err("The --settings location is not a kci-dev config file")
raise click.Abort()
Expand All @@ -23,43 +28,19 @@ def load_toml(settings, subcommand):
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)
with open(user_path, "rb") as f:
config = tomllib.load(f)
return config

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):
if subcommand != "config":
kci_err(f"Please use `kci-dev config` to create a config file")
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):
if subcommand != "config":
kci_err(f"Please use `kci-dev config` to create a config file")
with open(pypi_example_configuration, "r") as f:
config = toml.load(f)
with open(global_path, "rb") as f:
config = tomllib.load(f)
return config

if not config:
kci_err(
f"No `{fname}` configuration file found at `{global_path}`, `{user_path}` or `{settings}`"
f"No config file found, please use `kci-dev config` to create a config file"
)
raise click.Abort()

Expand Down
1 change: 0 additions & 1 deletion kcidev/subcommands/bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import click
import requests
import toml
from git import Repo

from kcidev.libs.common import *
Expand Down
1 change: 0 additions & 1 deletion kcidev/subcommands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import click
import requests
import toml
from git import Repo


Expand Down
1 change: 0 additions & 1 deletion kcidev/subcommands/maestro_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import click
import requests
import toml
from git import Repo

from kcidev.libs.common import *
Expand Down
1 change: 0 additions & 1 deletion kcidev/subcommands/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import click
import requests
import toml
from git import Repo

from kcidev.libs.maestro_common import *
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ classifiers = [
python = "^3.10"
click = "^8.1.7"
requests = "^2.32.3"
toml = "^0.10.2"
gitpython = "^3.1.43"
tomli = { version = "^2.2.1", python = "<3.11" }

[tool.poetry.scripts]
kci-dev = 'kcidev.main:run'
Expand Down
Loading