def add_arguments(self, parser, cli_name): """Add create package arguments.""" arg = parser.add_argument( 'name', nargs='?', help='Name of the package', ) arg = parser.add_argument( '--source-space', help="Path to the source space (default 'CWD/src/NAME')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--profile-space', type=argparse_existing_dir, help="Path to the profile space (default 'CWD/profile')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--public-space', help="Path to the public space (default 'CWD/public')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--private-space', help="Path to the private space (default 'CWD/private')", ) # Allow all available policy_type's to provide additional arguments for policy_type in yield_supported_policy_types(): policy_type_impl = policy_type.load()() group = parser.add_argument_group("'{0}' policy_type options" .format(policy_type_impl.policy_type)) call_prepare_arguments(policy_type_impl.prepare_arguments, group)
def add_arguments(self, parser, cli_name): """Add build package arguments.""" arg = parser.add_argument( 'path', nargs='?', type=argparse_existing_dir, default=os.curdir, help="Path to the package (default '%s')" % os.curdir, ) arg.completer = FilesCompleter() arg = parser.add_argument( '--build-space', help="Path to the build space (default 'CWD/build')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--install-space', help="Path to the install space (default 'CWD/install')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--public-space', help="Path to the public space (default 'CWD/public')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--private-space', help="Path to the private space (default 'CWD/private')", ) arg.completer = FilesCompleter() parser.add_argument( '--skip-build', action='store_true', default=False, help='Skip the build step (this can be used when installing or ' 'testing and you know that the build has successfully run)', ) parser.add_argument( '--skip-install', action='store_true', default=False, help='Skip the install step (only makes sense when install has been ' 'done before using symlinks and no new files have been added or ' 'when testing after a successful install)', ) # parser.add_argument( # '-s', '--symlink-install', # action='store_true', # default=False, # help='Use symlinks instead of copying files wherever possible', # ) # Allow all available build_type's to provide additional arguments for build_type in yield_supported_build_types(): build_type_impl = build_type.load()() group = parser.add_argument_group("'{0}' build_type options" .format(build_type_impl.build_type)) call_prepare_arguments(build_type_impl.prepare_arguments, group)
def prepare_arguments(parser, args): """Add parameters to argparse for the build verb and available plugins. After adding the generic verb arguments, this function loads all available build_type plugins and then allows the plugins to add additional arguments to the parser in a new :py:class:`argparse.ArgumentGroup` for that build_type. :param parser: ArgumentParser object to which arguments are added :type parser: :py:class:`argparse.ArgumentParser` :param list args: list of arguments as str's :returns: modified version of the original parser given :rtype: :py:class:`argparse.ArgumentParser` """ # Add verb arguments parser.add_argument('-C', '--directory', default=os.curdir, help="The base path of the workspace (default '%s')" % os.curdir) parser.add_argument( 'basepath', nargs='?', type=argparse_existing_dir, default=os.path.join(os.curdir, 'src'), help="Base path to the packages (default 'CWD/src')", ) build_pkg_add_arguments(parser) parser.add_argument( '--isolated', action='store_true', default=False, help='Use separate subfolders in the install space for each package', ) parser.add_argument( '--start-with', help='Start with a particular package', ) parser.add_argument( '--end-with', help='End with a particular package', ) parser.add_argument( '--only-package', '--only', help= 'Only process a particular package, implies --start-with <pkg> and --end-with <pkg>' ) # Allow all available build_type's to provide additional arguments for build_type in yield_supported_build_types(): build_type_impl = build_type.load()() group = parser.add_argument_group("'{0}' build_type options".format( build_type_impl.build_type)) call_prepare_arguments(build_type_impl.prepare_arguments, group, args) return parser
def prepare_arguments(parser, args): """ Add parameters to argparse for the build_pkg verb and its plugins. After adding the generic verb arguments, this function tries to determine the build type of the target package. This is done by gracefully trying to get the positional ``path`` argument from the arguments, falling back to the default ``os.curdir``. Then it searches for a package manifest in that path. If it finds the package manifest it then determines the build type of the package, e.g. ``ament_cmake``. It then tries to load a build type plugin for that build type. If the loading is successful it will allow the plugin to add additional arguments to the parser in a new :py:class:`argparse.ArgumentGroup` for that build type. :param parser: ArgumentParser object to which arguments are added :type parser: :py:class:`argparse.ArgumentParser` :param list args: list of arguments as str's :returns: modified version of the original parser given :rtype: :py:class:`argparse.ArgumentParser` """ # Add verb arguments add_path_argument(parser) add_arguments(parser) # Detected build type if possible try: # Remove -h and --help to prevent printing help messages filt_args = list(filter(lambda x: x not in ['-h', '--help'], args)) # Remove first position argument, because that will be the verb for i, arg in enumerate(filt_args): if not arg.startswith('-'): del filt_args[i] break # Parse the arguments to find the user's provided path (or the default) opts, _ = parser.parse_known_args(filt_args) # Check to ensure the path has a package validate_package_path(opts.path) # Get the build_type from the package manifest build_type = get_build_type(opts.path) # Find an entry point which supports this build type build_type_impl = get_class_for_build_type(build_type)() # Let the detected build type plugin add arguments group = parser.add_argument_group( '{0} (detected) options'.format(build_type_impl.build_type)) call_prepare_arguments( build_type_impl.prepare_arguments, group, args, ) # Catch value and system errors which will raise later # This is done to preserve -h and --help's ability to function except (MissingPluginError, ValueError) as exc: # If system exit AND -h or --help are used, show the error if '-h' in args or '--help' in args: print('Error: Could not detect package build type:', exc) return parser
def prepare_arguments(parser, args): """Add parameters to argparse for the build verb and available plugins. After adding the generic verb arguments, this function loads all available build_type plugins and then allows the plugins to add additional arguments to the parser in a new :py:class:`argparse.ArgumentGroup` for that build_type. :param parser: ArgumentParser object to which arguments are added :type parser: :py:class:`argparse.ArgumentParser` :param list args: list of arguments as str's :returns: modified version of the original parser given :rtype: :py:class:`argparse.ArgumentParser` """ # Add verb arguments parser.add_argument( '-C', '--directory', default=os.curdir, help="The base path of the workspace (default '%s')" % os.curdir ) parser.add_argument( 'basepath', nargs='?', type=argparse_existing_dir, default=os.path.join(os.curdir, 'src'), help="Base path to the packages (default 'CWD/src')", ) build_pkg_add_arguments(parser) parser.add_argument( '--isolated', action='store_true', default=False, help='Use separate subfolders in the install space for each package', ) parser.add_argument( '--start-with', help='Start with a particular package', ) parser.add_argument( '--end-with', help='End with a particular package', ) parser.add_argument( '--only-package', '--only', help='Only process a particular package, implies --start-with <pkg> and --end-with <pkg>' ) # Allow all available build_type's to provide additional arguments for build_type in yield_supported_build_types(): build_type_impl = build_type.load()() group = parser.add_argument_group("'{0}' build_type options" .format(build_type_impl.build_type)) call_prepare_arguments(build_type_impl.prepare_arguments, group, args) return parser
def prepare_arguments(parser, args): """ Add parameters to argparse for the build_pkg verb and its plugins. After adding the generic verb arguments, this function tries to determine the build type of the target package. This is done by gracefully trying to get the positional ``path`` argument from the arguments, falling back to the default ``os.curdir``. Then it searches for a package manifest in that path. If it finds the package manifest it then determines the build type of the package, e.g. ``ament_cmake``. It then tries to load a build type plugin for that build type. If the loading is successful it will allow the plugin to add additional arguments to the parser in a new :py:class:`argparse.ArgumentGroup` for that build type. :param parser: ArgumentParser object to which arguments are added :type parser: :py:class:`argparse.ArgumentParser` :param list args: list of arguments as str's :returns: modified version of the original parser given :rtype: :py:class:`argparse.ArgumentParser` """ # Add verb arguments add_path_argument(parser) add_arguments(parser) # Detected build type if possible try: # Remove -h and --help to prevent printing help messages filt_args = list(filter(lambda x: x not in ['-h', '--help'], args)) # Remove first position argument, because that will be the verb for i, arg in enumerate(filt_args): if not arg.startswith('-'): del filt_args[i] break # Parse the arguments to find the user's provided path (or the default) opts, _ = parser.parse_known_args(filt_args) # Check to ensure the path has a package validate_package_path(opts.path) # Get the build_type from the package manifest build_type = get_build_type(opts.path) # Find an entry point which supports this build type build_type_impl = get_class_for_build_type(build_type)() # Let the detected build type plugin add arguments group = parser.add_argument_group('{0} (detected) options'.format( build_type_impl.build_type)) call_prepare_arguments( build_type_impl.prepare_arguments, group, args, ) # Catch value and system errors which will raise later # This is done to preserve -h and --help's ability to function except (MissingPluginError, ValueError) as exc: # If system exit AND -h or --help are used, show the error if '-h' in args or '--help' in args: print('Error: Could not detect package build type:', exc) return parser
def add_arguments(self, parser, cli_name): """Add init profile arguments.""" arg = parser.add_argument( '--source-space', help="Path to the source space (default 'CWD/src')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--profile-space', # type=argparse_existing_dir, help="Path to the profile space (default 'CWD/profile')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--public-space', help="Path to the public space (default 'CWD/public')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--private-space', help="Path to the private space (default 'CWD/private')", ) arg = parser.add_argument( '--skip-build', action='store_true', default=False, help='Skip the build step (this can be used when installing or ' 'testing and you know that the build has successfully run)', ) arg = parser.add_argument( '--skip-install', action='store_true', default=False, help='Skip the install step (only makes sense when build has been ' 'done before and no new files have been added or)', ) arg = parser.add_argument( '--bootstrap', action='store', default=False, help='Bootstrap the profile step (only makes sense when no profle' 'is first provided to be initialized)', ) # Allow all available policy_type's to provide additional arguments for policy_type in yield_supported_policy_types(): policy_type_impl = policy_type.load()() group = parser.add_argument_group("'{0}' policy_type options" .format(policy_type_impl.policy_type)) call_prepare_arguments(policy_type_impl.prepare_arguments, group)
def add_arguments(self, parser, cli_name): """Add build arguments.""" arg = parser.add_argument( '-C', '--directory', default=os.curdir, help="The base path of the workspace (default '%s')" % os.curdir, ) arg = parser.add_argument( 'basepath', nargs='?', type=argparse_existing_dir, default=os.path.join(os.curdir, 'src'), help="Base path to the packages (default 'CWD/src')", ) arg.completer = FilesCompleter() arg = parser.add_argument( '--only-packages', nargs='+', default=[], help='Only process a particular set of packages', ) arg = parser.add_argument( '--skip-packages', nargs='*', default=[], help='Set of packages to skip', ) arg = parser.add_argument( '--parallel', action='store_true', help='Enable building packages in parallel', ) # Allow all available build_type's to provide additional arguments for build_type in yield_supported_build_types(): build_type_impl = build_type.load()() group = parser.add_argument_group( "'{0}' build_type options".format(build_type_impl.build_type)) call_prepare_arguments(build_type_impl.prepare_arguments, group)