Tox 在 运行 sphinx-build through Poetry in Docker container 时抛出错误
Tox throws an error when running sphinx-build through Poetry in Docker container
我正在尝试为使用 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"))'
快速浏览一下,我会说:
[testenv:docs]
中的 commands
设置覆盖了 [testenv]
中的设置。所以我想假设 poetry install -v
在 docs
测试环境中已经是 运行 但事实并非如此。无论如何sphinx
(和其他依赖项)都没有安装在docs
测试环境中。
您可能想在 [testenv:docs]
中 commands
设置的顶部添加一些 poetry install
的变体。
我正在尝试为使用 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"))'
快速浏览一下,我会说:
[testenv:docs]
中的 commands
设置覆盖了 [testenv]
中的设置。所以我想假设 poetry install -v
在 docs
测试环境中已经是 运行 但事实并非如此。无论如何sphinx
(和其他依赖项)都没有安装在docs
测试环境中。
您可能想在 [testenv:docs]
中 commands
设置的顶部添加一些 poetry install
的变体。