1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
From 4321df1bea36ea6d28a76f981b34a6e269f1e583 Mon Sep 17 00:00:00 2001
From: Alexandre Detiste <alexandre.detiste@gmail.com>
Date: Sat, 17 May 2025 17:21:55 +0200
Subject: [PATCH] tomli is part of the Python standard library since Py3.11
tomli and tomllib are the samething,
usage of old tomli will slowly fade away
---
.hooks/make_release_commit.py | 7 +++++--
taskipy/pyproject.py | 9 ++++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/.hooks/make_release_commit.py b/.hooks/make_release_commit.py
index 0c4b3a7..5d6dbb5 100644
--- a/.hooks/make_release_commit.py
+++ b/.hooks/make_release_commit.py
@@ -1,5 +1,8 @@
#!/usr/bin/env python3
-import tomli
+try:
+ import tomllib
+except ImportError:
+ import tomli as tomllib
import secrets
import subprocess
import webbrowser
@@ -9,7 +12,7 @@
def create_release_commit():
cwd = Path.cwd()
with open(cwd / "pyproject.toml", "rb") as file:
- pyproject = tomli.load(file)
+ pyproject = tomllib.load(file)
version = pyproject["tool"]["poetry"]["version"]
branch = f"release-{version}-{secrets.token_hex(12)}"
diff --git a/taskipy/pyproject.py b/taskipy/pyproject.py
index e7fd74e..d37ca30 100644
--- a/taskipy/pyproject.py
+++ b/taskipy/pyproject.py
@@ -1,4 +1,7 @@
-import tomli
+try:
+ import tomllib
+except ImportError:
+ import tomli as tomllib
from pathlib import Path
from typing import Any, Dict, MutableMapping, Optional, Union
@@ -92,10 +95,10 @@ def __load_toml_file(file_path: Union[str, Path]) -> MutableMapping[str, Any]:
file_path = Path(file_path).resolve()
with open(file_path, 'rb') as file:
- return tomli.load(file)
+ return tomllib.load(file)
except FileNotFoundError:
raise MissingPyProjectFileError()
- except tomli.TOMLDecodeError as e:
+ except tomllib.TOMLDecodeError as e:
raise MalformedPyProjectError(reason=str(e))
@staticmethod
|