Skip to content

Commit 434e8bc

Browse files
committed
cli:ppg2-filter-constraint-violations
1 parent 3fc485a commit 434e8bc

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
6767
[tool.pytest.ini_options]
6868
pythonpath = "python"
6969
addopts="--ignore=dev_utils"
70+
71+
72+
[project.scripts]
73+
ppg2-filter-constraint-violations = "pypipegraph2.cli:filter_constraint_violations"

python/pypipegraph2/cli.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""CLI interface to ppg2"""
2+
3+
import pyzstd
4+
import re
5+
import sys
6+
import pypipegraph2 as ppg2
7+
8+
9+
def filter_constraint_violations(filename=None, pipegraph=None):
10+
"""For when you really need to remove some jobs from the pipegraph's history.
11+
Takes a filename with job ids.
12+
Defaults to .ppg/errors/latest/constraint_violations.jobs
13+
14+
If you have your ppg history in a non standard place, pass in a ppg
15+
with the correct directories set.
16+
"""
17+
if '--help' in sys.argv:
18+
print("ppg2-cli filter_constraint_violations [filename] - filter constraint violations from history")
19+
if pipegraph is None:
20+
pipegraph = ppg2.new()
21+
22+
if sys.argv[1:]:
23+
filename = sys.argv[1]
24+
if filename is None:
25+
filename = pipegraph.dir_config.error_dir / "latest/constraint_violations.jobs"
26+
27+
q = filename.read_text().strip().split("\n")
28+
print("reading history")
29+
history = pipegraph._load_history()
30+
31+
to_del = set()
32+
for key, v in history.items():
33+
found = False
34+
for x in q:
35+
if key.startswith(x) or key.endswith(x):
36+
print("Would delete")
37+
print("\thistory: ", key)
38+
print("\tbecause: ", x)
39+
print("")
40+
to_del.add(key)
41+
found = True
42+
if found:
43+
break
44+
print(f"Delete {len(to_del)} history entries?")
45+
print("type yes<enter> to proceed")
46+
print("This tool does not create backups. Make a snapshot of your project first")
47+
for x in to_del:
48+
del history[x]
49+
if input() == "yes":
50+
ppg2.global_pipegraph._save_history(history)
51+
else:
52+
print("aborted")

python/pypipegraph2/runner.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def _executing_thread(self):
752752
# enable_logging_to_file("rust_debug.log")
753753

754754
self.evaluator.debug_is_finished()
755-
Path("debug.txt").write_text(
755+
Path("ppg_evaluator_debug.txt").write_text(
756756
self.evaluator.debug()
757757
)
758758
# self.evaluator.reconsider_all_jobs() # if this helps' we're looking at a propagation failure. Somewhere.
@@ -781,9 +781,7 @@ def _executing_thread(self):
781781
job.waiting = True
782782
job.actual_cores_needed = -1
783783
self._interactive_report()
784-
job.start_time = (
785-
time.time()
786-
) # assign it just in case anything fails before acquiring the lock
784+
job.start_time = time.time() # assign it just in case anything fails before acquiring the lock
787785
job.stop_time = float("nan")
788786
job.run_time = float("nan")
789787

@@ -876,9 +874,7 @@ def _executing_thread(self):
876874
outputs = None
877875
raise error
878876

879-
except (
880-
SystemExit
881-
) as e: # pragma: no cover - happens in spawned process, and we don't get coverage logging for it thanks to os._exit
877+
except SystemExit as e: # pragma: no cover - happens in spawned process, and we don't get coverage logging for it thanks to os._exit
882878
log_trace(
883879
"SystemExit in spawned process -> converting to hard exit"
884880
)
@@ -953,6 +949,18 @@ def _executing_thread(self):
953949
log_error(
954950
f"Recording job success failed for {job_id}. Likely constraint violation?: Message was '{e}'"
955951
)
952+
with self.evaluator_lock: # just so we don't mess up the file.
953+
log_filename = (
954+
self.job_graph.dir_config.error_dir
955+
/ self.job_graph.time_str
956+
/ "constraint_violations.jobs"
957+
)
958+
log_error(
959+
f"Job id has been logged to {log_filename}\n. You might want to use ppg-filter-constraint-violations after fixing the problem."
960+
)
961+
with open(log_filename, "a") as op:
962+
op.write(f"{job_id}\n")
963+
956964
self.job_outcomes[job_id] = RecordedJobOutcome(
957965
job_id, JobOutcome.Failed, str(e)
958966
)

0 commit comments

Comments
 (0)