Skip to content

Commit

Permalink
Fix a bunch of linting errors. But probably turned others on.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaak-Malers committed Feb 22, 2024
1 parent 64fdbdc commit 5c30628
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: Run PyLint on current directory
run: |
pylint --disable=line-too-long ./*.py
pylint --disable=line-too-long,invalid-name ./*.py
- name: Run PyLint on test directory
run: |
pylint --disable=line-too-long ./test/*.py
pylint --disable=line-too-long,invalid-name ./test/*.py
19 changes: 14 additions & 5 deletions CliFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@


class FunctionCliException(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.
"""
pass


class DefaultArgumentParser:
"""
The default argument parser. It is possible to create others (for example one that uses argparse) if so desired.
"""
def __init__(self):
pass

def name_and_abbreviations(self, *, python_name: str) -> [str]: # noqa
def name_and_abbreviations(self, *, python_name: str) -> [str]:
"""
Given a string name for a python function or method or argument, returns a list with multiple possible matches.
Examples:
Expand All @@ -35,7 +42,7 @@ def name_and_abbreviations(self, *, python_name: str) -> [str]: # noqa
# write
return sorted(list({python_name, abbreviation.lower()}), key=lambda item: -len(item))

def type_coercer(self, *, arg: str, desired_type: type): # noqa
def type_coercer(self, *, arg: str, desired_type: type):

if desired_type is str:
return arg
Expand Down Expand Up @@ -79,6 +86,7 @@ def generate_method_kwargs(self, *, args: [str], function) -> dict:
kwargs_to_return = {}

# Try to build up the kwarg dict. If anything tries to double add, bail out.
# pylint: disable=unused-variable
names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = inspect.getfullargspec(function)

# Check that all args specified have a place to go:
Expand All @@ -92,7 +100,7 @@ def generate_method_kwargs(self, *, args: [str], function) -> dict:
for name in kwonlyargs:
if arg_name in self.name_and_abbreviations(python_name=name):
if name in kwargs_to_return:
# TODO: See if we can make this give better errors.
# TO DO: See if we can make this give better errors.
# The function has an ambiguous naming scheme, this should probably error out?
return None

Expand Down Expand Up @@ -123,7 +131,7 @@ def __init__(self):

self.recursiveTargets: [Targets] = []

def printer(self, to_print: str): # noqa
def printer(self, to_print: str):
"""
Note: This function is only here so that this object is easy to mock/patch for unit tests.
"""
Expand Down Expand Up @@ -177,6 +185,7 @@ def add_target(self, to_add):
raise FunctionCliException(
"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(
Expand All @@ -187,7 +196,7 @@ def add_target(self, to_add):
raise FunctionCliException("Bake does not support varargs")
self.targets.append(to_add)

def function_help(self, func, pad: str = "") -> str: # noqa
def function_help(self, func, pad: str = "") -> str:
header = f"{pad}{func.__name__} -- {func.__doc__.strip()}"
names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = inspect.getfullargspec(func)
if kwonlydefaults is None:
Expand Down
3 changes: 3 additions & 0 deletions Example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from CliFunction import cli_function, cli
"""
An example file for how to use CliFunction! these methods don't do anything real, but serve as an example for how this library might be used.
"""


@cli_function
Expand Down

0 comments on commit 5c30628

Please sign in to comment.