Skip to content

Commit

Permalink
Merge pull request psychoinformatics-de#29 from datalad/rf-tst
Browse files Browse the repository at this point in the history
Round of fixes and updates
  • Loading branch information
mih committed Jan 24, 2022
2 parents ec54055 + 7b77859 commit 1929a22
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 79 deletions.
22 changes: 13 additions & 9 deletions .appveyor.yml
Expand Up @@ -67,6 +67,7 @@ environment:
INSTALL_SYSPKGS: python3-virtualenv
# system git-annex is way too old, use better one
INSTALL_GITANNEX: git-annex -m deb-url --url http://snapshot.debian.org/archive/debian/20210906T204127Z/pool/main/g/git-annex/git-annex_8.20210903-1_amd64.deb
CODECOV_BINARY: https://uploader.codecov.io/latest/linux/codecov
# Windows core tests
- ID: WinP39core
# ~35 min
Expand All @@ -82,6 +83,7 @@ environment:
PY: 3.8
INSTALL_GITANNEX: git-annex
DATALAD_LOCATIONS_SOCKETS: /Users/appveyor/DLTMP/sockets
CODECOV_BINARY: https://uploader.codecov.io/latest/macos/codecov

matrix:
allow_failures:
Expand Down Expand Up @@ -158,6 +160,11 @@ install:
# deploy git-annex, if desired
- cmd: IF DEFINED INSTALL_GITANNEX datalad-installer --sudo ok %INSTALL_GITANNEX%
- sh: "[ -n \"${INSTALL_GITANNEX}\" ] && datalad-installer --sudo ok ${INSTALL_GITANNEX}"
# in case of a snapshot installation, use the following approach to adjust
# the PATH as necessary
#- sh: "[ -n \"${INSTALL_GITANNEX}\" ] && datalad-installer -E ${HOME}/dlinstaller_env.sh --sudo ok ${INSTALL_GITANNEX}"
# add location of datalad installer results to PATH
#- sh: "[ -f ${HOME}/dlinstaller_env.sh ] && . ${HOME}/dlinstaller_env.sh || true"


#before_build:
Expand Down Expand Up @@ -189,15 +196,12 @@ test_script:


after_test:
# move coverage into the project dir to make default handling applicable
- cmd: move .coverage ..
- sh: mv .coverage ..
- cd ..
# use windows codecov uploader package
- cmd: choco install codecov
- cmd: python -m coverage xml
- cmd: codecov -f coverage.xml
- sh: bash <(curl -sfS https://codecov.io/bash)
- python -m coverage xml
- cmd: curl -fsSL -o codecov.exe "https://uploader.codecov.io/latest/windows/codecov.exe"
- cmd: .\codecov.exe -f "coverage.xml"
- sh: "curl -Os $CODECOV_BINARY"
- sh: chmod +x codecov
- sh: ./codecov


#on_success:
Expand Down
17 changes: 17 additions & 0 deletions .codeclimate.yml
@@ -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/"
73 changes: 3 additions & 70 deletions datalad_helloworld/__init__.py
Expand Up @@ -2,17 +2,8 @@

__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')

# Defines a datalad command suite.
# This variable must be bound as a setuptools entrypoint
Expand All @@ -24,7 +15,7 @@
# specification of a command, any number of commands can be defined
(
# importable module that contains the command implementation
'datalad_helloworld',
'datalad_helloworld.hello_cmd',
# name of the command class implementation in above module
'HelloWorld',
# optional name of the command in the cmdline API
Expand All @@ -35,64 +26,6 @@
]
)


# 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)


from datalad import setup_package
from datalad import teardown_package

Expand Down
76 changes: 76 additions & 0 deletions datalad_helloworld/hello_cmd.py
@@ -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)

0 comments on commit 1929a22

Please sign in to comment.