Skip to content

Commit

Permalink
Add bazel options arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Mickael Gaillard <[email protected]>
  • Loading branch information
Theosakamg committed Aug 22, 2018
1 parent 2cc3831 commit cfb901d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
22 changes: 19 additions & 3 deletions colcon_bazel/argcomplete_completer/bazel_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,36 @@ def __init__(self): # noqa: D107
ArgcompleteCompleterExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')

def get_completer(self, parser, *args, **kwargs): # noqa: D102
if '--bazel-args' not in args:
if not any(elem in args for elem in ['--bazel-args', '--bazel-opts']):
return None

try:
from argcomplete.completers import ChoicesCompleter
except ImportError:
return None

return ChoicesCompleter(get_bazel_args_completer_choices())
if '--bazel-opts' in args:
return ChoicesCompleter(get_bazel_opts_completer_choices())

if '--bazel-args' in args:
return ChoicesCompleter(get_bazel_args_completer_choices())


def get_bazel_args_completer_choices():
"""
Get the Bazel completer choices.
Get the Bazel arguments completer choices.
Currently this empty.
:rtype: list
"""
# HACK the quote and equal characters are currently a problem
# see https://github.com/kislyuk/argcomplete/issues/94
return []


def get_bazel_opts_completer_choices():
"""
Get the Bazel options completer choices.
Currently this empty.
:rtype: list
Expand Down
6 changes: 3 additions & 3 deletions colcon_bazel/task/bazel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def get_bazel_startup_options(args):
:returns: startup options
:rtype: list
"""
bazel_args = (args.bazel_args or [])
tmp_args = ' '.join(bazel_args)
bazel_opts = (args.bazel_opts or [])
tmp_opts = ' '.join(bazel_opts)

regex = '.*(' + BZL_OUTPUT + '|' + BZL_INSTALL + ').*'
if (not re.match(regex, tmp_args)):
if (not re.match(regex, tmp_opts)):
# Default Bazel 'build' & 'install' folder for colcon.
output_path = BZL_OUTPUT + '=' + args.build_base + '/bazel'
install_path = BZL_INSTALL + '=' + args.install_base + '/bazel'
Expand Down
10 changes: 7 additions & 3 deletions colcon_bazel/task/bazel/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ def __init__(self): # noqa: D107
satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')

def add_arguments(self, *, parser): # noqa: D102
parser.add_argument(
'--bazel-opts',
nargs='*', metavar='*', type=str.lstrip,
help='Append specific options of the default options')
parser.add_argument(
'--bazel-task',
help='Run a specific task instead of the default task')
parser.add_argument(
'--bazel-args',
nargs='*', metavar='*', type=str.lstrip,
help='Pass arguments to Bazel projects. '
'Arguments matching other options must be prefixed by a space,\n'
'e.g. --bazel-args " --help"')
parser.add_argument(
'--bazel-task',
help='Run a specific task instead of the default task')

async def build(
self, *, additional_hooks=None, skip_hook_creation=False
Expand Down
10 changes: 7 additions & 3 deletions colcon_bazel/task/bazel/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ def __init__(self): # noqa: D107
satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')

def add_arguments(self, *, parser): # noqa: D102
parser.add_argument(
'--bazel-opts',
nargs='*', metavar='*', type=str.lstrip,
help='Append specific options of the default options')
parser.add_argument(
'--bazel-task',
help='Run a specific task instead of the default task')
parser.add_argument(
'--bazel-args',
nargs='*', metavar='*', type=str.lstrip,
help='Pass arguments to Bazel projects. '
'Arguments matching other options must be prefixed by a space,\n'
'e.g. --bazel-args " --help"')
parser.add_argument(
'--bazel-task',
help='Run a specific task instead of the default task')

async def test(self, *, additional_hooks=None): # noqa: D102
pkg = self.context.pkg
Expand Down
19 changes: 17 additions & 2 deletions test/test_argcomplete_completer_bazel_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import BazelArgcompleteCompleter
from colcon_bazel.argcomplete_completer.bazel_args \
import get_bazel_args_completer_choices
from colcon_bazel.argcomplete_completer.bazel_args \
import get_bazel_opts_completer_choices
import sys
import pytest

Expand All @@ -14,9 +16,14 @@
def test_get_completer():
extension = BazelArgcompleteCompleter()

args=['--bazel-args']
karg={'--bazel-args': 'test'}
assert extension.get_completer(None, None, None) is None

args=['--bazel-args']
karg={'--bazel-args': 'test-args'}
assert extension.get_completer(None, *args, **karg) is not None

args=['--bazel-opts']
karg={'--bazel-opts': 'test-opts'}
assert extension.get_completer(None, *args, **karg) is not None


Expand All @@ -26,3 +33,11 @@ def test_get_bazel_args_completer_choices():
choices = get_bazel_args_completer_choices()

assert len(choices) == 0


@pytest.mark.skipif(sys.platform == 'win32',
reason='does not run on windows')
def test_get_bazel_opts_completer_choices():
choices = get_bazel_opts_completer_choices()

assert len(choices) == 0

0 comments on commit cfb901d

Please sign in to comment.