Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Create a wrapper for L0 readers click commands #61

Closed
ghiggi opened this issue Sep 13, 2022 · 0 comments
Closed

[FEATURE] Create a wrapper for L0 readers click commands #61

ghiggi opened this issue Sep 13, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ghiggi
Copy link
Collaborator

ghiggi commented Sep 13, 2022

Is your feature request related to a problem? Please describe.

I think the code readability of the L0 readers would improve if we manage to compact reduce the list of click commands
that are present above the reader function definition

Describe the solution you'd like

Follow this approach

@click.command()  # options_metavar='<options>'
@click.argument('raw_dir', type=click.Path(exists=True), metavar='<raw_dir>')
@click.argument('processed_dir', metavar='<processed_dir>')
@click.option('-L0A', '--L0A_processing', type=bool, show_default=True, default=True, help="Perform L0A processing")
@click.option('-L0B', '--L0B_processing', type=bool, show_default=True, default=True, help="Perform L0B processing")
@click.option('-k', '--keep_L0A', type=bool, show_default=True, default=True, help="Whether to keep the L0A Parquet file")
@click.option('-f', '--force', type=bool, show_default=True, default=False, help="Force overwriting")
@click.option('-v', '--verbose', type=bool, show_default=True, default=False, help="Verbose")
@click.option('-d', '--debugging_mode', type=bool, show_default=True, default=False, help="Switch to debugging mode")
@click.option('-l', '--lazy', type=bool, show_default=True, default=True, help="Use dask if lazy=True")
@click.option('-s', '--single_netcdf', type=bool, show_default=True, default=True, help="Produce single netCDF")
def main(raw_dir,
         processed_dir,
         L0A_processing=True,
         L0B_processing=True,
         keep_L0A=False,
         force=False,
         verbose=False,
         debugging_mode=False,
         lazy=True,
         single_netcdf = True, 
         ):

would become

# Define this in some file
def readers_click_options(function):
  function = click.argument('raw_dir', type=click.Path(exists=True), metavar='<raw_dir>')(function)
  function = click.argument('processed_dir', metavar='<processed_dir>')(function)
  function = click.option('-L0A', '--L0A_processing', type=bool, show_default=True, default=True, help="Perform L0A processing")(function)
  function = click.option('-L0B', '--L0B_processing', type=bool, show_default=True, default=True, help="Perform L0B processing")(function)
  function = click.option('-k', '--keep_L0A', type=bool, show_default=True, default=True, help="Whether to keep the L0A Parquet file")(function)
  function = click.option('-f', '--force', type=bool, show_default=True, default=False, help="Force overwriting")(function)
  function = click.option('-v', '--verbose', type=bool, show_default=True, default=False, help="Verbose")(function)
  function = click.option('-d', '--debugging_mode', type=bool, show_default=True, default=False, help="Switch to debugging mode")(function)
  function = click.option('-l', '--lazy', type=bool, show_default=True, default=True, help="Use dask if lazy=True")(function)
  function = click.option('-s', '--single_netcdf', type=bool, show_default=True, default=True, help="Produce single netCDF")(function)
  return function 

## In each reader 
#  Add the import of  readers_click_options
# And modify as follow
@click.command()
@readers_click_options
def main(raw_dir,
         processed_dir,
         L0A_processing=True,
         L0B_processing=True,
         keep_L0A=False,
         force=False,
         verbose=False,
         debugging_mode=False,
         lazy=True,
         single_netcdf = True, 
         ):



@regislon can you take care of that?
Related to this refactor ... do we maybe want to change the name of the function? From main to reader

@ghiggi ghiggi added the enhancement New feature or request label Sep 13, 2022
@ghiggi ghiggi self-assigned this Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants