def test_format_output_in_columns_default(self): """Format output on 2 lines, with default max-width and space sep""" expected = [ "ant catkin copy jdk kernel maven " "nodejs python3 tar-content", "autotools cmake go kbuild make nil " "python2 scons ", ] self.assertEquals(expected, common.format_output_in_columns(self.elements_list))
def test_format_output_in_columns_narrow(self): """Format output on 3 lines, with narrow max-width and space sep""" expected = ['ant cmake jdk make nodejs scons ', 'autotools copy kbuild maven python2 tar-content', 'catkin go kernel nil python3'] self.assertEquals(expected, common.format_output_in_columns(self.elements_list, max_width=60))
def test_format_output_in_columns_large(self): """Format output on one big line, with default space sep""" expected = ['ant autotools catkin cmake copy go jdk kbuild ' 'kernel make maven nil nodejs python2 python3 ' 'scons tar-content'] self.assertEquals(expected, common.format_output_in_columns(self.elements_list, max_width=990))
def test_format_output_in_columns_one_space(self): """Format output with one space sep""" expected = [ "ant cmake jdk make nodejs scons ", "autotools copy kbuild maven python2 tar-content", "catkin go kernel nil python3", ] self.assertEquals(expected, common.format_output_in_columns(self.elements_list, max_width=60, num_col_spaces=1))
def test_format_output_in_columns_default(self): """Format output on 2 lines, with default max-width and space sep""" expected = ['ant catkin copy jdk kernel maven ' 'nodejs python3 tar-content', 'autotools cmake go kbuild make nil ' 'python2 scons '] self.assertThat( common.format_output_in_columns(self.elements_list), Equals(expected))
def _list_plugins(): plugins = [] for importer, modname, is_package in pkgutil.iter_modules( snapcraft.plugins.__path__): plugins.append(modname.replace('_', '-')) # we wrap the output depending on terminal size width = get_terminal_width() for line in format_output_in_columns(plugins, max_width=width): print(line)
def test_format_output_in_columns_one_space(self): """Format output with one space sep""" expected = ['ant cmake jdk make nodejs scons ', 'autotools copy kbuild maven python2 tar-content', 'catkin go kernel nil python3'] self.assertThat( common.format_output_in_columns(self.elements_list, max_width=60, num_col_spaces=1), Equals(expected))
def list_plugins(): """List the available plugins that handle different types of part. This command has an alias of `plugins`. """ plugins = [] for _, modname, _ in pkgutil.iter_modules( snapcraft.plugins.__path__): # Only add non-private modules/packages to the plugin list if not modname.startswith('_'): plugins.append(modname.replace('_', '-')) # we wrap the output depending on terminal size width = get_terminal_width() for line in format_output_in_columns(plugins, max_width=width): click.echo(line)
def _list_plugins(): plugins = [] for importer, modname, is_package in pkgutil.iter_modules( snapcraft.plugins.__path__): plugins.append(modname.replace('_', '-')) # we wrap the output depending on terminal size width = MAX_CHARACTERS_WRAP with suppress(OSError): with suppress(subprocess.CalledProcessError): # this is the only way to get current terminal size reliably # without duplicating a bunch of logic command = ['tput', 'cols'] candidate_width = \ subprocess.check_output(command, stderr=subprocess.DEVNULL) width = min(int(candidate_width), width) for line in format_output_in_columns(plugins, max_width=width): print(line)