def get_package_descriptors(args, *, additional_argument_names=None): """ Get the package descriptors. The overview of the process: * Discover the package descriptors using the package discovery and identification extensions * Check is the passed package selection arguments have valid values * Augment the package descriptors :param additional_argument_names: A list of additional arguments to consider :returns: set of :py:class:`colcon_core.package_descriptor.PackageDescriptor` :rtype: set """ extensions = get_package_identification_extensions() descriptors = discover_packages(args, extensions) pkg_names = {d.name for d in descriptors} _check_package_selection_parameters(args, pkg_names) augment_packages(descriptors, additional_argument_names=additional_argument_names) return descriptors
def test_augment_packages(): desc1 = PackageDescriptor('/some/path') desc2 = PackageDescriptor('/other/path') descs = {desc1, desc2} with EntryPointContext(extension1=Extension1, extension2=Extension2): extensions = get_package_augmentation_extensions() extensions['extension1'].augment_package = Mock( side_effect=augment_package_metadata_with_data) extensions['extension2'].augment_package = Mock( side_effect=augment_package_metadata_with_path) augment_packages(descs) assert len(desc1.metadata) == 2 assert set(desc1.metadata.keys()) == {'key', 'path'} assert desc1.path == desc1.metadata['path'] assert len(desc2.metadata) == 1 assert set(desc2.metadata.keys()) == {'path'} assert desc2.path == desc2.metadata['path'] # raise exception desc1 = PackageDescriptor('/some/path') desc2 = PackageDescriptor('/other/path') descs = {desc1, desc2} with EntryPointContext(extension1=Extension1, extension2=Extension2): extensions = get_package_augmentation_extensions() extensions['extension1'].augment_package = Mock( side_effect=augment_package_with_hook) with patch('colcon_core.package_augmentation.logger.error') as error: augment_packages( descs, additional_argument_names=['arg1', 'arg2'], augmentation_extensions=extensions) assert desc1.hooks == ['arg1', 'arg2'] assert desc2.hooks == ['arg1', 'arg2'] # the raised exception is catched and results in an error message assert error.call_count == 1 assert len(error.call_args[0]) == 1 assert error.call_args[0][0].startswith( "Exception in package augmentation extension 'extension2': \n") # invalid return value desc1.hooks = [] desc2.hooks = [] extensions['extension2'].augment_packages = Mock(return_value=False) with patch('colcon_core.package_augmentation.logger.error') as error: augment_packages( descs, additional_argument_names=['arg1', 'arg2'], augmentation_extensions=extensions) assert desc1.hooks == ['arg1', 'arg2'] assert desc2.hooks == ['arg1', 'arg2'] # the raised assertion is catched and results in an error message assert error.call_count == 1 assert len(error.call_args[0]) == 1 assert error.call_args[0][0].startswith( "Exception in package augmentation extension 'extension2': ")