问题描述
我在 python 环境中需要这个。示例 here on my Github
我有一个文件 requirements.in
,我想看看它是否有变化。我向其中添加了库,保存后将运行编译和安装脚本。
我使用 pip-compile
将需求编译成 requirements.text
文件。然后使用 pip 安装此需求文件中的所有内容。理想情况下,我想创建一个还运行 jupyter notebook 的捆绑脚本。
目前我使用了 python 库“when-changed”并采用了这种方法:
#!/bin/bash
jupyter notebook &
when-changed requirements_dev.in pip-compile requirements_dev.in && requirements_dev.in pip install -r requirements_dev.txt && echo 'Installed requirements'
这种方法的问题在于它只编译需求而不安装它或执行echo语句。我猜这是因为 when-changed
库只能执行一个命令。
因此我的问题是:如何查看文件并执行多个命令? (不一定是 bash 脚本。也可以是 python 或任何最适合的)
解决方法
我想出的一种解决方法是在单独的终端窗口中启动 jupyter notebook,在另一个终端窗口中启动 watcher。启动脚本如下所示:
#!/bin/bash
pip-compile requirements_dev.in && pip install -r requirements_dev.txt && echo 'Installed requirements'
我只是跑
when-changed requirements_dev.in bash startup.sh
在自己的窗口中。
不过,我对其他解决方案持开放态度和好奇心。