Tox在Docker容器中通过Poetry运行狮身人面像构建时抛出错误



我正在尝试使用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容器中运行(安装了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以在容器中获得交互式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"))'

快速查看,我会说:

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

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

相关内容

  • 没有找到相关文章

最新更新