Skip to content

Commit

Permalink
Silence warnings for not consumed autoload_range and no_configure_log…
Browse files Browse the repository at this point in the history
…ging parameters in core config.
  • Loading branch information
starhel committed Apr 11, 2023
1 parent a475710 commit 6c5a463
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions luigi/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class core(task.Config):
This is arguably a bit of a hack.
'''
use_cmdline_section = False
ignore_unconsumed = {
'autoload_range',
'no_configure_logging',
}

local_scheduler = parameter.BoolParameter(
default=False,
Expand Down
3 changes: 2 additions & 1 deletion luigi/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,11 @@ def list_to_tuple(x):
if not hasattr(cls, "_unconsumed_params"):
cls._unconsumed_params = set()
if task_family in conf.sections():
ignore_unconsumed = getattr(cls, 'ignore_unconsumed', set())
for key, value in conf[task_family].items():
key = key.replace('-', '_')
composite_key = f"{task_family}_{key}"
if key not in result and composite_key not in cls._unconsumed_params:
if key not in result and key not in ignore_unconsumed and composite_key not in cls._unconsumed_params:
warnings.warn(
"The configuration contains the parameter "
f"'{key}' with value '{value}' that is not consumed by the task "
Expand Down
34 changes: 31 additions & 3 deletions test/task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ class TaskB(luigi.Task):

@with_config(
{
"TaskA": {
"TaskEdgeCase": {
"camelParam": "camelCase",
"underscore_param": "underscore",
"dash-param": "dash",
},
}
)
def test_unconsumed_params_edge_cases(self):
class TaskA(luigi.Task):
class TaskEdgeCase(luigi.Task):
camelParam = luigi.Parameter()
underscore_param = luigi.Parameter()
dash_param = luigi.Parameter()
Expand All @@ -243,12 +243,40 @@ class TaskA(luigi.Task):
category=luigi.parameter.UnconsumedParameterWarning,
)

task = TaskA()
task = TaskEdgeCase()
assert len(w) == 0
assert task.camelParam == "camelCase"
assert task.underscore_param == "underscore"
assert task.dash_param == "dash"

@with_config(
{
"TaskIgnoreUnconsumed": {
"a": "a",
"b": "b",
"c": "c",
},
}
)
def test_unconsumed_params_ignore_unconsumed(self):
class TaskIgnoreUnconsumed(luigi.Task):
ignore_unconsumed = {"b", "d"}

a = luigi.Parameter()

with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings(
action="ignore",
category=Warning,
)
warnings.simplefilter(
action="always",
category=luigi.parameter.UnconsumedParameterWarning,
)

TaskIgnoreUnconsumed()
assert len(w) == 1


class TaskFlattenOutputTest(unittest.TestCase):
def test_single_task(self):
Expand Down

0 comments on commit 6c5a463

Please sign in to comment.