Skip to content

Commit

Permalink
Use plugin name instead of hardcoded plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vikineema committed Oct 16, 2023
1 parent 1695eeb commit 578362e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
14 changes: 8 additions & 6 deletions deafrica_conflux/cli/run_from_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from importlib import import_module

import click
import datacube
Expand All @@ -20,10 +21,9 @@
help="Run deafrica-conflux on a list of dataset ids passed as a string.",
)
@click.option(
"--plugin-file",
"-p",
type=click.Path(exists=True, dir_okay=False),
help="Path to Conflux plugin (.py).",
"--plugin-name",
type=str,
help="Name of the plugin. Plugin file must be in the deafrica_conflux/plugins/ directory.",
)
@click.option(
"-dataset-ids-list", type=str, help="A list of dataset IDs to run deafrica-conflux on."
Expand Down Expand Up @@ -72,7 +72,7 @@
help="Not matter DataFrame is empty or not, always as it as Parquet file.",
)
def run_from_list(
plugin_file,
plugin_name,
dataset_ids_list,
polygons_vector_file,
use_id,
Expand All @@ -91,8 +91,10 @@ def run_from_list(
_log = logging.getLogger(__name__)

# Read the plugin as a Python module.
module = import_module(f"deafrica_conflux.plugins.{plugin_name}")
plugin_file = module.__file__
plugin = run_plugin(plugin_file)
_log.info(f"Using plugin {plugin.__file__}")
_log.info(f"Using plugin {plugin_file}")
validate_plugin(plugin)

# Get the product name from the plugin.
Expand Down
11 changes: 9 additions & 2 deletions deafrica_conflux/cli/run_from_queue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from importlib import import_module

import boto3
import click
Expand All @@ -13,7 +14,6 @@
import deafrica_conflux.queues
import deafrica_conflux.stack
from deafrica_conflux.cli.logs import logging_setup
from deafrica_conflux.plugins import waterbodies_timeseries
from deafrica_conflux.plugins.utils import run_plugin, validate_plugin


Expand All @@ -22,6 +22,11 @@
no_args_is_help=True,
help="Run deafrica-conflux on dataset ids from an SQS queue.",
)
@click.option(
"--plugin-name",
type=str,
help="Name of the plugin. Plugin file must be in the deafrica_conflux/plugins/ directory.",
)
@click.option(
"--dataset-ids-queue",
type=str,
Expand Down Expand Up @@ -81,6 +86,7 @@
help="Not matter DataFrame is empty or not, always as it as Parquet file.",
)
def run_from_sqs_queue(
plugin_name,
dataset_ids_queue,
polygons_vector_file,
use_id,
Expand All @@ -101,7 +107,8 @@ def run_from_sqs_queue(
_log = logging.getLogger(__name__)

# Read the plugin as a Python module.
plugin_file = waterbodies_timeseries.__file__
module = import_module(f"deafrica_conflux.plugins.{plugin_name}")
plugin_file = module.__file__
plugin = run_plugin(plugin_file)
_log.info(f"Using plugin {plugin_file}")
validate_plugin(plugin)
Expand Down
14 changes: 8 additions & 6 deletions deafrica_conflux/cli/run_from_txt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from importlib import import_module

import click
import datacube
Expand All @@ -22,10 +23,9 @@
help="Run deafrica-conflux on dataset ids from a text file.",
)
@click.option(
"--plugin-file",
"-p",
type=click.Path(exists=True, dir_okay=False),
help="Path to Conflux plugin (.py).",
"--plugin-name",
type=str,
help="Name of the plugin. Plugin file must be in the deafrica_conflux/plugins/ directory.",
)
@click.option(
"--dataset-ids-file",
Expand Down Expand Up @@ -76,7 +76,7 @@
help="Not matter DataFrame is empty or not, always as it as Parquet file.",
)
def run_from_txt(
plugin_file,
plugin_name,
dataset_ids_file,
polygons_vector_file,
use_id,
Expand All @@ -98,8 +98,10 @@ def run_from_txt(
_log = logging.getLogger(__name__)

# Read the plugin as a Python module.
module = import_module(f"deafrica_conflux.plugins.{plugin_name}")
plugin_file = module.__file__
plugin = run_plugin(plugin_file)
_log.info(f"Using plugin {plugin.__file__}")
_log.info(f"Using plugin {plugin_file}")
validate_plugin(plugin)

# Get the product name from the plugin.
Expand Down

0 comments on commit 578362e

Please sign in to comment.