Spaces:
Running
Running
Download scripts/smk_list.py from angerami/transformer-weights: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/angerami/transformer-weights/resolve/main/scripts/smk_list.py
- Command line
-
hf download hf://spaces/angerami/transformer-weights/scripts/smk_list.py
-
curl -L -o smk_list.py https://huggingface.co/spaces/angerami/transformer-weights/resolve/main/scripts/smk_list.py
1.23 kB
| #!/usr/bin/env python3 | |
| """Colorized wrapper for `snakemake --list`. | |
| Usage: | |
| python scripts/smk_list.py | |
| python scripts/smk_list.py --list-rules # pass extra snakemake flags | |
| """ | |
| import subprocess | |
| import sys | |
| BOLD_CYAN = "\033[1;36m" | |
| DIM = "\033[2m" | |
| RESET = "\033[0m" | |
| def colorize(lines): | |
| in_desc = False | |
| for line in lines: | |
| stripped = line.rstrip("\n") | |
| if stripped and not stripped.startswith(" "): | |
| in_desc = False | |
| if " (" in stripped: | |
| name, rest = stripped.split(" (", 1) | |
| print(f"{BOLD_CYAN}{name}{RESET} {DIM}({rest}{RESET}") | |
| in_desc = not stripped.endswith(")") | |
| else: | |
| print(f"{BOLD_CYAN}{stripped}{RESET}") | |
| else: | |
| # continuation line of a multi-line description | |
| print(f"{DIM}{stripped}{RESET}") | |
| def main(): | |
| extra = sys.argv[1:] | |
| result = subprocess.run( | |
| ["snakemake", "--list"] + extra, | |
| capture_output=True, text=True, | |
| ) | |
| colorize(result.stdout.splitlines(keepends=True)) | |
| if result.returncode != 0: | |
| sys.stderr.write(result.stderr) | |
| sys.exit(result.returncode) | |
| if __name__ == "__main__": | |
| main() | |