def __init__(self): # noqa: D107 super().__init__() satisfies_version( DesktopNotificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') if platform.system() != 'Linux': raise SkipExtensionException('Not used on non-Linux systems') if not which('notify-send'): raise SkipExtensionException("Could not find 'notify-send'")
async def generate_command_environment( self, task_name, build_base, dependencies, ): # noqa: D102 if sys.platform == 'win32': raise SkipExtensionException('Not usable on Windows systems') # check if all dependencies are available # removes dependencies available in the environment from the parameter check_dependency_availability( dependencies, script_filename='package.sh') hook_path = build_base / ('colcon_command_prefix_%s.sh' % task_name) expand_template( Path(__file__).parent / 'template' / 'command_prefix.sh.em', hook_path, {'dependencies': dependencies}) cmd = ['.', str(hook_path), '&&', 'env'] env = await get_environment_variables(cmd, cwd=str(build_base)) # write environment variables to file for debugging env_path = build_base / ('colcon_command_prefix_%s.sh.env' % task_name) with env_path.open('w') as h: for key in sorted(env.keys()): value = env[key] h.write('{key}={value}\n'.format_map(locals())) return env
def __init__(self): # noqa: D107 super().__init__() satisfies_version( DesktopNotificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') if platform.system() != 'Darwin': raise SkipExtensionException('Not used on non-Darwin systems')
def identify(self, metadata): if metadata.type is not None and metadata.type != self.name: return # skip package if it contains a CMakeLists.txt file cmake_txt = metadata.path / "CMakeLists.txt" if cmake_txt.is_file(): return # for it to be an ROS 2 rust package, there needs to be both a Cargo.toml and a # package.xml file cargo_toml = metadata.path / "Cargo.toml" if not cargo_toml.is_file(): return package_xml = metadata.path / "package.xml" if not package_xml.is_file(): return data = extract_data(cargo_toml) if not data: raise SkipExtensionException( 'Failed to extract Rust package information from "%s"' % cargo_toml.absolute()) metadata.type = "cargo_ros" if metadata.name is None: metadata.name = data["name"] metadata.dependencies["build"] |= data["depends"] metadata.dependencies["run"] |= data["depends"]
def __init__(self): # noqa: D107 super().__init__() satisfies_version( PythonTestingStepExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') entry_points = iter_entry_points('distutils.commands', name='pytest') if not list(entry_points): raise SkipExtensionException("'pytest-runner' not found")
def __init__(self): # noqa: D107 super().__init__() satisfies_version( PythonTestingStepExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') try: import pytest # noqa: F401 except ImportError: raise SkipExtensionException("'pytest' not found")
def __init__(self): # noqa: D107 super().__init__() satisfies_version( DesktopNotificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') if sys.platform != 'win32': raise SkipExtensionException('Not used on non-Windows systems') self._initialized = False self._last_notification = None
def __init__(self): # noqa: D107 super().__init__() satisfies_version( DesktopNotificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') try: import notify2 # noqa: F401 except ImportError: raise SkipExtensionException("'notify2' not found") self._initialized = False self._last_notification = None
def __init__(self): # noqa: D107 satisfies_version( PackageIdentificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') satisfies_version( PackageAugmentationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') # check if the necessary dependency to parse the manifest is available try: import catkin_pkg # noqa: F401 except ImportError: raise SkipExtensionException( "The Python module 'catkin_pkg' could not be imported, " 'therefore ROS packages can not be identified')
def test_get_command_environment(): with EntryPointContext(extension1=Extension1, extension2=Extension2): extensions = get_shell_extensions() # one not implemented, one skipped extension extensions[90]['extension1'].generate_command_environment = Mock( side_effect=SkipExtensionException()) coroutine = get_command_environment(None, '/build/base', None) with patch('colcon_core.shell.logger.debug') as debug: with patch('colcon_core.shell.logger.info') as info: with pytest.raises(RuntimeError) as e: run_until_complete(coroutine) assert 'Could not find a shell extension for the command environment' \ in str(e.value) assert extensions[90]['extension1'].generate_command_environment \ .call_count == 1 # the raised exceptions are catched and result in a debug/info message assert debug.call_count == 1 assert len(debug.call_args[0]) == 1 assert debug.call_args[0][0] == \ "Skip shell extension 'extension2' for command environment" assert info.call_count == 1 assert len(info.call_args[0]) == 1 assert info.call_args[0][0].startswith( "Skip shell extension 'extension1' for command environment: ") # raise runtime error extensions[100]['extension2'].generate_command_environment = Mock( side_effect=RuntimeError('custom exception')) extensions[90]['extension1'].generate_command_environment.reset_mock() coroutine = get_command_environment(None, '/build/base', None) with pytest.raises(RuntimeError) as e: run_until_complete(coroutine) assert str(e.value) == 'custom exception' assert extensions[90]['extension1'].generate_command_environment \ .call_count == 0 # one exception, one successful extensions[100]['extension2'].generate_command_environment = Mock( side_effect=Exception('custom exception')) extensions[90]['extension1'].generate_command_environment = Mock( side_effect=generate_command_environment) coroutine = get_command_environment(None, '/build/base', None) with patch('colcon_core.shell.logger.error') as error: env = run_until_complete(coroutine) assert env == {'key': 'value'} # 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 shell extension 'extension2': custom exception\n")
async def generate_command_environment( self, task_name, build_base, dependencies, ): # noqa: D102 global powershell_executable_name if not self._is_primary: raise SkipExtensionException('Not usable outside of PowerShell') # check if all dependencies are available # removes dependencies available in the environment from the parameter check_dependency_availability( dependencies, script_filename='package.ps1') hook_path = build_base / ('colcon_command_prefix_%s.ps1' % task_name) expand_template( Path(__file__).parent / 'template' / 'command_prefix.ps1.em', hook_path, {'dependencies': dependencies}) cmd = [ '.', str(hook_path), ';', '(Get-Item Env:).GetEnumerator()', '|', 'ForEach-Object', '{ "$($_.Key)=$($_.Value)" }' ] if POWERSHELL_EXECUTABLE is None: raise RuntimeError( "Could not find '{powershell_executable_name}' executable" .format(powershell_executable_name=powershell_executable_name)) cmd = [POWERSHELL_EXECUTABLE, '-Command', ' '.join(cmd)] env = await get_environment_variables( cmd, cwd=str(build_base), shell=False) # write environment variables to file for debugging env_path = build_base / \ ('colcon_command_prefix_%s.ps1.env' % task_name) with env_path.open('w') as h: for key in sorted(env.keys()): value = env[key] h.write('{key}={value}\n'.format_map(locals())) return env
async def generate_command_environment( self, task_name, build_base, dependencies, ): # noqa: D102 if sys.platform != 'win32': raise SkipExtensionException('Not usable on non-Windows systems') hook_path = build_base / ('colcon_command_prefix_%s.bat' % task_name) expand_template( Path(__file__).parent / 'template' / 'command_prefix.bat.em', hook_path, {'dependencies': dependencies}) # ensure that the referenced scripts exist missing = OrderedDict() for pkg_name, pkg_install_base in dependencies.items(): pkg_script = Path( pkg_install_base) / 'share' / pkg_name / 'package.bat' if not pkg_script.exists(): missing[pkg_name] = str(pkg_script) if missing: raise RuntimeError( 'Failed to find the following files:' + ''.join('\n- %s' % path for path in missing.values()) + '\nCheck that the following packages have been built:' + ''.join('\n- %s' % name for name in missing.keys())) cmd = [str(hook_path), '&&', 'set'] env = await get_environment_variables(cmd, cwd=str(build_base)) # write environment variables to file for debugging env_path = build_base / ('colcon_command_prefix_%s.bat.env' % task_name) with env_path.open('w') as h: for key in sorted(env.keys()): value = env[key] h.write('{key}={value}\n'.format_map(locals())) return env
def __init__(self): # noqa: D107 super().__init__() satisfies_version(ShellExtensionPoint.EXTENSION_POINT_VERSION, '^2.0') if sys.platform == 'win32' and not use_all_shell_extensions: raise SkipExtensionException('Not used on Windows systems')
def __init__(self): raise SkipExtensionException( 'extension raising skip extension exception')