Created
March 1, 2021 10:26
-
-
Save JohannesBuchner/0c0cb734536193dfac52be04306e8b66 to your computer and use it in GitHub Desktop.
Cache/Memoize any command line program. Keeps stdout, stderr and exit code, env aware.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
import joblib | |
import subprocess | |
mem = joblib.Memory('.', verbose=False) | |
@mem.cache | |
def run_cmd(args, env): | |
process = subprocess.run(args, capture_output=True, text=True) | |
return process.stdout, process.stderr, process.returncode | |
stdout, stderr, returncode = run_cmd(sys.argv[1:], dict(os.environ)) | |
sys.stdout.write(stdout) | |
sys.stdout.write(stderr) | |
sys.exit(returncode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outdated by https://pypi.org/project/cmdstancache/