MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / run_if

Function run_if

pipcl.py:2726–2956  ·  view source on GitHub ↗

Runs a command only if the output file is not up to date. Args: command: The command to run. We write this and a hash of argv[0] into a file .cmd so that we know to run a command if the command itself has changed. out: Pa

( command, out, *prerequisites, caller=1)

Source from the content-addressed store, hash-verified

2724
2725
2726def run_if( command, out, *prerequisites, caller=1):
2727 '''
2728 Runs a command only if the output file is not up to date.
2729
2730 Args:
2731 command:
2732 The command to run. We write this and a hash of argv[0] into a file
2733 <out>.cmd so that we know to run a command if the command itself
2734 has changed.
2735 out:
2736 Path of the output file.
2737
2738 prerequisites:
2739 List of prerequisite paths or true/false/None items. If an item
2740 is None it is ignored, otherwise if an item is not a string we
2741 immediately return it cast to a bool. We recurse into directories,
2742 effectively using the newest file in the directory.
2743
2744 Returns:
2745 True if we ran the command, otherwise None.
2746
2747
2748 If the output file does not exist, the command is run:
2749
2750 >>> verbose(1)
2751 1
2752 >>> log_line_numbers(0)
2753 >>> out = 'run_if_test_out'
2754 >>> if os.path.exists( out):
2755 ... os.remove( out)
2756 >>> if os.path.exists( f'{out}.cmd'):
2757 ... os.remove( f'{out}.cmd')
2758 >>> run_if( f'touch {out}', out, caller=0)
2759 pipcl.py:run_if(): Running command because: File does not exist: 'run_if_test_out'
2760 pipcl.py:run_if(): Running: touch run_if_test_out
2761 True
2762
2763 If we repeat, the output file will be up to date so the command is not run:
2764
2765 >>> run_if( f'touch {out}', out, caller=0)
2766 pipcl.py:run_if(): Not running command because up to date: 'run_if_test_out'
2767
2768 If we change the command, the command is run:
2769
2770 >>> run_if( f'touch {out};', out, caller=0)
2771 pipcl.py:run_if(): Running command because: Command has changed:
2772 pipcl.py:run_if(): @@ -1,2 +1,2 @@
2773 pipcl.py:run_if(): touch
2774 pipcl.py:run_if(): -run_if_test_out
2775 pipcl.py:run_if(): +run_if_test_out;
2776 pipcl.py:run_if():
2777 pipcl.py:run_if(): Running: touch run_if_test_out;
2778 True
2779
2780 If we add a prerequisite that is newer than the output, the command is run:
2781
2782 >>> time.sleep(1)
2783 >>> prerequisite = 'run_if_test_prerequisite'

Callers 1

build_extensionFunction · 0.85

Calls 9

fs_find_in_pathsFunction · 0.85
hash_getFunction · 0.85
_fs_mtimeFunction · 0.85
_make_prerequisitesFunction · 0.85
log2Function · 0.85
_fs_mtime_newestFunction · 0.85
log1Function · 0.85
removeMethod · 0.80
runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…