Skip to content

Commit 74686f7

Browse files
committed
Merge branch 'master' into advanced
2 parents ec8835e + e97a272 commit 74686f7

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: python
2-
dist: trusty
2+
dist: xenial
33
cache: pip
44
branches:
55
only:

doc/command_line.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
RAMP-workflow commands
44
######################
55

6+
The following commands are built using the
7+
`click <https://click.palletsprojects.com/en/7.x/>`_ package which provides tab
8+
completion for the command options. You however need to activate shell
9+
completion by following the instructions given in the `click documentation <https://click.palletsprojects.com/en/7.x/bashcomplete/#activation>`_.
10+
The `ramp-test` command also comes with tab completion for the submission name
11+
if the submission you are looking for is located in the `./submissions/` folder.
12+
613
.. click:: rampwf.utils.cli.testing:main
714
:prog: ramp-test
815
:show-nested:

rampwf/utils/cli/testing.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,34 @@
99
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
1010

1111

12+
def get_submissions(ctx, args, incomplete):
13+
"""Callback function for submission autocomplete.
14+
15+
Find the possible submission names and use them for autocompletion.
16+
This only works if the submissions can be found in a 'submissions' folder.
17+
18+
See click documentation for more information on the signature of the
19+
function.
20+
"""
21+
submission_dir_path = os.path.join('.', 'submissions')
22+
try:
23+
all_submissions = [
24+
f.name for f in os.scandir(submission_dir_path)
25+
if f.is_dir() and f.name != '__pycache__']
26+
except FileNotFoundError:
27+
return []
28+
else:
29+
valid_submissions = [submission for submission in all_submissions
30+
if incomplete in submission]
31+
return valid_submissions
32+
33+
1234
@click.command(context_settings=CONTEXT_SETTINGS)
1335
@click.option('--submission', default='starting_kit', show_default=True,
1436
help='The kit to test. It should be located in the '
1537
'"submissions" folder of the starting kit. If "ALL", all '
16-
'submissions in the directory will be tested.')
38+
'submissions in the directory will be tested.',
39+
autocompletion=get_submissions)
1740
@click.option('--ramp-kit-dir', default='.', show_default=True,
1841
help='Root directory of the ramp-kit to test.')
1942
@click.option('--ramp-data-dir', default='.', show_default=True,

rampwf/utils/cli/tests/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
import pandas as pd
44
import numpy as np
55

6+
from rampwf.utils.cli.testing import get_submissions
67
from rampwf.utils.cli.show import _bagged_table_and_headers
78
from rampwf.utils.cli.show import _mean_table_and_headers
89
from rampwf.utils.cli.show import _load_score_submission
910
PATH = os.path.dirname(__file__)
1011

1112

13+
def test_get_submissions(monkeypatch):
14+
iris_kit_path = os.path.join(
15+
PATH, '..', '..', '..', 'tests', 'kits', 'iris')
16+
monkeypatch.chdir(iris_kit_path)
17+
18+
assert ['starting_kit'] == get_submissions(None, None, 'star')
19+
completed_submissions = get_submissions(None, None, '')
20+
true_submissions = ['starting_kit', 'random_forest_10_10']
21+
# check ignoring order
22+
assert len(completed_submissions) == len(true_submissions)
23+
assert set(completed_submissions) == set(true_submissions)
24+
25+
1226
def test_bagged_table_and_headers():
1327
path_submissions = os.path.join(
1428
PATH, '..', '..', '..', 'tests', 'kits', 'iris',

0 commit comments

Comments
 (0)