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

🚀 Add information to app summary output for what will be run on --commit (#27) #53

Merged
merged 5 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
57 changes: 49 additions & 8 deletions isabl_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,46 @@ def run(
if verbose:
self.echo_run_summary(run_tuples, skipped_tuples, invalid_tuples)

click.echo(
f"RAN {len(run_tuples)} | "
f"SKIPPED {len(skipped_tuples)} | "
f"INVALID {len(invalid_tuples)}\n"
)
if commit:
click.echo(
f"RAN {len(run_tuples)} | "
f"SKIPPED {len(skipped_tuples)} | "
f"INVALID {len(invalid_tuples)}\n"
)

else:
click.echo(
f"STAGED {len(run_tuples)} | "
f"SKIPPED {len(skipped_tuples)} | "
f"INVALID {len(invalid_tuples)}\n"
)

num_run_on_commit = len(run_tuples)
num_succeeded = 0
num_failed = 0

for i in skipped_tuples:
if i[1] == "SUCCEEDED":
num_succeeded += 1
if not self.application_protect_results:
num_run_on_commit += 1
else:
num_failed += 1

if num_run_on_commit == 1:
juanesarango marked this conversation as resolved.
Show resolved Hide resolved
click.echo(f"Add --commit to run {num_run_on_commit} analysis:\n")
else:
click.echo(f"Add --commit to run {num_run_on_commit} analyses:\n")

click.echo(f"{len(run_tuples)} STAGED")

if not self.application_protect_results:
click.echo(f"{num_succeeded} SUCCEEDED (Unprotected)")

click.echo(f"\n{num_failed} FAILED will be skipped")

if self.application_protect_results:
click.echo(f"{num_succeeded} SUCCEEDED (Protected) will be skipped")

return run_tuples, skipped_tuples, invalid_tuples

Expand Down Expand Up @@ -1197,7 +1232,9 @@ def patch_application_settings(self, client_id=None, **settings):

try:
assert self.application.settings.get(client_id) == settings
click.secho(f"\tNo changes detected, skipping patch.\n", err=True, fg="yellow")
click.secho(
f"\tNo changes detected, skipping patch.\n", err=True, fg="yellow"
)
except AssertionError:
try:
api.patch_instance(
Expand All @@ -1218,7 +1255,9 @@ def patch_application_settings(self, client_id=None, **settings):

click.secho("\tSuccessfully patched settings.\n", fg="green")
except TypeError as error: # pragma: no cover
click.secho(f"\tPatched failed with error: {error}.\n", err=True, fg="red")
click.secho(
f"\tPatched failed with error: {error}.\n", err=True, fg="red"
)

# create or update project level application
if self.has_project_auto_merge:
Expand Down Expand Up @@ -1573,7 +1612,9 @@ def get_individual_level_analyses(self, tuples):
current_tuple = tuples_map[individual.pk]

# make sure we only have one analysis per individual
assert individual.pk not in existing, f"Multiple analyses for {individual}"
assert (
individual.pk not in existing
), f"Multiple analyses for {individual}"
existing[individual.pk] = i

# patch analysis if tuples differ
Expand Down
89 changes: 87 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,13 @@ def test_get_experiments_from_default_cli_options(tmpdir):
)
result = runner.invoke(command, args, catch_exceptions=False)
assert experiments[0].system_id in result.output
assert "RAN 3 | SKIPPED 0 | INVALID 2" in result.output, result.output
assert "STAGED 3 | SKIPPED 0 | INVALID 2" in result.output, result.output

# revalidate experiment on existing analysis
api.patch_instance("experiments", experiments[0].system_id, notes="")
result = runner.invoke(command, args, catch_exceptions=False)
assert experiments[0].system_id in result.output
assert "RAN 5 | SKIPPED 0 | INVALID 0" in result.output
assert "STAGED 5 | SKIPPED 0 | INVALID 0" in result.output

# just get coverage for get_job_name
assert ExperimentsFromDefaulCLIApplication.get_job_name(analysis)
Expand Down Expand Up @@ -1013,3 +1013,88 @@ def test_ran_by_user(tmpdir, capsys):

captured = capsys.readouterr()
assert "Can't restart: started by different user. Consider --force" in captured.out


def test_commit_description(tmpdir, capsys):
user = api.create_instance("users", **factories.UserFactory())

experiment1 = api.create_instance("experiments", **factories.ExperimentFactory())
experiment2 = api.create_instance("experiments", **factories.ExperimentFactory())
experiment3 = api.create_instance("experiments", **factories.ExperimentFactory())

application = MockApplication()
application.application_protect_results = False
analysis = api.create_instance(
"analyses",
storage_url=tmpdir.strpath,
status="FAILED",
ran_by=user.username,
application=application.application,
targets=[experiment2],
)

analysis = api.create_instance(
"analyses",
storage_url=tmpdir.strpath,
status="SUCCEEDED",
ran_by=user.username,
application=application.application,
targets=[experiment3],
)
ran_analyses, skipped_analyses, invalid_analyses = application.run(
[([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=False
)

captured = capsys.readouterr()
assert "STAGED 1 | SKIPPED 2 | INVALID 0\n" in captured.out
assert "Add --commit to run 2 analyses:\n" in captured.out
assert "1 STAGED" in captured.out
assert "1 SUCCEEDED (Unprotected)\n" in captured.out
assert "1 FAILED will be skipped" in captured.out

ran_analyses, skipped_analyses, invalid_analyses = application.run(
[([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=True
)
captured = capsys.readouterr()
assert "RAN 2 | SKIPPED 1 | INVALID 0" in captured.out

# testing description on commit = False and application_protect_results = True
experiment1 = api.create_instance("experiments", **factories.ExperimentFactory())
experiment2 = api.create_instance("experiments", **factories.ExperimentFactory())
experiment3 = api.create_instance("experiments", **factories.ExperimentFactory())

application = MockApplication()
application.application_protect_results = True
analysis = api.create_instance(
"analyses",
storage_url=tmpdir.strpath,
status="FAILED",
ran_by=user.username,
application=application.application,
targets=[experiment2],
)

analysis = api.create_instance(
"analyses",
storage_url=tmpdir.strpath,
status="SUCCEEDED",
ran_by=user.username,
application=application.application,
targets=[experiment3],
)
ran_analyses, skipped_analyses, invalid_analyses = application.run(
[([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=False
)

captured = capsys.readouterr()
assert "STAGED 1 | SKIPPED 2 | INVALID 0\n" in captured.out
assert "Add --commit to run 1 analysis:\n" in captured.out
assert "1 STAGED\n\n" in captured.out
assert "1 FAILED will be skipped" in captured.out
assert "1 SUCCEEDED (Protected) will be skipped" in captured.out

ran_analyses, skipped_analyses, invalid_analyses = application.run(
[([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=True
)
captured = capsys.readouterr()
assert "RAN 1 | SKIPPED 2 | INVALID 0" in captured.out