From c2eb626914a73e8c804f64b17cbbb54568910a7c Mon Sep 17 00:00:00 2001 From: isaak Date: Tue, 27 Feb 2024 23:01:28 -0700 Subject: [PATCH 1/3] Refactor Exception to conform to naming. --- CliFunction.py | 12 ++++++------ test/test_invalidTargets.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CliFunction.py b/CliFunction.py index d85de8b..7539aa3 100644 --- a/CliFunction.py +++ b/CliFunction.py @@ -4,7 +4,7 @@ import re -class FunctionCliException(Exception): +class CliFunctionException(Exception): """ Common exception type for CliFunction. This ensures it is obvious when a problem occurs with the CLI wrapper vs the code being called into. @@ -193,21 +193,21 @@ def add_target(self, to_add): """ for func in self.targets: if func.__name__ == to_add.__name__: - raise FunctionCliException(f"duplicate target names: {func.__name__}") + raise CliFunctionException(f"duplicate target names: {func.__name__}") if to_add.__doc__ is None: - raise FunctionCliException( + raise CliFunctionException( "Bake requires doc-strings for target functions (denoted by a triple quoted comment as the first thing in the function body)") # pylint: disable=unused-variable names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = inspect.getfullargspec(to_add) if len(names) != 0 or defaults is not None: - raise FunctionCliException( + raise CliFunctionException( "Bake requires functions with arguments to use exclusively keyword arguments (denoted by a [*] as the first argument to the function)") if varargs is not None: - raise FunctionCliException("Bake does not support varargs") + raise CliFunctionException("Bake does not support varargs") if varkw is not None: - raise FunctionCliException("Bake does not support varargs") + raise CliFunctionException("Bake does not support varargs") self.targets.append(to_add) def function_help(self, func, pad: str = "") -> str: diff --git a/test/test_invalidTargets.py b/test/test_invalidTargets.py index cd9fde4..cb7b59f 100644 --- a/test/test_invalidTargets.py +++ b/test/test_invalidTargets.py @@ -1,6 +1,6 @@ import pytest -from ..CliFunction import Targets, FunctionCliException +from ..CliFunction import Targets, CliFunctionException def one(): @@ -33,10 +33,10 @@ def test_no_docstring(self): t = Targets() with pytest.raises(Exception) as e: t.add_target(noDocstring) - assert e.type == FunctionCliException + assert e.type == CliFunctionException def test_no_kwargs_only(self): t = Targets() with pytest.raises(Exception) as e: t.add_target(noKwargs) - assert e.type == FunctionCliException + assert e.type == CliFunctionException From 35f134d863be85596c03c2f98ec6baec1e0ff8d0 Mon Sep 17 00:00:00 2001 From: isaak Date: Tue, 27 Feb 2024 23:05:01 -0700 Subject: [PATCH 2/3] remove mentions of bake. --- CliFunction.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CliFunction.py b/CliFunction.py index 7539aa3..d2fb8c5 100644 --- a/CliFunction.py +++ b/CliFunction.py @@ -75,7 +75,7 @@ def type_coercer(self, *, arg: str, desired_type: type): def generate_method_kwargs(self, *, args: [str], function) -> dict: """ should be passed the args string list from the terminal which will look something like this: - ['FunctionCLI.py', 'two', '--arg1=5'] + ['CliFunction.py', 'two', '--arg1=5'] and a function which may or may not be invoke-able given the information in the args string list. if the function cannot be invoked from the given arguments, return None @@ -193,21 +193,21 @@ def add_target(self, to_add): """ for func in self.targets: if func.__name__ == to_add.__name__: - raise CliFunctionException(f"duplicate target names: {func.__name__}") + raise CliFunctionException(f"duplicate function names: {func.__name__}") if to_add.__doc__ is None: raise CliFunctionException( - "Bake requires doc-strings for target functions (denoted by a triple quoted comment as the first thing in the function body)") + "CliFunction requires doc-strings for exposed functions (denoted by a triple quoted comment as the first thing in the function body)") # pylint: disable=unused-variable names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = inspect.getfullargspec(to_add) if len(names) != 0 or defaults is not None: raise CliFunctionException( - "Bake requires functions with arguments to use exclusively keyword arguments (denoted by a [*] as the first argument to the function)") + "CliFunction requires functions with arguments to use exclusively keyword arguments (denoted by a [*] as the first argument to the function)") if varargs is not None: - raise CliFunctionException("Bake does not support varargs") + raise CliFunctionException("CliFunction does not support varargs") if varkw is not None: - raise CliFunctionException("Bake does not support varargs") + raise CliFunctionException("CliFunction does not support varargs") self.targets.append(to_add) def function_help(self, func, pad: str = "") -> str: From b3e4a81d7f0b39c35194df6d12b8745b87c92fc0 Mon Sep 17 00:00:00 2001 From: isaak Date: Tue, 27 Feb 2024 23:06:12 -0700 Subject: [PATCH 3/3] Update version to push up a new version with the updated language. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 78345b9..43f76e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "clifunction" -version = "0.2.3" +version = "0.2.4" authors = [ { name="Isaak Malers", email="isaak.malers+clifunction@gmail.com" }, ]