在Docker容器中通过诗歌运行sphinx-build时,Tox引发错误

问题描述

我正在尝试使用Poetry and Tox为项目生成Sphinx文档。我有这个配置:

# tox.ini
[tox]
envlist = py36
isolated_build = True

[tox:.package]
basepython = python3

[testenv]
whitelist_externals = poetry
commands =
    poetry install -v
    poetry run pytest tests/

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
whitelist_externals = poetry
commands = poetry run sphinx-build -d "{toxworkdir}/docs_doctree" documentation/source "{toxworkdir}/docs_out" --color -bhtml {posargs}
           python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'
# pyproject.toml
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "my-project"
version = "0.0.1"
description = "My project"

[tool.poetry.dependencies]
python = "^3.6"
apache-beam = {extras = ["gcp"],version = "^2.24.0"}
click = "^7.1"
click-log = "^0.3"

[tool.poetry.dev-dependencies]
pytest = "^6.1"
black = "20.8b1"
sphinx = "^3.2.1"
sphinx-autoapi = "^1.5"

在本地,我可以运行以下命令行来生成文档,它们都可以工作:

  • cd documentation; make html
  • tox -e docs

但是对于Bamboo中的CI,我选择在Docker容器(安装了Poetry和Tox的FROM python:3.6)中运行,以避免代理上安装的其他软件包出现问题,然后tox -e docs引发错误:

 docs run-test: commands[0] | poetry run sphinx-build -d /app/.tox/docs_doctree documentation/source /app/.tox/docs_out --color -bhtml

  FileNotFoundError

  [Errno 2] No such file or directory
 
   at /usr/local/lib/python3.6/os.py:594 in _execvpe
        590│         path_list = map(fsencode,path_list)
        591│     for dir in path_list:
        592│         fullname = path.join(dir,file)
        593│         try:
     →  594│             exec_func(fullname,*argrest)
        595│         except OSError as e:
        596│             last_exc = e
        597│             tb = sys.exc_info()[2]
        598│             if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
 ERROR: InvocationError for command /usr/local/bin/poetry run sphinx-build -d .tox/docs_doctree documentation/source .tox/docs_out --color -bhtml (exited > with code 1)

如果我运行docker exec以在容器中获取交互式外壳程序并运行/usr/local/bin/poetry run sphinx-build -d .tox/docs_doctree documentation/source .tox/docs_out --color -bhtml,则会生成文档。

我找不到此错误的原因。我通过将sphinx依赖关系直接放入Tox配置中找到了解决方法,但是现在我在两个文件中都具有依赖关系,并且我想了解发生了什么:

deps =
    sphinx == 3.2.1
    sphinx-autoapi == 1.5.1
commands = poetry run sphinx-build -d "{toxworkdir}/docs_doctree" documentation/source "{toxworkdir}/docs_out" --color -bhtml {posargs}
           python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'

解决方法

快速浏览一下,我会说:

commands中的[testenv:docs]设置将覆盖[testenv]中的设置。因此,我想假设poetry install -v已经在docs测试环境中运行了,但是还没有。无论如何,sphinx测试环境中未安装docs(和其他依赖项)。

您可能想在poetry install的{​​{1}}设置的顶部添加commands的某些变体。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...