朱莉娅·Documenter(Julia Documenter):缺少文档字符串 [英] Julia Documenter: missing docstring

查看:173
本文介绍了朱莉娅·Documenter(Julia Documenter):缺少文档字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有功能,文档字符串和文档测试的Julia模块文件.我加载了它,并在Julia帮助中显示了文档字符串,但是Documenter.jl找不到文档字符串.

I have a Julia module file with a function, a doc-string, and a doc-test. I load it and the doc-string shows in the Julia help, but Documenter.jl cannot find the doc-string.

一个示例模块文件src/my_module.jl是:

module my_module

"""
    add(x, y)

Dummy function

# Examples
```jldoctest
julia> add(1, 2)
3
```
"""
function add(x::Number, y::Number)
    return x + y
end

end

make文件docs/make.jl为:

using Documenter, my_module

makedocs(
    modules = [my_module],
    format = :html,
    sitename = "my_module.jl",
    authors = "unknown",
    doctest = true
)

include("src/my_module.jl"),然后是?,然后是my_module.add的输出表明,Julia REPL找到了文档字符串:

The ouptut of include("src/my_module.jl"), then ?, then my_module.add, shows that the Julia REPL found the docstring:

help?> my_module.add
  add(x, y)

  Dummy function

     Examples
    ≡≡≡≡≡≡≡≡≡≡

  julia> add(1, 2)
  3

include("docs/make.jl")的输出显示Documenter没有:

Documenter: setting up build directory.
Documenter: expanding markdown templates.
Documenter: building cross-references.
Documenter: running document checks.
 > checking for missing docstrings.
 !! 1 docstring potentially missing:

    my_module.add :: Tuple{Number,Number}

 > running doctests.
 > checking footnote links.
Documenter: populating indices.
Documenter: rendering document.

Julia REPL是怎么找到文档字符串而不是Documenter的?

How come the Julia REPL finds the docstring and not Documenter?

注意事项:在运行代码之前,我运行了Pkg.update(). Documenter的版本为0.18.0,Julia的版本为0.6.3.

Notes: I ran Pkg.update() before running the code. Documenter has version 0.18.0, Julia has version 0.6.3.

推荐答案

如@fredrikekre的评论中所述,我缺少了@autodocs和其他一些详细信息.这是使用Documenter.jlJulia中进行文档测试的完整设置.

As mentioned in the comments of @fredrikekre, I was missing @autodocs and some other details. Here is a complete setup for doc-testing in Julia with Documenter.jl.

my_module的目录结构(来自命令tree,为清楚起见已重新排序):

Directory structure of my_module (from command tree, reordered for clarity):

.
|____src
| |____my_module.jl
| |____my_functions.jl
|____docs
| |____make.jl
| |____src
| | |____index.md
|____README.md
|____REQUIRE

文件src/my_module.jl是:

module my_module

# export functions you want to call without qualifications
export add_exported

using DataFrames # or any other module

# Include functions
include("my_functions.jl")

end

文件src/my_functions.jl包含已导出和未导出的功能.请注意,导出功能的doc-test没有资格,而未导出功能的doc-test具有以下条件:

The file src/my_functions.jl contains exported and non-exported functions. Note how the doc-test of exported functions has no qualification, and the doc-test of non-exported functions does:

"""
    add_exported(x, y)

Dummy function, exported

# Examples
```jldoctest
julia> add_exported(1, 2)
3
```
"""
function add_exported(x::Number, y::Number)
    return x + y
end

"""
    add_not_exported(x, y)

Dummy function, not exported

# Examples
```jldoctest
julia> my_module.add_not_exported(1, 2)
3
```
"""
function add_not_exported(x::Number, y::Number)
    return x + y
end

文件docs/make.jl是:

using Documenter, my_module

makedocs(
    modules = [my_module],
    format = :html,
    sitename = "my_module.jl",
    doctest = true
)

文件docs/src/index.md包含using my_module,该文件将导出的函数引入作用域:

The file docs/src/index.md contains using my_module, which brings exported functions into scope:

# Documentation

```@meta
CurrentModule = my_module
DocTestSetup = quote
    using my_module
end
```

```@autodocs
Modules = [my_module]
```

最后两个文件是可选的.文件REQUIRE仅用于软件包的远程安装.它包含:

The last two files are optional. The file REQUIRE serves only for remote installation of package. It contains:

julia 0.6.3
DataFrames 0.11.6

文件README.md在Markdown中包含说明:

The file README.md contains a description in Markdown:

# my_module and its description

最后,将目录更改为软件包的根目录,启动Julia会话,然后键入:

Finally, change directory to the root of the package, start a Julia session, and type:

julia> include("src/my_module.jl");include("docs/make.jl");
Documenter: setting up build directory.
Documenter: expanding markdown templates.
Documenter: building cross-references.
Documenter: running document checks.
 > checking for missing docstrings.
 > running doctests.
 > checking footnote links.
Documenter: populating indices.
Documenter: rendering document.

如果将文档测试中的add的结果从3更改为任何其他数字,则Documenter将显示错误并表明它可以正常工作.

If you change the result of add in the doc-test from 3 to any other number, the Documenter will show an error and show that it is working.

这篇关于朱莉娅·Documenter(Julia Documenter):缺少文档字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆