Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --packages-above-depth selection mechanism #22

Merged
merged 3 commits into from
Mar 18, 2019
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
45 changes: 45 additions & 0 deletions colcon_package_selection/package_selection/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0

import argparse
import sys

from colcon_core.package_selection import logger
from colcon_core.package_selection import PackageSelectionExtensionPoint
from colcon_core.plugin_system import satisfies_version


class _DepthAndPackageNames(argparse.Action):
"""Action to assign an integer depth optional package names."""

def __call__(self, parser, namespace, values, option_string=None):
assert len(values) >= 1
try:
values[0] = int(values[0])
if values[0] < 0:
raise ValueError()
except ValueError:
raise argparse.ArgumentError(
self, 'the first parameter must be a non-negative integer for '
'the depth')
setattr(namespace, self.dest, values)


class DependenciesPackageSelection(PackageSelectionExtensionPoint):
"""Select packages based on their dependencies."""

Expand All @@ -25,6 +42,11 @@ def add_arguments(self, *, parser): # noqa: D102
'--packages-above', nargs='*', metavar='PKG_NAME',
help='Only process a subset of packages and packages which '
'recursively depend on them')
parser.add_argument(
'--packages-above-depth', nargs='+',
metavar=('DEPTH', 'PKG_NAME'), action=_DepthAndPackageNames,
help='Only process a subset of packages and packages which '
'recursively depend on them up to a given depth')

parser.add_argument(
'--packages-select-by-dep', nargs='*', metavar='DEP_NAME',
Expand All @@ -50,6 +72,12 @@ def check_parameters(self, args, pkg_names): # noqa: D102
"Package '{name}' specified with --packages-above "
'was not found'
.format_map(locals()))
for name in (args.packages_above_depth or [])[1:]:
if name not in pkg_names:
sys.exit(
"Package '{name}' specified with "
'--packages-above-depth was not found'
.format_map(locals()))

def select_packages(self, args, decorators): # noqa: D102
if args.packages_up_to:
Expand Down Expand Up @@ -77,6 +105,23 @@ def select_packages(self, args, decorators): # noqa: D102
.format_map(locals()))
decorator.selected = False

if args.packages_above_depth and len(args.packages_above_depth) > 1:
depth = args.packages_above_depth[0]
select_pkgs = set(args.packages_above_depth[1:])
for decorator in decorators:
if decorator.descriptor.name in select_pkgs:
continue
if not [
d for d in set(decorator.recursive_dependencies)
if d in select_pkgs and d.metadata['depth'] <= depth
]:
if decorator.selected:
pkg = decorator.descriptor
logger.info(
"Skipping package '{pkg.name}' in '{pkg.path}'"
.format_map(locals()))
decorator.selected = False

if args.packages_select_by_dep:
deps = set(args.packages_select_by_dep)
for decorator in decorators:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ keywords = colcon

[options]
install_requires =
colcon-core
colcon-core>=0.3.19
packages = find:
tests_require =
flake8
Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[colcon-package-selection]
No-Python2:
Depends3: python3-colcon-core
Depends3: python3-colcon-core (>= 0.3.19)
Suite: xenial bionic stretch buster
X-Python3-Version: >= 3.5
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apache
argparse
colcon
deps
descs
Expand Down