aboutsummaryrefslogtreecommitdiffstats
path: root/task
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2023-07-30 06:44:57 -0400
committerGitHub <noreply@github.com>2023-07-30 13:44:57 +0300
commit51fe6c6849da2afdce13881a657d49cf7da80e69 (patch)
tree116464b0901f357eddfc0311004db88f4a6eb9e9 /task
parentRelease version 1.11.0 (diff)
downloadtaskipy2-51fe6c6849da2afdce13881a657d49cf7da80e69.zip
GH-63: Fix use_vars task override with project setting (#64)
* from now on, the use_vars task-level setting takes priority if it is ever explicitly set. Otherwise, the project-level setting is used * closes #63
Diffstat (limited to '')
-rw-r--r--taskipy/task.py20
-rw-r--r--taskipy/task_runner.py6
2 files changed, 16 insertions, 10 deletions
diff --git a/taskipy/task.py b/taskipy/task.py
index c812c42..61fd718 100644
--- a/taskipy/task.py
+++ b/taskipy/task.py
@@ -1,3 +1,5 @@
+from typing import Optional
+
from taskipy.exceptions import MalformedTaskError
@@ -9,29 +11,31 @@ class Task:
self.__task_use_vars = self.__extract_task_use_vars(task_toml_contents)
@property
- def name(self):
+ def name(self) -> str:
return self.__task_name
@property
- def command(self):
+ def command(self) -> str:
return self.__task_command
@property
- def description(self):
+ def description(self) -> str:
return self.__task_description
@property
- def use_vars(self):
+ def use_vars(self) -> Optional[bool]:
return self.__task_use_vars
- def __extract_task_use_vars(self, task_toml_contents: object) -> bool:
+ def __extract_task_use_vars(self, task_toml_contents: object) -> Optional[bool]:
if isinstance(task_toml_contents, str):
- return False
+ return None
+
if isinstance(task_toml_contents, dict):
- value = task_toml_contents.get('use_vars', False)
- if not isinstance(value, bool):
+ value = task_toml_contents.get('use_vars')
+ if value is not None and not isinstance(value, bool):
raise MalformedTaskError(self.__task_name, f'task\'s "use_vars" arg has to be bool type got {type(value)}')
return value
+
raise MalformedTaskError(self.__task_name, 'tasks must be strings, or dicts that contain { cmd, help, use_vars }')
def __extract_task_command(self, task_toml_contents: object) -> str:
diff --git a/taskipy/task_runner.py b/taskipy/task_runner.py
index 0a72225..561427e 100644
--- a/taskipy/task_runner.py
+++ b/taskipy/task_runner.py
@@ -134,8 +134,10 @@ class TaskRunner:
return nonrecursive_vars, recursive_vars
- def __format_task_command(self, task: Task, variables: Optional[dict]) -> str:
- if task.use_vars or self.__project.settings.get('use_vars'):
+ def __format_task_command(self, task: Task, variables: dict) -> str:
+ if task.use_vars or (
+ task.use_vars is None and self.__project.settings.get('use_vars')
+ ):
try:
return task.command.format(**variables)
except KeyError as e: