aboutsummaryrefslogtreecommitdiffstats
path: root/task
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2022-02-09 10:45:54 -0600
committerGitHub <noreply@github.com>2022-02-09 18:45:54 +0200
commite1adc6ca406c3bdbca12c6b3032c0b8f8b2a6cbf (patch)
tree76dec0cd4997a7f81ecff3b8df5a5d81cbf25d8d /task
parentFix `taskipy.variables` table name in error message (#39) (diff)
downloadtaskipy2-e1adc6ca406c3bdbca12c6b3032c0b8f8b2a6cbf.zip
Replace toml with tomli for TOML v1 support (#43)
* Replace toml with tomli for TOML v1 support
Diffstat (limited to '')
-rw-r--r--taskipy/exceptions.py12
-rw-r--r--taskipy/pyproject.py9
2 files changed, 16 insertions, 5 deletions
diff --git a/taskipy/exceptions.py b/taskipy/exceptions.py
index 573967e..d54a022 100644
--- a/taskipy/exceptions.py
+++ b/taskipy/exceptions.py
@@ -1,4 +1,5 @@
from argparse import ArgumentParser
+from typing import Optional
class TaskipyError(Exception):
exit_code = 1
@@ -18,8 +19,17 @@ class MissingPyProjectFileError(TaskipyError):
class MalformedPyProjectError(TaskipyError):
+ def __init__(self, reason: Optional[str] = None):
+ super().__init__()
+ self.reason = reason
+
def __str__(self):
- return 'pyproject.toml file is malformed and could not be read'
+ message = 'pyproject.toml file is malformed and could not be read'
+
+ if self.reason:
+ message += f'. reason: {self.reason}'
+
+ return message
class TaskNotFoundError(TaskipyError):
diff --git a/taskipy/pyproject.py b/taskipy/pyproject.py
index 702aad0..d59d6ac 100644
--- a/taskipy/pyproject.py
+++ b/taskipy/pyproject.py
@@ -1,4 +1,4 @@
-import toml
+import tomli
from pathlib import Path
from typing import Any, Dict, MutableMapping, Optional, Union
@@ -58,11 +58,12 @@ class PyProject:
if isinstance(file_path, str):
file_path = Path(file_path).resolve()
- return toml.load(file_path)
+ with open(file_path, 'rb') as file:
+ return tomli.load(file)
except FileNotFoundError:
raise MissingPyProjectFileError()
- except toml.TomlDecodeError:
- raise MalformedPyProjectError()
+ except tomli.TOMLDecodeError as e:
+ raise MalformedPyProjectError(reason=str(e))
@staticmethod
def __find_pyproject_path(base_dir: Path) -> Path: