Skip to content

Conversation

@rsarm
Copy link
Contributor

@rsarm rsarm commented Jan 14, 2021

This PR adds command-line auto-completion to ReFrame through the argcomplete package. It also adds some automatically generated shell script code that users will need to source in order to enable auto-completion for their shells.

Closes #725

@rsarm
Copy link
Contributor Author

rsarm commented Jan 14, 2021

So far this is a bit of a poc. On Daint this can be tested with

module load reframe
. ac-reframe.sh

Currently, this supports completion of command line options:

$> reframe [TAB][TAB]
-c               --help                    --module-mappings         -R                  -t
-C               --ignore-check-conflicts  --module-path             --recursive         --tag
--checkpath      -J                        -n                        --report-file       --timestamp
--config-file    --job-option              --name                    --restore-session   -u
--cpu-only       --keep-stage-files        --nocolor                 --run               --unload-module
(...)

files and directories for -c, --checkpath, -C and --config-file:

$> reframe -r -c cscs-checks/[TAB][TAB]
analytics/           apps/            compile/         libraries/       mch/            
microbenchmarks/     prgenv/          system/          tools/ 

and test names given a directory or file through the -c option

$> reframe -r -c cscs-checks/apps/quantumespresso/ -n  [TAB][TAB] QuantumESPRESSO
$> reframe -r -c cscs-checks/apps/quantumespresso/ -n QuantumESPRESSO[TAB][TAB]
QuantumESPRESSOCpuCheck_large_maint  QuantumESPRESSOCpuCheck_small_maint  
QuantumESPRESSOGpuCheck_large_maint  QuantumESPRESSOGpuCheck_small_maint
QuantumESPRESSOCpuCheck_large_prod   QuantumESPRESSOCpuCheck_small_prod   
QuantumESPRESSOGpuCheck_large_prod   QuantumESPRESSOGpuCheck_small_prod

@vkarak vkarak changed the title [wip] Add Bash completion support to ReFrame [feat] Add Bash completion support to ReFrame Jan 15, 2021
@teojgo teojgo self-requested a review January 19, 2021 09:30
@codecov-io
Copy link

codecov-io commented Jan 22, 2021

Codecov Report

Merging #1685 (cccaf73) into master (58d43d6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1685   +/-   ##
=======================================
  Coverage   87.33%   87.34%           
=======================================
  Files          46       46           
  Lines        7740     7742    +2     
=======================================
+ Hits         6760     6762    +2     
  Misses        980      980           
Impacted Files Coverage Δ
reframe/frontend/argparse.py 92.42% <100.00%> (+0.11%) ⬆️
reframe/frontend/cli.py 76.79% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58d43d6...cccaf73. Read the comment docs.

Copy link
Contributor

@vkarak vkarak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just played a bit with this PR. These are some problems I've noticed:

  • Strange characters when auto-completing command-line options:
$ reframe --c
--checkpath^[[m^[[K  --config-file^[[m^[[K--cpu-only^[[m^[[K
  • The same happens when it auto-completes the command-line:
$ reframe --checkpath^[\[m^[\[K

@rsarm
Copy link
Contributor Author

rsarm commented Feb 5, 2021

@vkarak in which terminal did you try?

@vkarak
Copy link
Contributor

vkarak commented Feb 5, 2021

@rsarm I tried on my Mac's bash. But then I started playing with argcomplete and tried to understand why it doesn't work in our case. Actually, it seems that it can work with our setup, but there is something that we still need to figure out. If you run the following Python script (using our ArgParser, slightly modified (see below)) it works:

#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK

import argcomplete
from argcomplete.completers import EnvironCompleter

import reframe.frontend.argparse as argparse


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--env-var1").completer = EnvironCompleter
    parser.add_argument("--env-var2").completer = EnvironCompleter
    parser.add_argument("--env-var3").completer = EnvironCompleter
    options = parser.parse_args()


if __name__ == '__main__':
    main()

And I added the following two lines in our ArgParser:

@@ -257,6 +257,9 @@ class ArgumentParser(_ArgumentHolder):
         `add_argument()` call. If no default value was specified either, the
         attribute will be set to `None`.'''

+        import argcomplete
+        argcomplete.autocomplete(self._holder)
+
         # We always pass an empty namespace to our internal argparser and we do
         # the namespace resolution ourselves. We do this, because we want the
         # newly parsed options to completely override any options defined in

Now if I try to run ./bin/reframe (with PYTHON_ARGCOMPLETE_OK), which uses the exact same parser it doesn't work. I think we need to replicate the file structure of ./bin/reframe and cli.py with completely stripped down versions and see why it can't pick the autocompletion in that case, because in principle the trick above can make it work. So it must be something in-between that is happening.

@vkarak vkarak changed the title [feat] Add Bash completion support to ReFrame [feat] Add auto completion support to ReFrame Feb 5, 2021
@vkarak vkarak marked this pull request as ready for review February 6, 2021 23:03
Copy link
Contributor

@vkarak vkarak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vkarak vkarak merged commit d173849 into reframe-hpc:master Feb 8, 2021
@rsarm rsarm deleted the feat/autocomplete branch March 10, 2021 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Bash completion support to ReFrame

4 participants