11import abc
2+ import argparse
23from typing import List
34
45from wai .logging import LOGGING_WARNING
5- from seppl import InputConsumer , OutputProducer , PluginWithLogging , Initializable , init_initializable , Session , SessionHandler
6+ from seppl import InputConsumer , OutputProducer , PluginWithLogging , Initializable , init_initializable , Session , SessionHandler , SkippablePlugin , add_skip_option
67
78FILTER_ACTION_KEEP = "keep"
89FILTER_ACTION_DISCARD = "discard"
910FILTER_ACTIONS = [FILTER_ACTION_KEEP , FILTER_ACTION_DISCARD ]
1011
1112
12- class Filter (PluginWithLogging , InputConsumer , OutputProducer , SessionHandler , Initializable , abc .ABC ):
13+ class Filter (PluginWithLogging , InputConsumer , OutputProducer , SessionHandler , Initializable , SkippablePlugin , abc .ABC ):
1314 """
1415 Base class for filters.
1516 """
@@ -26,6 +27,38 @@ def __init__(self, logger_name: str = None, logging_level: str = LOGGING_WARNING
2627 super ().__init__ (logger_name = logger_name , logging_level = logging_level )
2728 self ._session = None
2829 self ._last_input = None
30+ self .skip = False
31+
32+ def _create_argparser (self ) -> argparse .ArgumentParser :
33+ """
34+ Creates an argument parser. Derived classes need to fill in the options.
35+
36+ :return: the parser
37+ :rtype: argparse.ArgumentParser
38+ """
39+ parser = super ()._create_argparser ()
40+ add_skip_option (parser )
41+ return parser
42+
43+ def _apply_args (self , ns : argparse .Namespace ):
44+ """
45+ Initializes the object with the arguments of the parsed namespace.
46+
47+ :param ns: the parsed arguments
48+ :type ns: argparse.Namespace
49+ """
50+ super ()._apply_args (ns )
51+ self .skip = ns .skip
52+
53+ @property
54+ def is_skipped (self ) -> bool :
55+ """
56+ Returns whether the plugin is to be skipped.
57+
58+ :return: True if to be skipped
59+ :rtype: bool
60+ """
61+ return self .skip
2962
3063 @property
3164 def session (self ) -> Session :
0 commit comments