forked from psychoinformatics-de/datalad-debian
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request psychoinformatics-de#29 from datalad/rf-tst
Round of fixes and updates
- Loading branch information
Showing
4 changed files
with
109 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: "2" | ||
checks: | ||
file-lines: | ||
config: | ||
threshold: 500 | ||
plugins: | ||
bandit: | ||
enabled: true | ||
checks: | ||
assert_used: | ||
enabled: false | ||
exclude_patterns: | ||
- "_datalad_buildsupport/" | ||
- "versioneer.py" | ||
- "*/_version.py" | ||
- "tools/" | ||
- "**/tests/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""DataLad demo command""" | ||
|
||
__docformat__ = 'restructuredtext' | ||
|
||
from os.path import curdir | ||
from os.path import abspath | ||
|
||
from datalad.interface.base import Interface | ||
from datalad.interface.base import build_doc | ||
from datalad.support.param import Parameter | ||
from datalad.distribution.dataset import datasetmethod | ||
from datalad.interface.utils import eval_results | ||
from datalad.support.constraints import EnsureChoice | ||
|
||
from datalad.interface.results import get_status_dict | ||
|
||
import logging | ||
lgr = logging.getLogger('datalad.helloworld.hello_cmd') | ||
|
||
|
||
# decoration auto-generates standard help | ||
@build_doc | ||
# all commands must be derived from Interface | ||
class HelloWorld(Interface): | ||
# first docstring line is used a short description in the cmdline help | ||
# the rest is put in the verbose help and manpage | ||
"""Short description of the command | ||
Long description of arbitrary volume. | ||
""" | ||
|
||
# parameters of the command, must be exhaustive | ||
_params_ = dict( | ||
# name of the parameter, must match argument name | ||
language=Parameter( | ||
# cmdline argument definitions, incl aliases | ||
args=("-l", "--language"), | ||
# documentation | ||
doc="""language to say "hello" in""", | ||
# type checkers, constraint definition is automatically | ||
# added to the docstring | ||
constraints=EnsureChoice('en', 'de')), | ||
) | ||
|
||
@staticmethod | ||
# decorator binds the command to the Dataset class as a method | ||
@datasetmethod(name='hello_cmd') | ||
# generic handling of command results (logging, rendering, filtering, ...) | ||
@eval_results | ||
# signature must match parameter list above | ||
# additional generic arguments are added by decorators | ||
def __call__(language='en'): | ||
if language == 'en': | ||
msg = 'Hello!' | ||
elif language == 'de': | ||
msg = 'Tachchen!' | ||
else: | ||
msg = ("unknown language: '%s'", language) | ||
|
||
# commands should be implemented as generators and should | ||
# report any results by yielding status dictionaries | ||
yield get_status_dict( | ||
# an action label must be defined, the command name make a good | ||
# default | ||
action='demo', | ||
# most results will be about something associated with a dataset | ||
# (component), reported paths MUST be absolute | ||
path=abspath(curdir), | ||
# status labels are used to identify how a result will be reported | ||
# and can be used for filtering | ||
status='ok' if language in ('en', 'de') else 'error', | ||
# arbitrary result message, can be a str or tuple. in the latter | ||
# case string expansion with arguments is delayed until the | ||
# message actually needs to be rendered (analog to exception | ||
# messages) | ||
message=msg) |