From e443d1625deaba53edb7a93c2f564f7bc4fb30dd Mon Sep 17 00:00:00 2001 From: Arisu Tachibana Date: Mon, 20 Jan 2025 14:50:51 +0900 Subject: [PATCH] pyproject: Update toml dependency to tomllib Signed-off-by: Arisu Tachibana --- kcidev/libs/common.py | 45 ++++++++------------------- kcidev/subcommands/bisect.py | 1 - kcidev/subcommands/commit.py | 1 - kcidev/subcommands/maestro_results.py | 1 - kcidev/subcommands/patch.py | 1 - pyproject.toml | 3 +- 6 files changed, 14 insertions(+), 38 deletions(-) diff --git a/kcidev/libs/common.py b/kcidev/libs/common.py index 68b3692..2d62469 100644 --- a/kcidev/libs/common.py +++ b/kcidev/libs/common.py @@ -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): @@ -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() @@ -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() diff --git a/kcidev/subcommands/bisect.py b/kcidev/subcommands/bisect.py index 3665cc9..5d7f595 100644 --- a/kcidev/subcommands/bisect.py +++ b/kcidev/subcommands/bisect.py @@ -9,7 +9,6 @@ import click import requests -import toml from git import Repo from kcidev.libs.common import * diff --git a/kcidev/subcommands/commit.py b/kcidev/subcommands/commit.py index 716d624..7df4a34 100644 --- a/kcidev/subcommands/commit.py +++ b/kcidev/subcommands/commit.py @@ -5,7 +5,6 @@ import click import requests -import toml from git import Repo diff --git a/kcidev/subcommands/maestro_results.py b/kcidev/subcommands/maestro_results.py index 4fe4578..e82551d 100644 --- a/kcidev/subcommands/maestro_results.py +++ b/kcidev/subcommands/maestro_results.py @@ -6,7 +6,6 @@ import click import requests -import toml from git import Repo from kcidev.libs.common import * diff --git a/kcidev/subcommands/patch.py b/kcidev/subcommands/patch.py index b61a5b8..4a3fc81 100644 --- a/kcidev/subcommands/patch.py +++ b/kcidev/subcommands/patch.py @@ -5,7 +5,6 @@ import click import requests -import toml from git import Repo from kcidev.libs.maestro_common import * diff --git a/pyproject.toml b/pyproject.toml index c18786c..20de196 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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'