diff --git a/ctapipe/core/tests/test_tool.py b/ctapipe/core/tests/test_tool.py index 8db62479be1..a65ecf8344a 100644 --- a/ctapipe/core/tests/test_tool.py +++ b/ctapipe/core/tests/test_tool.py @@ -426,3 +426,38 @@ def start(self): assert run_tool(tool, raises=False) == 1 assert tool.manager.enter_called assert tool.manager.exit_called + + +def test_activity(tmp_path): + """check that the config is correctly in the provenance""" + + class MyTool(Tool): + name = "test_prov_log" + description = "test" + userparam = Float(5.0, help="parameter").tag(config=True) + + tool = MyTool() + + config_path = tmp_path / "config.json" + config_path.write_text(json.dumps({"MyTool": {"userparam": 10.0}})) + provenance_path = tmp_path / "provenance.json" + + run_tool( + tool, + [ + "--config", + str(config_path), + f"--provenance-log={provenance_path}", + ], + ) + + activities = json.loads(tool.provenance_log.read_text()) + # provlog contains all activities from all tests, last one is the tool we just ran + provlog = activities[-1] + assert provlog["activity_name"] == MyTool.name + + # test config file is in inputs, regression test for #2313 + inputs = provlog["input"] + assert len(inputs) == 1 + assert inputs[0]["role"] == "Tool Configuration" + assert inputs[0]["url"] == str(config_path) diff --git a/ctapipe/core/tool.py b/ctapipe/core/tool.py index 56de387a271..e39dcaff89b 100644 --- a/ctapipe/core/tool.py +++ b/ctapipe/core/tool.py @@ -405,11 +405,14 @@ def run(self, argv=None, raises=False): with self._exit_stack: try: - self.initialize(argv) self.log.info(f"Starting: {self.name}") Provenance().start_activity(self.name) + + self.initialize(argv) + self.setup() self.is_setup = True + self.log.debug(f"CONFIG: {self.get_current_config()}") Provenance().add_config(self.get_current_config()) diff --git a/docs/changes/2312.bugfix.rst b/docs/changes/2312.bugfix.rst new file mode 100644 index 00000000000..cdcf85d1e7c --- /dev/null +++ b/docs/changes/2312.bugfix.rst @@ -0,0 +1 @@ +Fix for config files not being included as inputs in provenance log.