【问题标题】:Tox throws an error when running sphinx-build through Poetry in Docker containerTox 在 Docker 容器中通过 Poetry 运行 sphinx-build 时抛出错误
【发布时间】:2020-10-15 08:14:40
【问题描述】:

我正在尝试为使用 Poetry 和 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 容器中运行(从 python:3.6 安装 Poetry 和 Tox)以避免代理上安装的其他包出现问题,然后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 以在容器中获取交互式 shell 并运行 /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"))'

【问题讨论】:

    标签: python-sphinx tox python-poetry


    【解决方案1】:

    快速浏览一下,我会说:

    [testenv:docs] 中的commands 设置会覆盖[testenv] 中的设置。所以我猜假设poetry install -v 已经在docs 测试环境中运行,但它没有。无论如何sphinx(和其他依赖项)都没有安装在docs 测试环境中。

    您可能希望在[testenv:docs] 中的commands 设置顶部添加poetry install 的一些变体。

    【讨论】:

    • 你是对的,我在poetry run sphinx-build 之前添加了poetry install 并且它有效。我刚开始使用 Tox,我认为 Docker 有一些特定的东西,没有考虑依赖安装。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 2021-09-15
    • 2019-12-04
    • 1970-01-01
    • 2019-09-30
    • 2019-09-27
    • 2020-08-16
    相关资源
    最近更新 更多