Julia Documenter:缺少文档字符串

时间:2018-06-08 20:40:24

标签: julia

我有一个带有函数,doc字符串和doc-test的Julia模块文件。我加载它并在Julia帮助中显示doc-string,但Documenter.jl找不到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的ouptut,显示Julia REPL找到了文档字符串:

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?

Notes :我在运行代码之前运行了Pkg.update()Documenter版本为0.18.0,Julia版本为0.6.3

1 个答案:

答案 0 :(得分:0)

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

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

.
|____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具有以下条件:

"""
    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,该文件将导出的函数引入作用域:

# Documentation

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

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

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

julia 0.6.3
DataFrames 0.11.6

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

# my_module and its description

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

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将显示错误并表明其有效。