Skip to content

Copying docstrings with @doc macro in packages doesn't work on master #52141

Closed
@jmert

Description

@jmert

Accessing the documentation attached to a binding with @doc name seems to return nothing inside a package, so doing something like copying a docstring from one binding to another no longer works.

For example, with a new package:

$ julia -e 'using Pkg; Pkg.generate("CopyDocs")'
  Generating  project CopyDocs:
    CopyDocs/Project.toml
    CopyDocs/src/CopyDocs.jl
$ cd CopyDocs

and writing the module

$ cat - > src/CopyDocs.jl <<EOF
module CopyDocs
export A, B
"My docstring" function A end
@doc (@doc A) function B end
end
EOF

The docstring for B exists on Julia 1.10 and prior ...

$ julia +1.10 --quiet --project
julia> VERSION
v"1.10.0-rc1"

julia> using CopyDocs

help?> A
search: A as Any any all abs ARGS ans axes atan asin asec any! all! acsc acot acos abs2 Array atanh atand asinh asind asech asecd

  My docstring

help?> B
search: B Bool big Base bind break begin bswap BitSet BigInt BitArray BigFloat binomial basename Broadcast BitVector BitMatrix

  My docstring

but appears to be nothing on master:

$ julia-dev --quiet --project
julia> VERSION
v"1.11.0-DEV.890"

julia> using CopyDocs

help?> A
search: A

  My docstring

help?> B
search: B

After some digging through the Docs code, I've found the pair of PRs #48594 and #51399 that effect Base.Docs.docm(). The former was merged before 1.10 was branched, so that doesn't appear to be the cause — therefore I'm guessing the movement of REPL out of the system image impacted this, though I haven't bisected to be sure.

Using the guess that @doc needs REPL to function, I tried adding it to the package dependencies and loading inside the package, and it does appear to fix the problem with the docstring not copying:

$ sed -i '1 a using REPL' src/CopyDocs.jl
$ julia-dev --project -e 'using Pkg; Pkg.add("REPL")'
...

and then

$ julia-dev --quiet --project
julia> VERSION
v"1.11.0-DEV.890"

julia> using CopyDocs

help?> B
search: B

  My docstring

Of course, I'd rather not have to add a dependency on the REPL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions