Commit 74be05b1 authored by Samuel GAIST's avatar Samuel GAIST

[cmdline] Pre-commit cleanup

parent 33320a6b
......@@ -59,41 +59,41 @@ logger = logging.getLogger(__name__)
def pull_impl(webapi, prefix, names, force, indentation, format_cache, lib_cache):
"""Copies algorithms (and required libraries/dataformats) from the server.
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to retrieve or a list of usernames from
which to retrieve objects. If the list is empty, then we pull all
available objects of a given type. If no user is set, then pull all
public objects of a given type.
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to retrieve or a list of usernames from
which to retrieve objects. If the list is empty, then we pull all
available objects of a given type. If no user is set, then pull all
public objects of a given type.
force (bool): If set to ``True``, then overwrites local changes with the
remotely retrieved copies.
force (bool): If set to ``True``, then overwrites local changes with the
remotely retrieved copies.
indentation (int): The indentation level, useful if this function is called
recursively while downloading different object types. This is normally
set to ``0`` (zero).
indentation (int): The indentation level, useful if this function is called
recursively while downloading different object types. This is normally
set to ``0`` (zero).
format_cache (dict): A dictionary containing all dataformats already
downloaded.
format_cache (dict): A dictionary containing all dataformats already
downloaded.
lib_cache (dict): A dictionary containing all libraries already
downloaded.
lib_cache (dict): A dictionary containing all libraries already
downloaded.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
from .dataformats import pull_impl as dataformats_pull
from .libraries import pull_impl as libraries_pull
......@@ -384,9 +384,9 @@ commands.initialise_asset_commands(algorithms, CMD_LIST, AlgorithmCommand)
def pull(ctx, name, force):
"""Downloads the specified algorithms from the server
Example:
$ beat algorithms pull --force yyy
"""
Example:
$ beat algorithms pull --force yyy
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return pull_impl(webapi, ctx.meta["config"].path, name, force, 0, {}, {})
......@@ -401,10 +401,10 @@ def pull(ctx, name, force):
def execute(ctx, instructions, example):
"""Execute an algorithm following instructions in a JSON file
Example:
$ beat algorithms execute <instructions>
$ beat algorithms execute --examples
"""
Example:
$ beat algorithms execute <instructions>
$ beat algorithms execute --examples
"""
if example:
print_examples()
return 0
......
......@@ -89,8 +89,8 @@ class MutuallyExclusiveOption(click.Option):
class AssetInfo:
""" Information needed by the command to properly call local and remote
commands
"""Information needed by the command to properly call local and remote
commands
"""
def __init__(
......@@ -108,8 +108,8 @@ class AssetInfo:
class AssetCommand(click.Command):
""" Custom click command that will update the context with asset information
related to the command called.
"""Custom click command that will update the context with asset information
related to the command called.
"""
asset_info = AssetInfo()
......
......@@ -88,9 +88,9 @@ def list_impl(ctx, remote):
def path_impl(ctx, names):
"""Displays local path of asset files
Example:
$ beat <asset_type> path xxx
"""
Example:
$ beat <asset_type> path xxx
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
......@@ -104,9 +104,9 @@ def path_impl(ctx, names):
def edit_impl(ctx, name):
"""Edit local asset file
Example:
$ beat <asset_type> edit xxx
"""
Example:
$ beat <asset_type> edit xxx
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
......@@ -135,9 +135,9 @@ def check_impl(ctx, names):
def status_impl(ctx):
"""Shows (editing) status for all available items of asset type
Example:
$ beat <asset_type> status
"""
Example:
$ beat <asset_type> status
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
......
......@@ -42,6 +42,7 @@ import fnmatch
import glob
import logging
import os
from enum import Enum
from enum import unique
......@@ -307,24 +308,24 @@ def retrieve_remote_list(webapi, asset_type, fields):
"""Utility function used by commands to retrieve a remote list of objects
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
fields (:py:class:`list`): A list of fields to retrieve from the remote
server
fields (:py:class:`list`): A list of fields to retrieve from the remote
server
Returns:
Returns:
:py:class:`list`: A list of dictionaries containing the ``name``,
``short_description`` and ``hash`` of available remote objects.
:py:class:`list`: A list of dictionaries containing the ``name``,
``short_description`` and ``hash`` of available remote objects.
"""
"""
logger.debug("retrieving remote %s list...", TYPE_PLURAL[asset_type])
......@@ -338,31 +339,31 @@ def retrieve_remote_list(webapi, asset_type, fields):
def make_up_remote_list(webapi, asset_type, requirements):
"""Creates a list of downloadable objects from user requirements.
This function can create a list of downloadable objects from user
requirements. User requirements may point to valid object names (in which
case these are returned unchanged) or partial object names, which are used to
filter available remote resources. A list of fully resolved remote names
respecting user restrictions is returned.
This function can create a list of downloadable objects from user
requirements. User requirements may point to valid object names (in which
case these are returned unchanged) or partial object names, which are used to
filter available remote resources. A list of fully resolved remote names
respecting user restrictions is returned.
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
requirements (:py:class:`list`): A list of requirements that are used to
filter (additively) the available (remote) objects.
requirements (:py:class:`list`): A list of requirements that are used to
filter (additively) the available (remote) objects.
Returns:
Returns:
:py:class:`list`: A list of valid object names matching user requirements
and its order.
:py:class:`list`: A list of valid object names matching user requirements
and its order.
"""
"""
candidates = retrieve_remote_list(webapi, asset_type, ["name"])
......@@ -394,22 +395,22 @@ def make_up_remote_list(webapi, asset_type, requirements):
def display_remote_list(webapi, asset_type):
"""Implements a generic "list --remote" command
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest, on behalf of a pre-configured user.
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest, on behalf of a pre-configured user.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
remote_list = retrieve_remote_list(
webapi, asset_type, ["name", "short_description"]
......@@ -433,32 +434,32 @@ def display_remote_list(webapi, asset_type):
def make_up_local_list(prefix, asset_type, requirements):
"""Creates a list of uploadable objects from user requirements.
This function can create a list of uploadable objects from user requirements.
User requirements may point to valid object names (in which case these are
returned unchanged) or partial object names, which are used to filter
available local resources. A list of fully resolved local names respecting
user restrictions is returned.
This function can create a list of uploadable objects from user requirements.
User requirements may point to valid object names (in which case these are
returned unchanged) or partial object names, which are used to filter
available local resources. A list of fully resolved local names respecting
user restrictions is returned.
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
requirements (:py:class:`list`): A list of requirements that are used to
filter (additively) the available (remote) objects.
requirements (:py:class:`list`): A list of requirements that are used to
filter (additively) the available (remote) objects.
Returns:
Returns:
:py:class:`list`: A list of strings, each with the relative name of an
object belonging to a certain category and in the order prescribed by the
user.
:py:class:`list`: A list of strings, each with the relative name of an
object belonging to a certain category and in the order prescribed by the
user.
"""
"""
root = os.path.join(prefix, TYPE_PLURAL[asset_type])
asset_path_list = glob.glob(os.path.join(root, TYPE_GLOB[asset_type]))
......@@ -500,22 +501,22 @@ def display_local_list(prefix, asset_type):
"""Implements the local "list" command
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
names = make_up_local_list(prefix, asset_type, [])
......@@ -543,22 +544,22 @@ def display_local_path(prefix, asset_type, names):
"""Implements the local "path" command
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
selected_type = None
......@@ -599,22 +600,22 @@ def edit_local_file(prefix, editor, asset_type, name):
"""Implements the local "path" command
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
selected_type = None
......@@ -666,17 +667,17 @@ def edit_local_file(prefix, editor, asset_type, name):
def make_webapi(config):
"""Instantiates an usable web-api proxy using the command-line configuration
Parameters:
Parameters:
config (object): The command-line configuration object, from which this function
will extract the ``platform``, ``user`` and ``token`` parameters.
config (object): The command-line configuration object, from which this function
will extract the ``platform``, ``user`` and ``token`` parameters.
Returns
Returns
WebAPI: A valid web-api proxy instance
WebAPI: A valid web-api proxy instance
"""
"""
from .webapi import WebAPI
......@@ -687,21 +688,21 @@ def check_one(prefix, asset_type, name):
"""Implements object validation for a single, well-defined object
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
name (str): The name of the object, representing the unique relative path
of the objects to check (e.g. ``user/integer/1``)
name (str): The name of the object, representing the unique relative path
of the objects to check (e.g. ``user/integer/1``)
klass (type): A python class that validates the object. It must accept the
object
klass (type): A python class that validates the object. It must accept the
object
"""
"""
o = TYPE_VALIDATOR[asset_type](prefix, name)
......@@ -720,26 +721,26 @@ def check(prefix, asset_type, names):
"""Implements object validation
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to check. If the list is empty, then we
check all available objects of a given type.
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to check. If the list is empty, then we
check all available objects of a given type.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
names = make_up_local_list(prefix, asset_type, names)
return sum([check_one(prefix, asset_type, name) for name in names])
......@@ -748,25 +749,25 @@ def check(prefix, asset_type, names):
def fetch_object(webapi, asset_type, name, fields):
"""Retrieves a single well-known object from the server
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
name (str): A string defining the name of the object to retrieve
name (str): A string defining the name of the object to retrieve
fields (:py:class:`list`): A list of fields to retrieve from the remote
server
fields (:py:class:`list`): A list of fields to retrieve from the remote
server
Returns:
Returns:
dict: A dictionary containing the object contents
dict: A dictionary containing the object contents
"""
"""
fields = "?object_format=string&fields=%s" % ",".join(fields)
if name is not None:
......@@ -781,49 +782,49 @@ def pull(webapi, prefix, asset_type, names, fields, force, indentation):
"""Copies objects from the server to the local prefix
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to retrieve or a list of usernames from
which to retrieve objects. If the list is empty, then we pull all
available objects of a given type. If no user is set, then pull all
public objects of a given type.
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to retrieve or a list of usernames from
which to retrieve objects. If the list is empty, then we pull all
available objects of a given type. If no user is set, then pull all
public objects of a given type.
fields (:py:class:`list`): A list of strings, each defining one field that
**must** be downloaded from the web-server for a given object of the
current type and passed, unchanged to the storage ``save()`` method. For
example, for toolchains, this value shall be ``['declaration']``. For
algorithms, it shall be ``['declaration', 'code']``.
fields (:py:class:`list`): A list of strings, each defining one field that
**must** be downloaded from the web-server for a given object of the
current type and passed, unchanged to the storage ``save()`` method. For
example, for toolchains, this value shall be ``['declaration']``. For
algorithms, it shall be ``['declaration', 'code']``.
force (bool): If set to ``True``, then overwrites local changes with the
remotely retrieved copies.
force (bool): If set to ``True``, then overwrites local changes with the
remotely retrieved copies.
indentation (int): The indentation level, useful if this function is called
recursively while downloading different object types. This is normally
set to ``0`` (zero).
indentation (int): The indentation level, useful if this function is called
recursively while downloading different object types. This is normally
set to ``0`` (zero).
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
:py:class:`list`: A list of strings containing the names of objects
successfuly downloaded or which were already present on the current
installation (if the user has chosen not to ``--force`` the override), in
the order of their download.
:py:class:`list`: A list of strings containing the names of objects
successfuly downloaded or which were already present on the current
installation (if the user has chosen not to ``--force`` the override), in
the order of their download.
"""
"""
names = make_up_remote_list(webapi, asset_type, names)
if not names:
......@@ -866,7 +867,10 @@ def pull(webapi, prefix, asset_type, names, fields, force, indentation):
try:
file_data = webapi.download(
"/api/v1/%s/%s/file/"
% (TYPE_PLURAL[asset_type], storage.fullname,)
% (
TYPE_PLURAL[asset_type],
storage.fullname,
)
)
data["code"] = file_data
except Exception as e:
......@@ -885,33 +889,33 @@ def diff(webapi, prefix, asset_type, name, fields):
"""Shows the differences between two objects, for each of the fields
Parameters:
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
name (str): A string defining the name of the object to calculate
differences from.
name (str): A string defining the name of the object to calculate
differences from.
fields (:py:class:`list`): A list of strings, each defining one field that
**must** be downloaded from the web-server for a given object of the
current type. For example, for toolchains, this value shall be
``['declaration']``. For algorithms, it shall be ``['declaration',
'code']``.
fields (:py:class:`list`): A list of strings, each defining one field that
**must** be downloaded from the web-server for a given object of the
current type. For example, for toolchains, this value shall be
``['declaration']``. For algorithms, it shall be ``['declaration',
'code']``.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
extension = {"code": ".py", "declaration": ".json", "description": ".rst"}
......@@ -985,24 +989,24 @@ def create(prefix, asset_type, names):
"""Creates an empty object of a certain type under the given name
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
names (str): A string defining the names of the objects to create.
names (str): A string defining the names of the objects to create.
Returns:
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
"""
status = 0
......@@ -1028,27 +1032,27 @@ def create(prefix, asset_type, names):
def copy(prefix, asset_type, src, dst):
"""Creates a new object by copying another object of the same type.
Parameters:
Parameters:
prefix (str): A string representing the root of the path in which the user
objects are stored
prefix (str): A string representing the root of the path in which the user
objects are stored
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,
``toolchain`` or ``experiment``.
asset_type (str): One of ``database``, ``dataformat``, ``algorithm``,