Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

allow multiple package names for --only-packages #114

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 49 additions & 47 deletions ament_tools/verbs/build/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def prepare_arguments(parser, args):
help='End with a particular package',
)
parser.add_argument(
'--only-package',
'--only',
help='Only process a particular package, implies --start-with <pkg> and --end-with <pkg>'
'--only-packages',
nargs='+', default=[],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to keep the --only alias for convenience ?

Copy link
Contributor Author

@dirk-thomas dirk-thomas Nov 7, 2016

Choose a reason for hiding this comment

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

Any shorter but unique variation of arguments is always available. That's also why renaming it from --only-package to --only-packages is backward compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, but it won't be displayed in the help message anymore if it is removed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but neither do many of the other arguments have that kind of alternative explicit shortcut. If more people want to keep it please feel free to readd it.

Copy link
Contributor

Choose a reason for hiding this comment

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

it will be an extra option that we have to maintain auto-complete for so I'd support leaving it off the list

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, let's leave it out then

help='Only process a particular set of packages'
Copy link
Contributor

Choose a reason for hiding this comment

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

'List of packages to process' would be more consistent with the --skip-packages help (and makes it clear it's not a flag)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the existing help string to use set too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that the whole phrase makes it sounds like a boolean flag to me. but the array "type" in the help output will make it clearer

)
parser.add_argument(
'--skip-packages',
nargs='*',
help='List of packages to skip'
nargs='*', default=[],
help='Set of packages to skip'
)
parser.add_argument(
'--parallel',
Expand Down Expand Up @@ -161,14 +161,20 @@ def main(opts, per_package_main=build_pkg_main):
raise VerbExecutionError('Circular dependency within the following '
'packages: %s' % circular_dependencies[0])

print_topological_order(opts, packages)
pkg_names = [p.name for _, p, _ in packages]
check_opts(opts, pkg_names)
consolidate_package_selection(opts, pkg_names)
print_topological_order(opts, pkg_names)

return iterate_packages(opts, packages, per_package_main)
if set(pkg_names) <= set(opts.skip_packages):
print('All selected packages are being skipped. Nothing to do.',
file=sys.stderr)
return 0

return iterate_packages(opts, packages, per_package_main)

def print_topological_order(opts, packages):
package_names = [p.name for _, p, _ in packages]

def check_opts(opts, package_names):
if opts.start_with and opts.start_with not in package_names:
sys.exit("Package '{0}' specified with --start-with was not found."
.format(opts.start_with))
Expand All @@ -177,77 +183,73 @@ def print_topological_order(opts, packages):
sys.exit("Package '{0}' specified with --end-with was not found."
.format(opts.end_with))

if 'skip_packages' not in opts:
opts.skip_packages = []
else:
opts.skip_packages = opts.skip_packages or []
nonexistent_skip_packages = []
for skip_package in opts.skip_packages:
if skip_package not in package_names:
nonexistent_skip_packages.append(skip_package)
if skip_package == opts.only_package:
sys.exit("Cannot --skip-packages and --only-package the same package: '{0}'."
.format(skip_package))
nonexistent_skip_packages = set(opts.skip_packages) - set(package_names)
if nonexistent_skip_packages:
sys.exit('Packages [{0}] specified with --skip-packages were not found.'
.format(', '.join(nonexistent_skip_packages)))
sys.exit('Packages [{0}] specified with --skip-packages were not found.'
.format(', '.join(sorted(nonexistent_skip_packages))))

if opts.only_package:
if opts.only_packages:
if opts.start_with or opts.end_with:
# The argprase mutually exclusive mechanism is broken for subparsers
# See: http://bugs.python.org/issue10680
# So we'll check it manually here
sys.exit("The --start-with and --end-with options cannot be used with "
"the --only-package option.")
if opts.only_package not in package_names:
sys.exit("Package '{0}' specified with --only-package was not found."
.format(opts.only_package))
opts.start_with = opts.only_package
opts.end_with = opts.only_package

if opts.start_with and opts.end_with and not opts.only_package:
"the --only-packages option.")
for only_package in opts.only_packages:
if only_package not in package_names:
sys.exit("Package '{0}' specified with --only-packages was not found."
.format(only_package))

if opts.start_with and opts.end_with:
# Make sure that the --end-with doesn't come before the --start-with package.
test_start_with_found = False
for (path, package, _) in packages:
if package.name == opts.start_with:
for pkg_name in package_names:
if pkg_name == opts.start_with:
test_start_with_found = True
if package.name == opts.end_with:
if pkg_name == opts.end_with:
if not test_start_with_found:
sys.exit("The --end-with package '{0}' occurs topologically "
"before the --start-with package '{1}'"
.format(opts.end_with, opts.start_with))
break

print('# Topological order')

def consolidate_package_selection(opts, package_names):
# after this function opts.skip_packages will contain the information from:
# start_with, end_with, only_packages
start_with_found = not opts.start_with
end_with_found = not opts.end_with
for (path, package, _) in packages:
if package.name == opts.start_with:
for pkg_name in package_names:
if pkg_name == opts.start_with:
start_with_found = True
should_skip = False
if not start_with_found or (opts.end_with and end_with_found):
should_skip = True
if package.name in opts.skip_packages:
if opts.only_packages and pkg_name not in opts.only_packages:
should_skip = True
if should_skip:
print(' - (%s)' % package.name)
else:
print(' - %s' % package.name)
if package.name == opts.end_with:
if pkg_name not in opts.skip_packages:
opts.skip_packages.append(pkg_name)
if pkg_name == opts.end_with:
end_with_found = True


def print_topological_order(opts, package_names):
print('# Topological order')
for pkg_name in package_names:
if pkg_name in opts.skip_packages:
print(' - (%s)' % pkg_name)
else:
print(' - %s' % pkg_name)


def iterate_packages(opts, packages, per_package_callback):
start_with_found = not opts.start_with
opts.skip_packages = opts.skip_packages or []
install_space_base = opts.install_space
package_dict = dict([(path, package) for path, package, _ in packages])
workspace_package_names = [pkg.name for pkg in package_dict.values()]
jobs = OrderedDict()
for (path, package, depends) in packages:
if package.name == opts.start_with:
start_with_found = True
if not start_with_found or package.name in opts.skip_packages:
if package.name in opts.skip_packages:
print('# Skipping: %s' % package.name)
else:
pkg_path = os.path.join(opts.basepath, path)
Expand Down
4 changes: 2 additions & 2 deletions completion/ament-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ _ament()
COMPREPLY=($(compgen -W "$(ament list_packages --names-only)" -- ${cur}))
elif [[ "--end-with" == *${prev}* && ${cur} != -* ]] ; then
COMPREPLY=($(compgen -W "$(ament list_packages --names-only)" -- ${cur}))
elif [[ "--only-package" == *${prev}* && ${cur} != -* ]] ; then
elif [[ "--only-packages" == *${prev}* && ${cur} != -* ]] ; then
COMPREPLY=($(compgen -W "$(ament list_packages --names-only)" -- ${cur}))
elif [[ "--cmake-args" == *${prev}* && ${cur} != -* ]] ; then
COMPREPLY=($(compgen -W "-DCMAKE_BUILD_TYPE=" -- ${cur}))
else
COMPREPLY=($(compgen -W "--ament-cmake-args --build-space --build-tests -C --cmake-args --end-with --force-ament-cmake-configure --force-cmake-configure --make-flags --install-space --isolated --only-package --parallel --skip-build --skip-install --start-with --symlink-install" -- ${cur}))
COMPREPLY=($(compgen -W "--ament-cmake-args --build-space --build-tests -C --cmake-args --end-with --force-ament-cmake-configure --force-cmake-configure --make-flags --install-space --isolated --only-packages --parallel --skip-build --skip-install --start-with --symlink-install" -- ${cur}))
fi
elif [[ "${COMP_WORDS[@]}" == *" list_packages"* ]] ; then
if [[ "--depends-on" == *${prev}* && ${cur} != -* ]] ; then
Expand Down