Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CmdRunner

本项目是什么?

一个python3.12标准库编写的、0依赖的脚本运行框架(目前还算不上框架),支持多进程批量运行shell命令,尤其适用于需要大量和shell交互的数据分析工作流。

初衷是什么?

  • 因为生信分析常常涉及重复的批量运行 shell 脚本,奈何本人不太熟悉 shell,又不愿意去学 snakemakenf-core一类成熟的 pipeline 管理框架,所以简单的写一个mini-framework,自己开心最重要
  • 因为本人痛恨无穷无尽且臃肿的依赖,所以这个项目会全程坚持 0 依赖的作风,完全使用标准库实现

Quick Start

从头写

  1. 克隆本仓库

    git clone --depth 1 https://github.com/zdWang04/CmdRunner.git path/to/some/folder
  2. 编辑器支持(仅vscode)

    ctrl+shift+P,输入setting.json打开配置文件,将

    "python.analysis.extraPaths": ["path/to/some/folder"],

    写入到配置中

  3. 制作脚本

    # ur_script.py
    
    import sys
    sys.path.append("path/to/some/folder") # 换为克隆时指定的文件夹
    from task import create_single_task, create_parallel_tasks_from_list, create_serial_tasks_from_list
    from config import GLOBAL_CONFIG as cfg
    
    # 首先进行一些配置
    cfg.dry_run = False
    cfg.max_workers = 16
    cfg.log_path = "./zzz_log_path"
    
    # 然后制作命令和任务标签
    single_cmd = "shell_cmd0"
    single_cmd_tag = "cmd0_tag" # (可选)
    cmd_list = ["shell_cmd1", "shell_cmd2", "shell_cmd3"]
    tag_list = ["cmd1_tag", "cmd2_tag", "cmd3_tag"] # (可选)
    
    # 然后创建任务
    single_task = create_single_task(single_cmd, single_cmd_tag)
    parallel_tasks = create_parallel_tasks_from_list(cmd_list, tag_list)
    serial_tasks = create_serial_tasks_from_list(cmd_list, tag_list)
    
    # 最后跑起来,run!!!
    single_task.run()
    parallel_tasks.run() # 并行运行命令
    serial_tasks.run() # 串行运行命令
  4. 运行脚本

    python3 ./ur_script.py || python ./ur_script.py

需要注意什么?

  • 需要注意这个项目只在python3.12解释器 + ubuntu24.04 上正常运行,并没有在其他版本python和环境下进行完全测试
  • 需要注意作者可能会无期限的暂停开发,所以欢迎 fork
  • 需要注意这个狗屎仓库远远不能用于生产使用

TODO

  • 日志
  • 更干净的输出
  • 隐晦角落的 bug
  • 对 Pipeline 的支持

About

mini-framework for runing shell command/making pipeline

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages