Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
986b1d79
Commit
986b1d79
authored
Oct 18, 2019
by
Samuel GAIST
Browse files
[algorithms] Port to AssetCommand and implent dependency handling for push
parent
5d40e6b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/algorithms.py
View file @
986b1d79
...
...
@@ -45,12 +45,15 @@ from beat.core.execution import DockerExecutor
from
beat.core.dock
import
Host
from
beat.core
import
hash
from
beat.backend.python.algorithm
import
Storage
as
AlgorithmStorage
from
beat.backend.python.algorithm
import
Algorithm
from
.
import
common
from
.
import
commands
from
.decorators
import
raise_on_error
from
.click_helper
import
AliasedGroup
from
.click_helper
import
AssetCommand
from
.click_helper
import
AssetInfo
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -325,14 +328,37 @@ def execute_impl(prefix, cache, instructions_file):
return
0
def
get_dependencies
(
ctx
,
asset_name
):
prefix
=
ctx
.
meta
[
"config"
].
path
alg
=
Algorithm
(
prefix
,
asset_name
)
dependencies
=
{}
libraries
=
list
(
alg
.
libraries
.
keys
())
if
libraries
:
dependencies
[
"libraries"
]
=
libraries
dataformats
=
list
(
alg
.
dataformats
.
keys
())
if
dataformats
:
dependencies
[
"dataformats"
]
=
dataformats
return
dependencies
class
AlgorithmCommand
(
AssetCommand
):
asset_info
=
AssetInfo
(
asset_type
=
"algorithm"
,
diff_fields
=
[
"declaration"
,
"code"
,
"description"
],
push_fields
=
[
"name"
,
"declaration"
,
"code"
,
"description"
],
get_dependencies
=
get_dependencies
,
)
@
click
.
group
(
cls
=
AliasedGroup
)
@
click
.
pass_context
def
algorithms
(
ctx
):
"""Configuration and manipulation of algorithms"""
ctx
.
meta
[
"asset_type"
]
=
"algorithm"
ctx
.
meta
[
"diff_fields"
]
=
[
"declaration"
,
"code"
,
"description"
]
CMD_LIST
=
[
"list"
,
...
...
@@ -345,9 +371,10 @@ CMD_LIST = [
"fork"
,
"rm"
,
"diff"
,
"push"
,
]
commands
.
initialise_asset_commands
(
algorithms
,
CMD_LIST
)
commands
.
initialise_asset_commands
(
algorithms
,
CMD_LIST
,
AlgorithmCommand
)
@
algorithms
.
command
()
...
...
@@ -367,38 +394,6 @@ def pull(ctx, name, force):
return
pull_impl
(
webapi
,
ctx
.
meta
[
"config"
].
path
,
name
,
force
,
0
,
{},
{})
@
algorithms
.
command
()
@
click
.
argument
(
"name"
,
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
,
name
,
force
,
dry_run
):
"""Uploads algorithms to the server
Example:
$ beat algorithms push --dry-run yyy
"""
with
common
.
make_webapi
(
ctx
.
meta
[
"config"
])
as
webapi
:
return
common
.
push
(
webapi
,
ctx
.
meta
[
"config"
].
path
,
"algorithm"
,
name
,
[
"name"
,
"declaration"
,
"code"
,
"description"
],
{},
force
,
dry_run
,
0
,
)
@
algorithms
.
command
()
@
click
.
argument
(
"instructions"
,
nargs
=
1
)
@
click
.
option
(
...
...
beat/cmdline/test/test_algorithms.py
View file @
986b1d79
...
...
@@ -38,7 +38,6 @@
import
nose.tools
from
beat.core.test.utils
import
slow
from
beat.core.algorithm
import
Storage
from
beat.core.dataformat
import
Storage
as
DFStorage
...
...
@@ -46,7 +45,7 @@ from . import core
from
.
import
tmp_prefix
class
TestOnlinAlgorithms
(
core
.
OnlineAssetTestCase
):
class
TestOnlin
e
Algorithms
(
core
.
OnlineAssetTestCase
):
asset_type
=
"algorithm"
storage_cls
=
Storage
...
...
@@ -54,6 +53,8 @@ class TestOnlinAlgorithms(core.OnlineAssetTestCase):
"pull"
:
"user/integers_add/1"
,
"diff"
:
"user/integers_add/1"
,
"create"
:
"user/newobject/1"
,
"push"
:
"user/db_input_loop_processor/1"
,
"not_owner_push"
:
"v1/integers_add/1"
,
}
def
_modify_asset
(
self
,
asset_name
):
...
...
@@ -62,27 +63,6 @@ class TestOnlinAlgorithms(core.OnlineAssetTestCase):
storage
=
self
.
storage_cls
(
tmp_prefix
,
asset_name
)
storage
.
code
.
save
(
"class Algorithm:
\n
pass"
)
def
create_dataformat
(
self
):
obj
=
"user/integers/1"
storage
=
DFStorage
(
tmp_prefix
,
obj
)
if
not
storage
.
exists
():
exit_code
,
outputs
=
TestAlgorithmLocal
.
call
(
"create"
,
obj
,
prefix
=
tmp_prefix
,
asset_type
=
"dataformat"
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
exit_code
,
outputs
=
self
.
call
(
"push"
,
obj
,
prefix
=
tmp_prefix
,
asset_type
=
"dataformat"
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
@
slow
@
core
.
skip_disconnected
def
test_push_and_delete
(
self
):
self
.
create_dataformat
()
super
().
test_push_and_delete
()
class
TestAlgorithmLocal
(
core
.
AssetLocalTest
):
storage_cls
=
Storage
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment