Skip to content

Commit 7e95a28

Browse files
authored
Improve the documentation (#4)
Even though this package is pretty simple and the README covers it fairly well, packages hosted at JuliaDocs presumably should demonstrate best practices, and there is room for being more expansive in a "real" docs page. Note that the doctests fail without the trailing blank space added to docs/src/index.md. This also fixes the coverage badge.
1 parent 9941729 commit 7e95a28

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaDocs.github.io/ModuleDocstrings.jl/stable)
44
[![Build Status](https://github.com/JuliaDocs/ModuleDocstrings.jl/workflows/CI/badge.svg)](https://github.com/JuliaDocs/ModuleDocstrings.jl/actions)
5-
[![Coverage](https://codecov.io/gh/JuliaDocs/ModuleDocstrings.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaDocs/ModuleDocstrings.jl)
5+
[![Coverage](https://codecov.io/gh/JuliaDocs/ModuleDocstrings.jl/branch/main/graph/badge.svg?token=5Wdh1eXbGc)](https://codecov.io/gh/JuliaDocs/ModuleDocstrings.jl)
66

77
A package to create simple "module docstrings" for Julia packages. These are targeted at summarizing the main components of your package, essentially as a prompt or reminder to users. For example:
88

@@ -18,16 +18,23 @@ search: ModuleDocstrings
1818
• ModuleDocstrings.write: add an API summary docstring to a package.
1919
```
2020

21-
Then, to learn more about `generate`:
21+
This reminds users that the two main functions are `ModuleDocstrings.generate` and `ModuleDocstrings.write`.
22+
23+
These summaries are brief; to learn more about a particular function, read its help in full:
2224

2325
```julia
2426
help?> ModuleDocstrings.generate
2527
ModuleDocstrings.generate(mod::Module)
2628

2729
Return an API summary string for mod.
2830

29-
The summary is assembled from all docstrings in the package, picking the
30-
first sentence of each docstring. Expect to need to edit these by hand to
31-
produce something truly useful.
31+
The summary is assembled from all docstrings in the package, picking the first sentence of each docstring. When added to the
32+
package (see ModuleDocstrings.write), you should expect to make edits by hand:
33+
34+
• exclude docstrings that shouldn't appear in the API summary
3235

36+
• rephrase summaries for greater clarity or compactness (alternatively, consider making such changes to the original
37+
docstring)
3338
```
39+
40+
Once you've added the docstring to a `Pkg.develop`ed package, it can be submitted as a pull request.

docs/src/index.md

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,91 @@ CurrentModule = ModuleDocstrings
44

55
# ModuleDocstrings
66

7-
Documentation for [ModuleDocstrings](https://github.com/JuliaDocs/ModuleDocstrings.jl).
7+
This package aims to make it easier to attach a docstring to a module, providing users with a quick summary of the core functionality in a package.
8+
9+
To demonstrate, let's create a module with a few docstrings. This module has two functions: `radius` with a single method,
10+
and `distance` with two methods (the details of the methods don't really matter much for this demonstration):
811

9-
```@index
12+
```jldoctest example
13+
julia> module TestDocStrings
14+
15+
export radius, distance
16+
17+
"""
18+
radius(x, y, z)
19+
20+
Compute the radius of the cartesian-coordinate position `[x, y, z]`.
21+
22+
There really isn't much more to say; it's pretty straightforward.
23+
"""
24+
radius(x, y, z) = sqrt(x^2 + y^2 + z^2)
25+
26+
27+
"""
28+
distance(pos1::AbstractVector, pos2::AbstractVector)
29+
30+
Compute the distance between points `pos1` and `pos2`.
31+
"""
32+
distance(pos1::AbstractVector, pos2::AbstractVector) = radius((pos1 - pos2)...)
33+
34+
"""
35+
distance(pos::AbstractVector, points::PointCollection)
36+
37+
Compute the minimum distance between `pos` and any point in `points`.
38+
"""
39+
distance(pos::AbstractVector, points::AbstractVector{<:AbstractVector}) = minimum(p -> distance(pos, p), points)
40+
41+
end
42+
TestDocStrings
1043
```
1144

12-
```@autodocs
13-
Modules = [ModuleDocstrings]
45+
Now let's generate a module doctring:
46+
47+
```jldoctest example
48+
julia> using ModuleDocstrings
49+
50+
julia> print(ModuleDocstrings.generate(TestDocStrings))
51+
- `distance`:
52+
+ Compute the minimum distance between `pos` and any point in `points`.
53+
+ Compute the distance between points `pos1` and `pos2`.
54+
- `radius`: Compute the radius of the cartesian-coordinate position `[x, y, z]`.
55+
```
56+
57+
From this, you can see that both methods of `distance` are listed, as well as the single method for `radius`.
58+
For each, only the first sentence is used in the summary.
59+
60+
If this were a package that you have in `Pkg.develop` mode, you could insert this string into the package with [`ModuleDocstrings.write`](@ref). However, in this case, you get
61+
62+
```jldoctest example; filter=(r"julia/dev/.*")
63+
julia> ModuleDocstrings.write(TestDocStrings)
64+
ERROR: TestDocStrings must be a writable package, but there is no corresponding file, suggesting it wasn't loaded from a package.
65+
Stacktrace:
66+
[1] error(s::String)
67+
@ Base ./error.jl:33
68+
[2] error_write(mod::Module, #unused#::Nothing)
69+
@ ModuleDocstrings ~/.julia/dev/ModuleDocstrings/src/ModuleDocstrings.jl:101
70+
[3] write(mod::Module, str::String)
71+
@ ModuleDocstrings ~/.julia/dev/ModuleDocstrings/src/ModuleDocstrings.jl:79
72+
[4] write(mod::Module)
73+
@ ModuleDocstrings ~/.julia/dev/ModuleDocstrings/src/ModuleDocstrings.jl:96
74+
[5] top-level scope
75+
@ none:1
76+
```
77+
78+
This error ocurred because we defined the module at the REPL; it will likewise error if you have `Pkg.add`ed rather than `Pkg.develop`ed. But for a package checked out in `develop` mode it will modify the main package file.
79+
80+
!!! warning
81+
Be sure you've saved any work *before* running `ModuleDocstrings.write`.
82+
83+
Generally speaking, you should then edit the docstring to trim any methods that don't merit a mention in the summary, and/or to improve the clarity, brevity, or organization of the summaries. Sometimes, you may discover that you can improve the original source docstring as well.
84+
85+
Your changes can then be submitted as a pull request.
86+
87+
## API
88+
89+
Documentation for [ModuleDocstrings](https://github.com/JuliaDocs/ModuleDocstrings.jl).
90+
91+
```@docs
92+
ModuleDocstrings.generate
93+
ModuleDocstrings.write
1494
```

src/ModuleDocstrings.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ module ModuleDocstrings
1010
Return an API summary string for `mod`.
1111
1212
The summary is assembled from all docstrings in the package, picking the first sentence of each docstring.
13-
Expect to need to edit these by hand to produce something truly useful.
13+
When added to the package (see [`ModuleDocstrings.write`](@ref)), you should expect to make edits by hand:
14+
15+
- exclude docstrings that shouldn't appear in the API summary
16+
- rephrase summaries for greater clarity or compactness (alternatively, consider making such changes to the
17+
original docstring)
1418
"""
1519
function generate(mod::Module)
1620
exported = Set(names(mod))

0 commit comments

Comments
 (0)