Julia Documenter: missing docstring

后端 未结 1 2040
礼貌的吻别
礼貌的吻别 2021-01-06 04:06

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.

相关标签:
1条回答
  • 2021-01-06 05:03

    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.

    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
    

    The file src/my_module.jl is:

    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
    

    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
    

    The file docs/make.jl is:

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

    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]
    ```
    

    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
    

    The file README.md contains a description in Markdown:

    # my_module and its description
    

    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.
    

    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.

    0 讨论(0)
提交回复
热议问题