Sphinx-multiversion: 下载文件不可读

huangapple go评论65阅读模式
英文:

Sphinx-multiversion: Download file not readable

问题

I have a Sphinx documentation and would like to have a multiversion Sphinx docs.

On top of that, I have a zip file which I would like to be part of the documentation, where visitors can just click and download.

I have the zip file in ./docs/source/_downloads/examples/ folder. In one of the RST file, the download link is annotated as:

:download:`here </_downloads/examples/examples.zip>`

However, I get this error when building the docs via sphinx-multiversion "docs/source" "docs/build/html" -W --keep-going -n:

C:\Users\<username>\AppData\Local\Temp\tmpei93x8y0d1e6ca1fe60c272b003f0bf7e611df99dc35d1d\docs\source\examples.rst:4: WARNING: download file not readable: C:\Users\<username>\AppData\Local\Temp\tmpei93x8y0d1e6ca1fe60c272b003f0bf7e611df99dc35d1d\docs\source\_downloads\examples\examples.zip

I am using Python 3.9.4, Sphinx 7.0.1, and sphinx-multiversion 0.2.4.

英文:

I have a Sphinx documentation and would like to have a multiversion Sphinx docs.

On top of that, I have a zip file which I would like to be part of the documentation, where visitors can just click and download.

I have the zip file in ./docs/source/_downloads/examples/ folder. In one of the RST file, the download link is annotated as:

:download:`here </_downloads/examples/examples.zip>`

However, I get this error when building the docs via sphinx-multiversion "docs/source" "docs/build/html" -W --keep-going -n:

C:\Users\<username>\AppData\Local\Temp\tmpei93x8y0d1e6ca1fe60c272b003f0bf7e611df99dc35d1d\docs\source\examples.rst:4: WARNING: download file not readable: C:\Users\<username>\AppData\Local\Temp\tmpei93x8y0d1e6ca1fe60c272b003f0bf7e611df99dc35d1d\docs\source\_downloads\examples\examples.zip

I am using Python 3.9.4, Sphinx 7.0.1 and sphinx-multiversion 0.2.4.

答案1

得分: 0

显然,sphinx-multiversion通过提交哈希存档文件,因此如果在本地进行更改但未通过git commit提交,则sphinx-multiversion构建将失败。

在sphinx-multiversion的git.py模块中:

def copy_tree(gitroot, src, dst, reference, sourcepath="."):
    with tempfile.SpooledTemporaryFile() as fp:
        cmd = (
            "git",
            "archive",
            "--format",
            "tar",
            reference.commit,
            "--",
            sourcepath,
        )
        subprocess.check_call(cmd, cwd=gitroot, stdout=fp)
        fp.seek(0)
        with tarfile.TarFile(fileobj=fp) as tarfp:
            tarfp.extractall(dst)

在sphinx-multiversion的main.py中使用:

git.copy_tree(str(gitroot), gitroot.as_uri(), repopath, gitref)

一旦我git addgit commit可下载的文件,构建就能完美无误地进行,没有错误。

英文:

Apparently sphinx-multiversion archives the files via commit hashes, hence if the changes are made locally and not committed via git commit, the sphinx-multiversion build will fail.

In sphinx-multiversion's git.py module:

def copy_tree(gitroot, src, dst, reference, sourcepath="."):
    with tempfile.SpooledTemporaryFile() as fp:
        cmd = (
            "git",
            "archive",
            "--format",
            "tar",
            reference.commit,
            "--",
            sourcepath,
        )
        subprocess.check_call(cmd, cwd=gitroot, stdout=fp)
        fp.seek(0)
        with tarfile.TarFile(fileobj=fp) as tarfp:
            tarfp.extractall(dst)

Used in sphinx-multiversion's main.py:

git.copy_tree(str(gitroot), gitroot.as_uri(), repopath, gitref)

Once I git add and git commit the downloadable file, the build works perfectly without errors.

huangapple
  • 本文由 发表于 2023年6月12日 20:14:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76456582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定