使用 cron 在虚拟环境中制作 Sphinx 文档

Making Sphinx documentation inside of a virtual environment with cron

我有一个应用程序开发服务器,它每晚自动更新一个庞大的 shell 脚本,我们 运行 使用 crontab。该脚本在文件顶部指定了 #!/bin/sh,我无法更改它。该脚本的基本目的是遍历机器并在我们在脚本中列出的每个目录中下载最新代码。更新所有存储库后,我们通过直接调用 virtualenv 的 python,使用适当的虚拟环境(Django manage.py 命令)执行一些脚本来更新相关数据库。

我遇到的问题是我们在其中一个虚拟环境中安装了所有必要的 Sphinx 插件,以允许我们从脚本末尾的代码构建文档,但我似乎无法理解了解如何允许 make 命令在 virtualenv 内部 运行 以便它可以访问正确的包和库。我需要一种方法来 运行 虚拟环境中的 make 命令,并在必要时停用该环境,以便脚本的其余部分可以 运行.

我当前的脚本如下所示,并在后 3 行给出错误,因为 sh 没有 workon 或 deactivate,并且因为 make 找不到 sphinx-build。

cd ${_proj_root}/dev/docs
workon dev
make clean && make html
deactivate

我找到了这个问题的答案here。当您尝试从根目录构建 sphinx 文档时显示的错误消息如下,并导致那里提供的答案:

Makefile:12: *** The 'sphinx-build' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the 'sphinx-build' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/. Stop.

下面列出了当所有工具都安装在各种虚拟环境中时希望通过 cron 构建 sphinx 文档的任何人的完整命令。您可以在环境激活时使用 which 找到 python 和 sphinx-build 命令的位置。

make html SPHINXBUILD='<virtualenv-path-to>/python <virtualenv-path-to>/sphinx-build'