code: def args_to_api(args, parser):
      """Convert argparse args to API calls."""
  
      # handle legacy executor names
      if args.dryrun:
          args.executor = "dryrun"
      elif args.touch:
          args.executor = "touch"
      elif args.executor is None:
          args.executor = "local"
  
      executor_plugin = _get_executor_plugin_registry().get_plugin(
          args.executor
      )
      executor_settings = executor_plugin.get_settings(args)
  
      storage_provider_settings = {
          name: StoragePluginRegistry()
          .get_plugin(name)
          .get_settings(args)
          for name in StoragePluginRegistry().get_registered_plugins()
      }
  
      if args.cores is None:
          if executor_plugin.common_settings.local_exec:
              # use --jobs as an alias for --cores
              args.cores = args.jobs
          elif executor_plugin.common_settings.dryrun_exec:
              args.cores = 1
  
      # start profiler if requested
      if args.runtime_profile:
          import yappi
  
          yappi.start()
  
      log_handlers = setup_log_handlers(args, parser)
  
      edit_notebook = parse_edit_notebook(args)
  
      wait_for_files = parse_wait_for_files(args)
  
      with SnakemakeApi(
          OutputSettings(
              printshellcmds=args.printshellcmds,
              nocolor=args.nocolor,
              quiet=args.quiet,
              debug_dag=args.debug_dag,
              verbose=args.verbose,
              show_failed_logs=args.show_failed_logs,
              log_handlers=log_handlers,
              keep_logger=False,
          )
      ) as snakemake_api:
          deployment_method = args.software_deployment_method
          if args.use_conda:
              deployment_method.add(DeploymentMethod.CONDA)
          if args.use_apptainer:
              deployment_method.add(DeploymentMethod.APPTAINER)
          if args.use_envmodules:
              deployment_method.add(DeploymentMethod.ENV_MODULES)
  
          try:
              storage_settings = StorageSettings(
                  default_storage_provider=args.default_storage_provider,
                  default_storage_prefix=args.default_storage_prefix,
                  local_storage_prefix=args.local_storage_prefix,
                  shared_fs_usage=args.shared_fs_usage,
                  keep_storage_local=args.keep_storage_local_copies,
                  notemp=args.notemp,
                  all_temp=args.all_temp,
                  unneeded_temp_files=args.unneeded_temp_files,
              )
  
              if args.deploy_sources:
                  query, checksum = args.deploy_sources
                  snakemake_api.deploy_sources(
                      query,
                      checksum,
                      storage_settings=storage_settings,
                      storage_provider_settings=storage_provider_settings,
                  )
              else:
                  workflow_api = snakemake_api.workflow(
                      resource_settings=ResourceSettings(
                          cores=args.cores,
                          nodes=args.jobs,
                          local_cores=args.local_cores,
                          max_threads=args.max_threads,
                          resources=args.resources,
                          overwrite_threads=args.set_threads,
                          overwrite_scatter=args.set_scatter,
                          overwrite_resource_scopes=args.set_resource_scopes,
                          overwrite_resources=args.set_resources,
                          default_resources=args.default_resources,
                      ),
                      config_settings=ConfigSettings(
                          config=args.config,
                          configfiles=args.configfile,
                      ),
                      storage_settings=storage_settings,
                      storage_provider_settings=storage_provider_settings,
                      workflow_settings=WorkflowSettings(
                          wrapper_prefix=args.wrapper_prefix,
                          exec_mode=args.mode,
                          cache=args.cache,
                      ),
                      deployment_settings=DeploymentSettings(
                          deployment_method=deployment_method,
                          conda_prefix=args.conda_prefix,
                          conda_cleanup_pkgs=args.conda_cleanup_pkgs,
                          conda_base_path=args.conda_base_path,
                          conda_frontend=args.conda_frontend,
                          conda_not_block_search_path_envvars=args.conda_not_block_search_path_envvars,
                          apptainer_args=args.apptainer_args,
                          apptainer_prefix=args.apptainer_prefix,
                      ),
                      snakefile=args.snakefile,
                      workdir=args.directory,
                  )
  
                  if args.lint:
                      any_lint = workflow_api.lint()
                      if any_lint:
                          # trigger exit code 1
                          return False
                  elif args.list_target_rules:
                      workflow_api.list_rules(only_targets=True)
                  elif args.list_rules:
                      workflow_api.list_rules(only_targets=False)
                  elif args.print_compilation:
                      workflow_api.print_compilation()
                  else:
                      dag_api = workflow_api.dag(
                          dag_settings=DAGSettings(
                              targets=args.targets,
                              target_jobs=args.target_jobs,
                              target_files_omit_workdir_adjustment=args.target_files_omit_workdir_adjustment,
                              batch=args.batch,
                              forcetargets=args.force,
                              forceall=args.forceall,
                              forcerun=args.forcerun,
                              until=args.until,
                              omit_from=args.omit_from,
                              force_incomplete=args.rerun_incomplete,
                              allowed_rules=args.allowed_rules,
                              rerun_triggers=args.rerun_triggers,
                              max_inventory_wait_time=args.max_inventory_time,
                          ),
                      )
  
                      # None indicates that the flag is not being used, a set indicates used
                      if args.preemptible_rules is not None:
                          # If no explicit rules provided (empty set) we assume all preemptible
                          # Checking for "not" evaluates for an empty set
                          if not args.preemptible_rules:
                              preemptible_rules = PreemptibleRules(
                                  all=True
                              )
                          else:
                              preemptible_rules = PreemptibleRules(
                                  rules=args.preemptible_rules
                              )
                      else:
                          preemptible_rules = PreemptibleRules()
  
                      if args.containerize:
                          dag_api.containerize()
                      elif args.report:
                          dag_api.create_report(
                              path=args.report,
                              stylesheet=args.report_stylesheet,
                          )
                      elif args.generate_unit_tests:
                          dag_api.generate_unit_tests(
                              args.generate_unit_tests
                          )
                      elif args.dag:
                          dag_api.printdag()
                      elif args.rulegraph:
                          dag_api.printrulegraph()
                      elif args.filegraph:
                          dag_api.printfilegraph()
                      elif args.d3dag:
                          dag_api.printd3dag()
                      elif args.unlock:
                          dag_api.unlock()
                      elif args.cleanup_metadata:
                          dag_api.cleanup_metadata(
                              args.cleanup_metadata
                          )
                      elif args.conda_cleanup_envs:
                          dag_api.conda_cleanup_envs()
                      elif args.conda_create_envs_only:
                          dag_api.conda_create_envs()
                      elif args.list_conda_envs:
                          dag_api.conda_list_envs()
                      elif args.cleanup_shadow:
                          dag_api.cleanup_shadow()
                      elif args.container_cleanup_images:
                          dag_api.container_cleanup_images()
                      elif args.list_changes:
                          dag_api.list_changes(args.list_changes)
                      elif args.list_untracked:
                          dag_api.list_untracked()
                      elif args.summary:
                          dag_api.summary()
                      elif args.detailed_summary:
                          dag_api.summary(detailed=True)
                      elif args.archive:
                          dag_api.archive(args.archive)
                      elif args.delete_all_output:
                          dag_api.delete_output()
                      elif args.delete_temp_output:
                          dag_api.delete_output(
                              only_temp=True, dryrun=args.dryrun
                          )
                      else:
                          dag_api.execute_workflow(
                              executor=args.executor,
                              execution_settings=ExecutionSettings(
                                  keep_going=args.keep_going,
                                  debug=args.debug,
                                  standalone=True,
                                  ignore_ambiguity=args.allow_ambiguity,
                                  lock=not args.nolock,
                                  ignore_incomplete=args.ignore_incomplete,
                                  latency_wait=args.latency_wait,
                                  wait_for_files=wait_for_files,
                                  no_hooks=args.no_hooks,
                                  retries=args.retries,
                                  attempt=args.attempt,
                                  use_threads=args.force_use_threads,
                                  shadow_prefix=args.shadow_prefix,
                                  keep_incomplete=args.keep_incomplete,
                                  keep_metadata=not args.drop_metadata,
                                  edit_notebook=edit_notebook,
                                  cleanup_scripts=not args.skip_script_cleanup,
                              ),
                              remote_execution_settings=RemoteExecutionSettings(
                                  jobname=args.jobname,
                                  jobscript=args.jobscript,
                                  max_status_checks_per_second=args.max_status_checks_per_second,
                                  seconds_between_status_checks=args.seconds_between_status_checks,
                                  container_image=args.container_image,
                                  preemptible_retries=args.preemptible_retries,
                                  preemptible_rules=preemptible_rules,
                                  envvars=args.envvars,
                                  immediate_submit=args.immediate_submit,
                                  job_deploy_sources=args.job_deploy_sources,
                              ),
                              scheduling_settings=SchedulingSettings(
                                  prioritytargets=args.prioritize,
                                  scheduler=args.scheduler,
                                  ilp_solver=args.scheduler_ilp_solver,
                                  solver_path=args.scheduler_solver_path,
                                  greediness=args.scheduler_greediness,
                                  max_jobs_per_second=args.max_jobs_per_second,
                              ),
                              group_settings=GroupSettings(
                                  group_components=args.group_components,
                                  overwrite_groups=args.groups,
                                  local_groupid=args.local_groupid,
                              ),
                              executor_settings=executor_settings,
                          )
  
          except Exception as e:
              snakemake_api.print_exception(e)
              return False
  
      # store profiler results if requested
      if args.runtime_profile:
          with open(args.runtime_profile, "w") as out:
              profile = yappi.get_func_stats()
              profile.sort("totaltime")
              profile.print_all(
                  out=out,
                  columns={
                      0: ("name", 120),
                      1: ("ncall", 10),
                      2: ("tsub", 8),
                      3: ("ttot", 8),
                      4: ("tavg", 8),
                  },
              )
      return True
  
imports: import os
  import re
  import sys
  from argparse import ArgumentDefaultsHelpFormatter
  from functools import partial
  from importlib.machinery import SourceFileLoader
  from pathlib import Path
  from typing import Set
  from snakemake_interface_executor_plugins.settings import ExecMode
  from snakemake_interface_storage_plugins.registry import StoragePluginRegistry
  import snakemake.common.argparse
  from snakemake import logging
  from snakemake.api import SnakemakeApi, _get_executor_plugin_registry, resolve_snakefile
  from snakemake.common import SNAKEFILE_CHOICES, __version__, async_run, get_appdirs, parse_key_value_arg
  from snakemake.dag import Batch
  from snakemake.exceptions import CliException, ResourceScopesException, print_exception
  from snakemake.resources import DefaultResources, ResourceScopes, eval_resource_expression, parse_resources
  from snakemake.settings import ChangeType, ConfigSettings, DAGSettings, DeploymentMethod, DeploymentSettings, ExecutionSettings, GroupSettings, NotebookEditMode, OutputSettings, PreemptibleRules, Quietness, RemoteExecutionSettings, RerunTrigger, ResourceSettings, SchedulingSettings, SharedFSUsage, StorageSettings, WorkflowSettings
  from snakemake.target_jobs import parse_target_jobs_cli_args
  from snakemake.utils import available_cpu_count, update_config
label_desc: Use image node_id 22 for calling a global function with example usage: args_to_api(args, parser) and returns: True, False, False