From 56c3682dc9cf45b7a5c36bad92cd1f58f5b7744a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Tue, 18 Jul 2023 00:30:25 +0200 Subject: [PATCH] DEP: migrate from toml package to tomllib (#93) --- pyproject.toml | 2 +- spin/__main__.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 075b482..82b8244 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ ] dependencies = [ "click", - "toml", + "tomli; python_version < '3.11'", "colorama; platform_system == 'Windows'" ] diff --git a/spin/__main__.py b/spin/__main__.py index 194fa84..a718436 100644 --- a/spin/__main__.py +++ b/spin/__main__.py @@ -5,12 +5,16 @@ import sys import click -import toml from spin import cmds as _cmds from spin.color_format import ColorHelpFormatter from spin.sectioned_help import SectionedHelpGroup +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + click.Context.formatter_class = ColorHelpFormatter @@ -41,10 +45,10 @@ def main(): print("Error: cannot find [pyproject.toml]") sys.exit(1) - with open("pyproject.toml") as f: + with open("pyproject.toml", "rb") as f: try: - toml_config = toml.load(f) - except: + toml_config = tomllib.load(f) + except tomllib.TOMLDecodeError: print("Cannot parse [pyproject.toml]") sys.exit(1)