Skip to content

Commit

Permalink
pyproject: Update toml dependency to tomllib
Browse files Browse the repository at this point in the history
Signed-off-by: Arisu Tachibana <arisu.tachibana@miraclelinux.com>
  • Loading branch information
aliceinwire committed Jan 20, 2025
1 parent f8c94f2 commit e443d16
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 38 deletions.
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
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ classifiers = [
python = "^3.10"
click = "^8.1.7"
requests = "^2.32.3"
toml = "^0.10.2"
gitpython = "^3.1.43"
gitpython = "^3.1.44"

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

0 comments on commit e443d16

Please sign in to comment.