Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 naming sweep #17

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CliFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 function names: {func.__name__}")

if to_add.__doc__ is None:
raise FunctionCliException(
"Bake requires doc-strings for target functions (denoted by a triple quoted comment as the first thing in the function body)")
raise CliFunctionException(
"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 FunctionCliException(
"Bake requires functions with arguments to use exclusively keyword arguments (denoted by a [*] as the first argument to the function)")
raise CliFunctionException(
"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 FunctionCliException("Bake does not support varargs")
raise CliFunctionException("CliFunction does not support varargs")
if varkw is not None:
raise FunctionCliException("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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
Expand Down
6 changes: 3 additions & 3 deletions test/test_invalidTargets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from ..CliFunction import Targets, FunctionCliException
from ..CliFunction import Targets, CliFunctionException


def one():
Expand Down Expand Up @@ -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
Loading