pax_global_header00006660000000000000000000000064137371076530014526gustar00rootroot0000000000000052 comment=2521b2a5d3e0a0145f5ddfd21e33cd8bca1e92df colcon-package-selection-0.2.10/000077500000000000000000000000001373710765300164375ustar00rootroot00000000000000colcon-package-selection-0.2.10/.travis.yml000066400000000000000000000007641373710765300205570ustar00rootroot00000000000000language: python python: "3.5" dist: trusty sudo: true install: - pip install -U setuptools # install_requires - pip install -U git+https://github.com/colcon/colcon-core # tests_require - pip install -U flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-quotes pep8-naming pylint pytest pytest-cov scspell3k script: # invoke pytest - pytest --cov=colcon_package_selection --cov-branch notifications: email: false colcon-package-selection-0.2.10/LICENSE000066400000000000000000000261361373710765300174540ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. colcon-package-selection-0.2.10/README.rst000066400000000000000000000002521373710765300201250ustar00rootroot00000000000000colcon-package-selection ======================== An extension for `colcon-core `_ to select a subset of packages for processing. colcon-package-selection-0.2.10/appveyor.yml000066400000000000000000000011421373710765300210250ustar00rootroot00000000000000version: '{build}' environment: matrix: - PYTHON: "C:\\Python36-x64" install: - "%PYTHON%\\python.exe -m pip install -U setuptools" # install_requires - "%PYTHON%\\python.exe -m pip install -U git+https://github.com/colcon/colcon-core" # tests_require - "%PYTHON%\\python.exe -m pip install -U flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-quotes pep8-naming pylint pytest pytest-cov scspell3k" build: off test_script: # invoke pytest - "%PYTHON%\\python.exe -m pytest --cov=colcon_package_selection --cov-branch" colcon-package-selection-0.2.10/colcon_package_selection/000077500000000000000000000000001373710765300234345ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/__init__.py000066400000000000000000000001531373710765300255440ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 __version__ = '0.2.10' colcon-package-selection-0.2.10/colcon_package_selection/argument.py000066400000000000000000000022561373710765300256350ustar00rootroot00000000000000# Copyright 2020 Dirk Thomas # Licensed under the Apache License, Version 2.0 import argparse import re def argument_package_name(value): """ Check if an argument is a valid package name. Used as a ``type`` callback in ``add_argument()`` calls. Package names starting with a dash must be prefixed with a space to avoid collisions with command line arguments. :param str value: The command line argument :returns: The package name :raises argparse.ArgumentTypeError: if the value starts with a dash """ if value.startswith('-'): raise argparse.ArgumentTypeError('unrecognized argument: ' + value) return value.lstrip() def argument_valid_regex(value): """ Check if an argument is a valid regular expression. Used as a ``type`` callback in ``add_argument()`` calls. :param str value: The command line argument :returns: The regular expression object :raises argparse.ArgumentTypeError: if the value is not a valid regex """ try: return re.compile(value) except re.error as e: # noqa: F841 raise argparse.ArgumentTypeError( 'must be a valid regex: {e}'.format_map(locals())) colcon-package-selection-0.2.10/colcon_package_selection/package_discovery/000077500000000000000000000000001373710765300271165ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_discovery/__init__.py000066400000000000000000000000001373710765300312150ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_discovery/ignore.py000066400000000000000000000056071373710765300307630ustar00rootroot00000000000000# Copyright 2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 import re import typing from colcon_core.package_augmentation import PackageAugmentationExtensionPoint from colcon_core.package_discovery import logger from colcon_core.package_discovery import PackageDiscoveryExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_package_selection.argument import argument_package_name from colcon_package_selection.argument import argument_valid_regex class IgnorePackageDiscovery( PackageDiscoveryExtensionPoint, PackageAugmentationExtensionPoint, ): """Ignore discovered packages based on cli arguments.""" def __init__(self): # noqa: D107 super().__init__() satisfies_version( PackageDiscoveryExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') satisfies_version( PackageAugmentationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') self._args = None def add_arguments(self, *, parser, with_default): # noqa: D102 parser.add_argument( '--packages-ignore', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Ignore packages as if they were not discovered') parser.add_argument( '--packages-ignore-regex', nargs='*', metavar='PATTERN', type=argument_valid_regex, help='Ignore packages where any of the patterns match the package ' 'name') def has_parameters(self, *, args): # noqa: D102 self._args = args return False def discover(self, *, args, identification_extensions): # noqa: D102 return set() def augment_packages( self, descs, *, additional_argument_names=None ): # noqa: D102 pkg_names = {d.name for d in descs} # check patterns and remove invalid ones for pattern in (self._args.packages_ignore_regex or []): if not any(re.match(pattern, pkg_name) for pkg_name in pkg_names): if isinstance(pattern, typing.Pattern): pattern = pattern.pattern logger.warning( "the --packages-ignore-regex '{pattern}' doesn't match " 'any of the package names'.format_map(locals())) for pkg_name in (self._args.packages_ignore or []): if pkg_name not in pkg_names: logger.warning( "ignoring unknown package '{pkg_name}' in " '--packages-ignore'.format_map(locals())) # remove the descriptors which should be ignored for desc in set(descs): if desc.name in (self._args.packages_ignore or []): descs.remove(desc) continue for pattern in (self._args.packages_ignore_regex or []): if re.match(pattern, desc.name): descs.remove(desc) break colcon-package-selection-0.2.10/colcon_package_selection/package_selection/000077500000000000000000000000001373710765300270745ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_selection/__init__.py000066400000000000000000000000001373710765300311730ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_selection/dependencies.py000066400000000000000000000244471373710765300321070ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 import argparse import re import sys import typing from colcon_core.package_selection import logger from colcon_core.package_selection import PackageSelectionExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_package_selection.argument import argument_package_name from colcon_package_selection.argument import argument_valid_regex 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') for i in range(1, len(values)): values[i] = argument_package_name(values[i]) setattr(namespace, self.dest, values) class DependenciesPackageSelection(PackageSelectionExtensionPoint): """Select packages based on their dependencies.""" def __init__(self): # noqa: D107 super().__init__() satisfies_version( PackageSelectionExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 parser.add_argument( '--packages-up-to', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Only process a subset of packages and their recursive ' 'dependencies') parser.add_argument( '--packages-up-to-regex', nargs='*', metavar='PATTERN', type=argument_valid_regex, help='Only process a subset of packages and their ' 'recursive dependencies, where any of the ' 'patterns match the package name') parser.add_argument( '--packages-above', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Only process a subset of packages and packages which ' 'recursively depend on them') parser.add_argument( '--packages-above-and-dependencies', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Only process a subset of packages and packages which ' 'recursively depend on them including all their recursive ' 'dependencies') 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='PKG_NAME', type=argument_package_name, help='Only process packages which (recursively) depend on this') parser.add_argument( '--packages-skip-by-dep', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Skip packages which (recursively) depend on this') parser.add_argument( '--packages-skip-up-to', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Skip a subset of packages and their recursive dependencies') def check_parameters(self, args, pkg_names): # noqa: D102 # exit on invalid arguments error_messages = [] for name in args.packages_up_to or set(): if name not in pkg_names: error_messages.append( "Package '{name}' specified with --packages-up-to " 'was not found' .format_map(locals())) for pattern in (args.packages_up_to_regex or []): if not any(re.match(pattern, pkg_name) for pkg_name in pkg_names): if isinstance(pattern, typing.Pattern): pattern = pattern.pattern error_messages.append( "the --packages-up-to-regex '{pattern}' doesn't match " 'any of the package names'.format_map(locals())) for name in args.packages_above or set(): if name not in pkg_names: error_messages.append( "Package '{name}' specified with --packages-above " 'was not found' .format_map(locals())) for name in args.packages_above_and_dependencies or set(): if name not in pkg_names: error_messages.append( "Package '{name}' specified with " '--packages-above-and-dependencies was not found' .format_map(locals())) for name in (args.packages_above_depth or [])[1:]: if name not in pkg_names: error_messages.append( "Package '{name}' specified with " '--packages-above-depth was not found' .format_map(locals())) if error_messages: sys.exit('\n'.join(error_messages)) def select_packages(self, args, decorators): # noqa: D102 if args.packages_up_to: select_pkgs = set(args.packages_up_to) for decorator in reversed(decorators): if decorator.descriptor.name in select_pkgs: select_pkgs |= set(decorator.recursive_dependencies) elif decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False if args.packages_up_to_regex: select_pkgs = set() patterns = args.packages_up_to_regex for decorator in reversed(decorators): pkg = decorator.descriptor if ( pkg.name in select_pkgs or any(re.match(pattern, pkg.name) for pattern in patterns) ): select_pkgs |= set(decorator.recursive_dependencies) elif decorator.selected: logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False if args.packages_above: select_pkgs = set(args.packages_above) for decorator in decorators: if decorator.descriptor.name in select_pkgs: continue if not (select_pkgs & set(decorator.recursive_dependencies)): if decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False if args.packages_above_and_dependencies: # collect all above packages select_pkgs = set(args.packages_above_and_dependencies) for decorator in decorators: if decorator.descriptor.name in select_pkgs: continue if set(decorator.recursive_dependencies) & select_pkgs: select_pkgs.add(decorator.descriptor.name) for decorator in reversed(decorators): if decorator.descriptor.name in select_pkgs: select_pkgs |= set(decorator.recursive_dependencies) elif decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .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: if not (deps & set(decorator.recursive_dependencies)): if decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False if args.packages_skip_by_dep: deps = set(args.packages_skip_by_dep) for decorator in decorators: if deps & set(decorator.recursive_dependencies): if decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False if args.packages_skip_up_to: skip_pkgs = set(args.packages_skip_up_to) for decorator in reversed(decorators): if decorator.descriptor.name in skip_pkgs: skip_pkgs |= set(decorator.recursive_dependencies) if decorator.selected: pkg = decorator.descriptor logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False colcon-package-selection-0.2.10/colcon_package_selection/package_selection/previous/000077500000000000000000000000001373710765300307505ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_selection/previous/__init__.py000066400000000000000000000023461373710765300330660ustar00rootroot00000000000000# Copyright 2019 Dirk Thomas # Licensed under the Apache License, Version 2.0 import pathlib RESULT_FILENAME = 'colcon_{verb_name}.rc' TEST_FAILURE_RESULT = 'test failures' def get_previous_result(package_build_base, verb_name): """ Get the result of a verb from the package build directory. :param str package_build_base: The build directory of a package :param str verb_name: The invoked verb name :returns: The previously persisted result, otherwise None :rtype: str """ path = _get_result_path(package_build_base, verb_name) if not path.exists(): return None return path.read_text().rstrip() def set_result(package_build_base, verb_name, result): """ Persist the result of a verb in the package build directory. :param str package_build_base: The build directory of a package :param str verb_name: The invoked verb name :param str result: The result of the invocation """ path = _get_result_path(package_build_base, verb_name) path.parent.mkdir(parents=True, exist_ok=True) path.write_text(str(result) + '\n') def _get_result_path(package_build_base, verb_name): return pathlib.Path( package_build_base) / RESULT_FILENAME.format_map(locals()) colcon-package-selection-0.2.10/colcon_package_selection/package_selection/previous/event_handler.py000066400000000000000000000034141373710765300341420ustar00rootroot00000000000000# Copyright 2019 Dirk Thomas # Licensed under the Apache License, Version 2.0 from colcon_core.event.job import JobEnded from colcon_core.event.test import TestFailure from colcon_core.event_handler import EventHandlerExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_core.verb.build import BuildPackageArguments from colcon_core.verb.test import TestPackageArguments from colcon_package_selection.package_selection.previous \ import set_result from colcon_package_selection.package_selection.previous \ import TEST_FAILURE_RESULT class StoreResultEventHandler(EventHandlerExtensionPoint): """ Persist the result of a job in a file in its build directory. The extension handles events of the following types: - :py:class:`colcon_core.event.job.JobEnded` - :py:class:`colcon_core.event.test.TestFailure` """ def __init__(self): # noqa: D107 super().__init__() satisfies_version( EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') self._test_failures = set() def __call__(self, event): # noqa: D102 data = event[0] if isinstance(data, TestFailure): job = event[1] self._test_failures.add(job) elif isinstance(data, JobEnded): job = event[1] if isinstance(job.task_context.args, BuildPackageArguments): verb_name = 'build' elif isinstance(job.task_context.args, TestPackageArguments): verb_name = 'test' else: return if job in self._test_failures: result = TEST_FAILURE_RESULT else: result = data.rc set_result(job.task_context.args.build_base, verb_name, result) package_selection.py000066400000000000000000000125741373710765300347140ustar00rootroot00000000000000colcon-package-selection-0.2.10/colcon_package_selection/package_selection/previous# Copyright 2019 Dirk Thomas # Licensed under the Apache License, Version 2.0 import os from colcon_core.package_selection import logger from colcon_core.package_selection import PackageSelectionExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_core.subprocess import SIGINT_RESULT from colcon_package_selection.package_selection.previous \ import get_previous_result class PreviousPackageSelectionExtension(PackageSelectionExtensionPoint): """Skip a set of packages based on results of previous invocations.""" def __init__(self): # noqa: D107 super().__init__() satisfies_version( PackageSelectionExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 group = parser.add_mutually_exclusive_group() group.add_argument( '--packages-select-build-failed', action='store_true', help='Only process a subset of packages which have failed to ' 'build previously (aborted packages are not ' 'considered errors)') group.add_argument( '--packages-skip-build-finished', action='store_true', help='Skip a set of packages which have finished to build ' 'previously') group.add_argument( '--packages-select-test-failures', action='store_true', help='Only process a subset of packages which had test failures ' 'previously') group.add_argument( '--packages-skip-test-passed', action='store_true', help='Skip a set of packages which had no test failures ' 'previously') def select_packages(self, args, decorators): # noqa: D102 if not any(( args.packages_select_build_failed, args.packages_skip_build_finished, args.packages_select_test_failures, args.packages_skip_test_passed, )): return if not hasattr(args, 'build_base'): if args.packages_select_build_failed: argument = '--packages-select-build-failed' elif args.packages_skip_build_finished: argument = '--packages-skip-build-finished' elif args.packages_select_test_failures: argument = '--packages-select-test-failures' elif args.packages_skip_test_passed: argument = '--packages-skip-test-passed' else: assert False logger.warning( "Ignoring '{argument}' since the invoked verb doesn't have a " "'--build-base' argument and therefore can't access " 'information about the previous state of a package' .format_map(locals())) return for decorator in decorators: # skip packages which have already been ruled out if not decorator.selected: continue pkg = decorator.descriptor if ( args.packages_select_build_failed or args.packages_skip_build_finished ): verb_name = 'build' elif ( args.packages_select_test_failures or args.packages_skip_test_passed ): verb_name = 'test' else: assert False previous_result = get_previous_result( os.path.join(args.build_base, pkg.name), verb_name) if args.packages_select_build_failed: package_kind = None if previous_result is None: package_kind = 'not previously built' elif previous_result == SIGINT_RESULT: package_kind = 'previously aborted' elif previous_result == '0': package_kind = 'previously built' if package_kind is not None: logger.info( "Skipping {package_kind} package '{pkg.name}' in " "'{pkg.path}'".format_map(locals())) decorator.selected = False if args.packages_skip_build_finished: if previous_result == '0': logger.info( "Skipping previously built package '{pkg.name}' in " "'{pkg.path}'".format_map(locals())) decorator.selected = False if args.packages_select_test_failures: package_kind = None if previous_result is None: package_kind = 'not previously tested' elif previous_result == SIGINT_RESULT: package_kind = 'previously aborted' elif previous_result == '0': package_kind = 'previously tested' if package_kind is not None: logger.info( "Skipping {package_kind} package '{pkg.name}' in " "'{pkg.path}'".format_map(locals())) decorator.selected = False if args.packages_skip_test_passed: if previous_result == '0': logger.info( "Skipping previously tested package '{pkg.name}' in " "'{pkg.path}'".format_map(locals())) decorator.selected = False colcon-package-selection-0.2.10/colcon_package_selection/package_selection/select_skip.py000066400000000000000000000105241373710765300317550ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 import re import typing from colcon_core.package_selection import logger from colcon_core.package_selection import PackageSelectionExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_package_selection.argument import argument_package_name from colcon_package_selection.argument import argument_valid_regex class SelectSkipPackageSelectionExtension(PackageSelectionExtensionPoint): """Select a set of packages based on select / skip criteria.""" def __init__(self): # noqa: D107 super().__init__() satisfies_version( PackageSelectionExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 parser.add_argument( '--packages-select', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Only process a subset of packages') parser.add_argument( '--packages-skip', nargs='*', metavar='PKG_NAME', type=argument_package_name, help='Skip a set of packages') parser.add_argument( '--packages-select-regex', nargs='*', metavar='PATTERN', type=argument_valid_regex, help='Only process a subset of packages where any of the patterns ' 'match the package name') parser.add_argument( '--packages-skip-regex', nargs='*', metavar='PATTERN', type=argument_valid_regex, help='Skip a set of packages where any of the patterns match the ' 'package name') def check_parameters(self, args, pkg_names): # noqa: D102 # warn about ignored arguments for pkg_name in args.packages_select or []: if pkg_name not in pkg_names: logger.warning( "ignoring unknown package '{pkg_name}' in " '--packages-select'.format_map(locals())) for pkg_name in args.packages_skip or []: if pkg_name not in pkg_names: logger.warning( "ignoring unknown package '{pkg_name}' in " '--packages-skip'.format_map(locals())) for pattern in (args.packages_select_regex or []): if not any(re.match(pattern, pkg_name) for pkg_name in pkg_names): if isinstance(pattern, typing.Pattern): pattern = pattern.pattern logger.warning( "the --packages-select-regex '{pattern}' doesn't match " 'any of the package names'.format_map(locals())) for pattern in (args.packages_skip_regex or []): if not any(re.match(pattern, pkg_name) for pkg_name in pkg_names): if isinstance(pattern, typing.Pattern): pattern = pattern.pattern logger.warning( "the --packages-skip-regex '{pattern}' doesn't match any " 'of the package names'.format_map(locals())) def select_packages(self, args, decorators): # noqa: D102 for decorator in decorators: # skip packages which have already been ruled out if not decorator.selected: continue pkg = decorator.descriptor if ( pkg.name in (args.packages_skip or []) or any( re.match(pattern, pkg.name) for pattern in (args.packages_skip_regex or []) ) ): logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False elif ( args.packages_select is not None or args.packages_select_regex is not None ): if ( pkg.name not in (args.packages_select or []) and not any( re.match(pattern, pkg.name) for pattern in (args.packages_select_regex or []) ) ): logger.info( "Skipping not selected package '{pkg.name}' in " "'{pkg.path}'".format_map(locals())) decorator.selected = False colcon-package-selection-0.2.10/colcon_package_selection/package_selection/start_end.py000066400000000000000000000053641373710765300314410ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 import sys from colcon_core.package_selection import logger from colcon_core.package_selection import PackageSelectionExtensionPoint from colcon_core.plugin_system import satisfies_version from colcon_package_selection.argument import argument_package_name class StartEndPackageSelection(PackageSelectionExtensionPoint): """Select a range of packages based on flattened topological ordering.""" def __init__(self): # noqa: D107 super().__init__() satisfies_version( PackageSelectionExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 parser.add_argument( '--packages-start', metavar='PKG_NAME', type=argument_package_name, help='Skip packages before this in flat topological ordering') parser.add_argument( '--packages-end', metavar='PKG_NAME', type=argument_package_name, help='Skip packages after this in flat topological ordering') def check_parameters(self, args, pkg_names): # noqa: D102 # exit on invalid arguments if args.packages_start and args.packages_start not in pkg_names: sys.exit( "Package '{args.packages_start}' specified with " '--packages-start was not found' .format_map(locals())) if args.packages_end and args.packages_end not in pkg_names: sys.exit( "Package '{args.packages_end}' specified with --packages-end " 'was not found' .format_map(locals())) def select_packages(self, args, decorators): # noqa: D102 pkg_within_range = not args.packages_start for decorator in decorators: pkg = decorator.descriptor # identify start of range if pkg.name == args.packages_start: pkg_within_range = True selected = pkg_within_range if decorator.selected and not selected: # mark packages outside of the range as not selected logger.info( "Skipping package '{pkg.name}' in '{pkg.path}'" .format_map(locals())) decorator.selected = False # identify end of range if pkg.name == args.packages_end: if not pkg_within_range: sys.exit( "The --packages-end package '{args.packages_end}' " 'occurs topologically before the --packages-start ' "package '{args.packages_start}'" .format_map(locals())) pkg_within_range = False colcon-package-selection-0.2.10/publish-python.yaml000066400000000000000000000005211373710765300223060ustar00rootroot00000000000000artifacts: - type: wheel uploads: - type: pypi - type: stdeb uploads: - type: packagecloud config: repository: dirk-thomas/colcon distributions: - ubuntu:xenial - ubuntu:bionic - ubuntu:focal - debian:stretch - debian:buster colcon-package-selection-0.2.10/setup.cfg000066400000000000000000000043711373710765300202650ustar00rootroot00000000000000[metadata] name = colcon-package-selection version = attr: colcon_package_selection.__version__ url = https://colcon.readthedocs.io project_urls = Changelog = https://github.com/colcon/colcon-package-selection/milestones?direction=desc&sort=due_date&state=closed GitHub = https://github.com/colcon/colcon-package-selection/ author = Dirk Thomas author_email = web@dirk-thomas.net maintainer = Dirk Thomas maintainer_email = web@dirk-thomas.net classifiers = Development Status :: 3 - Alpha Environment :: Plugins Intended Audience :: Developers License :: OSI Approved :: Apache Software License Operating System :: MacOS Operating System :: Microsoft :: Windows Operating System :: POSIX Programming Language :: Python Topic :: Software Development :: Build Tools license = Apache License, Version 2.0 description = Extension for colcon to select the packages to process. long_description = file: README.rst keywords = colcon [options] install_requires = colcon-core>=0.3.19 packages = find: tests_require = flake8>=3.6.0 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes pep8-naming pylint pytest pytest-cov scspell3k>=2.2 zip_safe = true [tool:pytest] filterwarnings = error junit_suite_name = colcon-package-selection [options.entry_points] colcon_core.event_handler = store_result = colcon_package_selection.package_selection.previous.event_handler:StoreResultEventHandler colcon_core.package_augmentation = ignore = colcon_package_selection.package_discovery.ignore:IgnorePackageDiscovery colcon_core.package_discovery = ignore = colcon_package_selection.package_discovery.ignore:IgnorePackageDiscovery colcon_core.package_selection = dependencies = colcon_package_selection.package_selection.dependencies:DependenciesPackageSelection previous = colcon_package_selection.package_selection.previous.package_selection:PreviousPackageSelectionExtension select_skip = colcon_package_selection.package_selection.select_skip:SelectSkipPackageSelectionExtension start_end = colcon_package_selection.package_selection.start_end:StartEndPackageSelection [flake8] import-order-style = google colcon-package-selection-0.2.10/setup.py000066400000000000000000000001721373710765300201510ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 from setuptools import setup setup() colcon-package-selection-0.2.10/stdeb.cfg000066400000000000000000000002251373710765300202200ustar00rootroot00000000000000[colcon-package-selection] No-Python2: Depends3: python3-colcon-core (>= 0.3.19) Suite: xenial bionic focal stretch buster X-Python3-Version: >= 3.5 colcon-package-selection-0.2.10/test/000077500000000000000000000000001373710765300174165ustar00rootroot00000000000000colcon-package-selection-0.2.10/test/spell_check.words000066400000000000000000000002051373710765300227470ustar00rootroot00000000000000apache argparse colcon deps descs iterdir lstrip nargs noqa pathlib pkgs plugin pytest rstrip rtype scspell setuptools sigint thomas colcon-package-selection-0.2.10/test/test_copyright_license.py000066400000000000000000000024271373710765300245460ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 from pathlib import Path import sys def test_copyright_license(): missing = check_files([Path(__file__).parents[1]]) assert not len(missing), \ 'In some files no copyright / license line was found' def check_files(paths): missing = [] for path in paths: if path.is_dir(): for p in sorted(path.iterdir()): if p.name.startswith('.'): continue if p.name.endswith('.py') or p.is_dir(): missing += check_files([p]) if path.is_file(): content = path.read_text() if not content: continue lines = content.splitlines() has_copyright = \ any(line for line in lines if line.startswith('# Copyright')) has_license = \ '# Licensed under the Apache License, Version 2.0' in lines if not has_copyright or not has_license: print( 'Could not find copyright / license in:', path, file=sys.stderr) missing .append(path) else: print('Found copyright / license in:', path) return missing colcon-package-selection-0.2.10/test/test_flake8.py000066400000000000000000000030131373710765300221760ustar00rootroot00000000000000# Copyright 2016-2018 Dirk Thomas # Licensed under the Apache License, Version 2.0 import logging from pathlib import Path import sys from flake8 import LOG from flake8.api.legacy import get_style_guide # avoid debug and info messages from flake8 internals LOG.setLevel(logging.WARN) def test_flake8(): style_guide = get_style_guide( extend_ignore=['D100', 'D104'], show_source=True, ) style_guide_tests = get_style_guide( extend_ignore=['D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'], show_source=True, ) stdout = sys.stdout sys.stdout = sys.stderr # implicitly calls report_errors() report = style_guide.check_files([ str(Path(__file__).parents[1] / 'colcon_package_selection'), ]) report_tests = style_guide_tests.check_files([ str(Path(__file__).parents[1] / 'test'), ]) sys.stdout = stdout total_errors = report.total_errors + report_tests.total_errors if total_errors: # pragma: no cover # output summary with per-category counts print() if report.total_errors: report._application.formatter.show_statistics(report._stats) if report_tests.total_errors: report_tests._application.formatter.show_statistics( report_tests._stats) print( 'flake8 reported {total_errors} errors' .format_map(locals()), file=sys.stderr) assert not total_errors, \ 'flake8 reported {total_errors} errors'.format_map(locals()) colcon-package-selection-0.2.10/test/test_spell_check.py000066400000000000000000000035661373710765300233150ustar00rootroot00000000000000# Copyright 2016-2019 Dirk Thomas # Licensed under the Apache License, Version 2.0 from pathlib import Path import pytest from scspell import Report from scspell import SCSPELL_BUILTIN_DICT from scspell import spell_check spell_check_words_path = Path(__file__).parent / 'spell_check.words' @pytest.fixture(scope='module') def known_words(): global spell_check_words_path return spell_check_words_path.read_text().splitlines() def test_spell_check(known_words): source_filenames = [Path(__file__).parents[1] / 'setup.py'] + \ list( (Path(__file__).parents[1] / 'colcon_package_selection') .glob('**/*.py')) + \ list((Path(__file__).parents[1] / 'test').glob('**/*.py')) for source_filename in sorted(source_filenames): print('Spell checking:', source_filename) # check all files report = Report(known_words) spell_check( [str(p) for p in source_filenames], base_dicts=[SCSPELL_BUILTIN_DICT], report_only=report, additional_extensions=[('', 'Python')]) unknown_word_count = len(report.unknown_words) assert unknown_word_count == 0, \ 'Found {unknown_word_count} unknown words: '.format_map(locals()) + \ ', '.join(sorted(report.unknown_words)) unused_known_words = set(known_words) - report.found_known_words unused_known_word_count = len(unused_known_words) assert unused_known_word_count == 0, \ '{unused_known_word_count} words in the word list are not used: ' \ .format_map(locals()) + ', '.join(sorted(unused_known_words)) def test_spell_check_word_list_order(known_words): assert known_words == sorted(known_words), \ 'The word list should be ordered alphabetically' def test_spell_check_word_list_duplicates(known_words): assert len(known_words) == len(set(known_words)), \ 'The word list should not contain duplicates'