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

Fix activity start order #2312

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ctapipe/core/tests/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions docs/changes/2312.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for config files not being included as inputs in provenance log.