def test_iteration(self): self.maxDiff = None class Subsys1(Subsystem): options_scope = 'subsys1' class Subsys2(Subsystem): options_scope = 'subsys2' @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, 'subsys2'), ) class Goal1Task2(Task): options_scope = 'goal1.task12' @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, 'goal1.task12'), ) infos = [ ScopeInfo(GLOBAL_SCOPE, ScopeInfo.GLOBAL, GlobalOptionsRegistrar), ScopeInfo('subsys2', ScopeInfo.SUBSYSTEM, Subsys2), ScopeInfo('subsys1.subsys2', ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo('goal1', ScopeInfo.INTERMEDIATE), ScopeInfo('goal1.task11', ScopeInfo.TASK), ScopeInfo('goal1.task12', ScopeInfo.TASK, Goal1Task2), ScopeInfo('subsys1.goal1.task12', ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo('goal2', ScopeInfo.INTERMEDIATE), ScopeInfo('goal2.task21', ScopeInfo.TASK), ScopeInfo('goal2.task22', ScopeInfo.TASK), ScopeInfo('goal3', ScopeInfo.INTERMEDIATE), ScopeInfo('goal3.task31', ScopeInfo.TASK), ScopeInfo('goal3.task32', ScopeInfo.TASK), ] scope_to_infos = dict((x.scope, x) for x in infos) it = ScopeInfoIterator(scope_to_infos) actual = list( it.iterate([GLOBAL_SCOPE, 'goal1', 'goal2.task21', 'goal3'])) expected_scopes = [ GLOBAL_SCOPE, 'subsys2', 'subsys1.subsys2', 'goal1', 'goal1.task11', 'goal1.task12', 'subsys1.goal1.task12', 'goal2.task21', 'goal3', 'goal3.task31', 'goal3.task32', ] expected_scope_infos = [scope_to_infos[x] for x in expected_scopes] self.assertEquals(expected_scope_infos, actual)
def test_iteration(self): self.maxDiff = None class Subsys1(Subsystem): options_scope = "subsys1" class Subsys2(Subsystem): options_scope = "subsys2" @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, "subsys2"), ) class Goal1Task2(Task): options_scope = "goal1.task12" @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, "goal1.task12"), ) infos = [ ScopeInfo(GLOBAL_SCOPE, ScopeInfo.GLOBAL, GlobalOptions), ScopeInfo("subsys2", ScopeInfo.SUBSYSTEM, Subsys2), ScopeInfo("subsys1.subsys2", ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo("goal1", ScopeInfo.INTERMEDIATE), ScopeInfo("goal1.task11", ScopeInfo.TASK), ScopeInfo("goal1.task12", ScopeInfo.TASK, Goal1Task2), ScopeInfo("subsys1.goal1.task12", ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo("goal2", ScopeInfo.INTERMEDIATE), ScopeInfo("goal2.task21", ScopeInfo.TASK), ScopeInfo("goal2.task22", ScopeInfo.TASK), ScopeInfo("goal3", ScopeInfo.INTERMEDIATE), ScopeInfo("goal3.task31", ScopeInfo.TASK), ScopeInfo("goal3.task32", ScopeInfo.TASK), ] scope_to_infos = dict((x.scope, x) for x in infos) it = ScopeInfoIterator(scope_to_infos) actual = list( it.iterate({GLOBAL_SCOPE, "goal1", "goal2.task21", "goal3"})) expected_scopes = [ GLOBAL_SCOPE, "subsys2", "subsys1.subsys2", "goal1", "goal1.task11", "goal1.task12", "subsys1.goal1.task12", "goal2.task21", "goal3", "goal3.task31", "goal3.task32", ] expected_scope_infos = [scope_to_infos[x] for x in expected_scopes] self.assertEqual(expected_scope_infos, actual)
def test_iteration(self): self.maxDiff = None class Subsys1(Subsystem): options_scope = 'subsys1' class Subsys2(Subsystem): options_scope = 'subsys2' @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, 'subsys2'),) class Goal1Task2(Task): options_scope = 'goal1.task12' @classmethod def subsystem_dependencies(cls): return (SubsystemDependency(Subsys1, 'goal1.task12'),) # Ignore default Task subsystem dependencies. @classmethod def task_subsystems(cls): return tuple() infos = [ ScopeInfo(GLOBAL_SCOPE, ScopeInfo.GLOBAL, GlobalOptionsRegistrar), ScopeInfo('subsys2', ScopeInfo.SUBSYSTEM, Subsys2), ScopeInfo('subsys1.subsys2', ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo('goal1', ScopeInfo.INTERMEDIATE), ScopeInfo('goal1.task11', ScopeInfo.TASK), ScopeInfo('goal1.task12', ScopeInfo.TASK, Goal1Task2), ScopeInfo('subsys1.goal1.task12', ScopeInfo.SUBSYSTEM, Subsys1), ScopeInfo('goal2', ScopeInfo.INTERMEDIATE), ScopeInfo('goal2.task21', ScopeInfo.TASK), ScopeInfo('goal2.task22', ScopeInfo.TASK), ScopeInfo('goal3', ScopeInfo.INTERMEDIATE), ScopeInfo('goal3.task31', ScopeInfo.TASK), ScopeInfo('goal3.task32', ScopeInfo.TASK), ] scope_to_infos = dict((x.scope, x) for x in infos) it = ScopeInfoIterator(scope_to_infos) actual = list(it.iterate([GLOBAL_SCOPE, 'goal1', 'goal2.task21', 'goal3'])) expected_scopes = [ GLOBAL_SCOPE, 'subsys2', 'subsys1.subsys2', 'goal1', 'goal1.task11', 'goal1.task12', 'subsys1.goal1.task12', 'goal2.task21', 'goal3', 'goal3.task31', 'goal3.task32', ] expected_scope_infos = [scope_to_infos[x] for x in expected_scopes] self.assertEquals(expected_scope_infos, actual)
def _print_options_help(self): """Print a help screen. Assumes that self._help_request is an instance of OptionsHelp. Note: Ony useful if called after options have been registered. """ show_all_help = self._help_request.all_scopes if show_all_help: help_scopes = list(self._options.known_scope_to_info.keys()) else: # The scopes explicitly mentioned by the user on the cmd line. help_scopes = set( self._options.scope_to_flags.keys()) - {GLOBAL_SCOPE} scope_infos = list( ScopeInfoIterator( self._options.known_scope_to_info).iterate(help_scopes)) if scope_infos: for scope_info in scope_infos: help_str = self._format_help(scope_info) if help_str: print(help_str) return else: print(pants_release()) print('\nUsage:') print( f' {self.bin_name} [option ...] [goal ...] [target...] Attempt the specified goals.' ) print( f' {self.bin_name} help Get help.' ) print( f' {self.bin_name} help [goal] Get help for a goal.' ) print( f' {self.bin_name} help-advanced [goal] Get help for a goal\'s advanced options.' ) print( f' {self.bin_name} help-all Get help for all goals.' ) print( f' {self.bin_name} goals List all installed goals.' ) print('') print(' [target] accepts two special forms:') print( ' dir: to include all targets in the specified directory.') print( ' dir:: to include all targets found recursively under the directory.' ) print('\nFriendly docs:\n http://pantsbuild.org/') print(self._format_help(ScopeInfo(GLOBAL_SCOPE, ScopeInfo.GLOBAL)))
def get_scope_data(scope): ret = [] for si in ScopeInfoIterator(self.context.options.known_scope_to_info).iterate([scope]): help_info = HelpInfoExtracter(si.scope).get_option_scope_help_info_from_parser( self.context.options.get_parser(si.scope)) ret.append({ # We don't use _asdict(), because then .description wouldn't be available. 'scope_info': si, # We do use _asdict() here, so our mustache library can do property expansion. 'help_info': help_info._asdict(), }) return ret
def _print_options_help(self) -> None: """Print a help screen. Assumes that self._help_request is an instance of OptionsHelp. Note: Ony useful if called after options have been registered. """ help_request = cast(OptionsHelp, self._help_request) global_options = self._options.for_global_scope() if help_request.all_scopes: help_scopes = set(self._options.known_scope_to_info.keys()) else: # The scopes explicitly mentioned by the user on the cmd line. help_scopes = set( self._options.scope_to_flags.keys()) - {GLOBAL_SCOPE} # If --v1 is enabled at all, don't use v2_help, even if --v2 is also enabled. v2_help = global_options.v2 and not global_options.v1 scope_info_iterator = ScopeInfoIterator( scope_to_info=self._options.known_scope_to_info, v2_help=v2_help) scope_infos = list(scope_info_iterator.iterate(help_scopes)) if scope_infos: for scope_info in scope_infos: help_str = self._format_help(scope_info, help_request.advanced) if help_str: print(help_str) return else: print(pants_release()) print("\nUsage:") print( f" {self.bin_name} [option ...] [goal ...] [target/file ...] Attempt the specified goals." ) print( f" {self.bin_name} help Get help." ) print( f" {self.bin_name} help [goal] Get help for a goal." ) print( f" {self.bin_name} help-advanced Get help for global advanced options." ) print( f" {self.bin_name} help-advanced [goal] Get help for a goal's advanced options." ) print( f" {self.bin_name} help-all Get help for all goals." ) print( f" {self.bin_name} goals List all installed goals." ) print("") print(" [file] can be:") print(" A path to a file.") print( " A path glob, such as '**/*.ext', in quotes to prevent shell expansion." ) print(" [target] accepts two special forms:") print( " dir: to include all targets in the specified directory.") print( " dir:: to include all targets found recursively under the directory." ) print("\nFriendly docs:\n http://pantsbuild.org/") print( self._format_help(ScopeInfo(GLOBAL_SCOPE, ScopeInfo.GLOBAL), help_request.advanced))