Commit 58b6641d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments] Port to AssetCommand and implent dependency handling for push

parent 76283061
......@@ -63,9 +63,13 @@ from . import commands
from .plotters import plot_impl as plotters_plot
from .plotters import pull_impl as plotters_pull
from .decorators import raise_on_error
from .click_helper import AliasedGroup
from .click_helper import MutuallyExclusiveOption
from .click_helper import AssetCommand
from .click_helper import AssetInfo
logger = logging.getLogger(__name__)
......@@ -705,18 +709,39 @@ def plot_impl(
return status
def get_dependencies(ctx, asset_name):
prefix = ctx.meta["config"].path
exp = Experiment(prefix, asset_name)
dependencies = {"toolchains": [exp.toolchain.name]}
algorithms = list(exp.algorithms.keys())
if algorithms:
dependencies["algorithms"] = algorithms
# databases are not considered as dependencies as they can't be uploaded.
return dependencies
class ExperimentCommand(AssetCommand):
asset_info = AssetInfo(
asset_type="experiment",
diff_fields=["declaration", "description"],
push_fields=["name", "declaration", "toolchain", "description"],
get_dependencies=get_dependencies,
)
@click.group(cls=AliasedGroup)
@click.pass_context
def experiments(ctx):
"""experiments commands"""
ctx.meta["asset_type"] = "experiment"
ctx.meta["diff_fields"] = ["declaration", "description"]
CMD_LIST = ["list", "path", "edit", "check", "status", "fork", "rm", "diff"]
CMD_LIST = ["list", "path", "edit", "check", "status", "fork", "rm", "diff", "push"]
commands.initialise_asset_commands(experiments, CMD_LIST)
commands.initialise_asset_commands(experiments, CMD_LIST, ExperimentCommand)
@experiments.command()
......@@ -796,39 +821,6 @@ def pull(ctx, names, force):
return pull_impl(webapi, config.path, names, force, 0, {})
@experiments.command()
@click.argument("names", nargs=-1)
@click.option(
"--force", help="Performs operation regardless of conflicts", is_flag=True
)
@click.option(
"--dry-run",
help="Doesn't really perform the task, just " "comments what would do",
is_flag=True,
)
@click.pass_context
@raise_on_error
def push(ctx, names, force, dry_run):
"""Uploads experiments to the server.
Example:
$ beat experiments push --dry-run yyy
"""
config = ctx.meta.get("config")
with common.make_webapi(config) as webapi:
return common.push(
webapi,
config.path,
"experiment",
names,
["name", "declaration", "toolchain", "description"],
{},
force,
dry_run,
0,
)
@experiments.command()
@click.argument("names", nargs=-1)
@click.option(
......
......@@ -66,6 +66,9 @@ class TestOnlineExperiments(core.OnlineAssetTestCase):
object_map = {
"pull": "user/user/single/1/single",
"diff": "user/user/single/1/single",
"push": "user/user/unknown/1/unknown",
"push": "user/user/unknown/1/unknown",
"not_owner_push": "other_user/other_user/somechain/1/someexp",
}
def _modify_asset(self, asset_name):
......@@ -98,18 +101,6 @@ class TestOnlineExperiments(core.OnlineAssetTestCase):
nose.tools.eq_(exit_code, 0, outputs)
nose.tools.assert_false(storage.exists())
@core.skip_disconnected
def test_push_and_delete(self):
obj = "user/user/double_triangle/1/double_triangle"
obj2 = "user/user/double_triangle/1/different"
self.test_fork(obj, obj2)
# now push the fork and then delete it remotely
exit_code, outputs = self.call("push", obj2, prefix=tmp_prefix)
nose.tools.eq_(exit_code, 0, outputs)
exit_code, outputs = self.call("rm", "--remote", obj2, prefix=tmp_prefix)
nose.tools.eq_(exit_code, 0, outputs)
@core.skip_disconnected
def test_draw(self):
obj = "user/user/double_triangle/1/double_triangle"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment