Skip to content

Commit

Permalink
Merge pull request #113 from yarikoptic/rf-get_func_kwargs_doc
Browse files Browse the repository at this point in the history
RF: move (and minimal RF) get_func_kwargs_doc from core
  • Loading branch information
yarikoptic authored Nov 10, 2021
2 parents a53978c + 386fa85 commit 8e674f3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion datalad_crawler/crawl_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from datalad.dochelpers import exc_str
from datalad.support.param import Parameter
from datalad.support.constraints import EnsureStr, EnsureNone
from datalad.utils import get_func_kwargs_doc
from datalad_crawler.pipeline import load_pipeline_from_template
from datalad_crawler.pipeline import initiate_pipeline_config
from datalad_crawler.utils import get_func_kwargs_doc

from logging import getLogger
lgr = getLogger('datalad.api.crawl_init')
Expand Down
11 changes: 10 additions & 1 deletion datalad_crawler/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from ..utils import flatten
from ..utils import (
flatten,
get_func_kwargs_doc,
)

from datalad.tests.utils import assert_equal

Expand All @@ -21,3 +24,9 @@ def test_flatten():
assert_equal(flatten(({0}, (1, 2)), types=(set, tuple)), (0, 1, 2))
assert_equal(flatten([(0,), {1: 2}], types=(list, tuple, dict), base_type=tuple),
(0, 1))


def test_get_func_kwargs_doc():
def some_func(arg1, kwarg1=None, kwarg2="bu"):
return
assert_equal(get_func_kwargs_doc(some_func), ['arg1', 'kwarg1', 'kwarg2'])
21 changes: 20 additions & 1 deletion datalad_crawler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
# copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Various utils which might be later moved into datalad core
"""Various utils which were moved from datalad core or might be later moved into it
To simplify such refactoring tests should be provided here as well
"""

import inspect


def flatten(l, types=None, base_type=None):
"""Given a list, return a recursively flattened version
Expand Down Expand Up @@ -38,3 +40,20 @@ def flatten(l, types=None, base_type=None):
base_type()) \
if isinstance(l, types) \
else base_type((l,))


# moved from datalad core, made python 3 specific
def get_func_kwargs_doc(func):
""" Provides args for a function
Parameters
----------
func:
function from which args are being requested
Returns
-------
list
of the args that a function takes in
"""
return inspect.getfullargspec(func)[0]

0 comments on commit 8e674f3

Please sign in to comment.