Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce strict docs compilation and add Documentation best practices guidelines #419

Merged
merged 43 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1b70baa
Add explanation
kdayday Oct 18, 2024
37f2e22
Add howto compile
kdayday Oct 18, 2024
57dfa1f
Add how to view on github
kdayday Oct 18, 2024
0583c1c
Add docs troubleshoot draft
kdayday Oct 18, 2024
70850aa
Add new pages to make
kdayday Oct 18, 2024
4beb783
Add useful links
kdayday Oct 22, 2024
5a19035
Add how-to write a tutorial and draft requirements checklist
kdayday Oct 23, 2024
dcc6edc
Update explanation
kdayday Oct 23, 2024
24ffbdb
Tweak how-to tutorial
kdayday Oct 23, 2024
12002c8
Add general formatting how-to
kdayday Oct 23, 2024
e5e5b51
Fix logging link
kdayday Oct 24, 2024
ed5cda2
Format explanation
kdayday Oct 24, 2024
484a856
Add missing docstrings from Optimization and Simulation submodules an…
kdayday Oct 24, 2024
5fad70f
import to using
kdayday Nov 2, 2024
fafda01
list format
kdayday Nov 2, 2024
efc5f59
Add DocumenterInterLinks and update Project.toml
kdayday Nov 4, 2024
2e7ed27
Partial draft how to write docstrings
kdayday Nov 5, 2024
d1f98eb
Merge branch 'main' into docs_bp
kdayday Nov 5, 2024
0cbbf9c
typo
kdayday Dec 11, 2024
4bbfa9c
Fix how to cmpile logic
kdayday Dec 11, 2024
f43af58
Formatting updates
kdayday Dec 13, 2024
7459a00
Update organize apis and add example pics
kdayday Dec 13, 2024
fb96e6d
Complete how-to docstrings
kdayday Dec 13, 2024
42f16b4
Add id
kdayday Dec 13, 2024
c2905cb
Finish how-to trouble-shoot
kdayday Dec 13, 2024
e0c0da4
Add how-to write how-to
kdayday Dec 14, 2024
654cbce
Add tutorial warning
kdayday Dec 14, 2024
804305f
Wording fixes
kdayday Dec 16, 2024
9a6d42e
Update links
kdayday Dec 16, 2024
b4a54fd
Update troubleshooting
kdayday Dec 16, 2024
33e2371
Add basic formatting do
kdayday Dec 16, 2024
5ec4584
Finish requirements as how-to
kdayday Dec 16, 2024
5a26008
Format troubleshoot
kdayday Dec 16, 2024
ceaf77d
Run formatter
kdayday Dec 16, 2024
c9b8e03
Minor wording
kdayday Dec 16, 2024
7d58720
github update
kdayday Dec 16, 2024
f9a4483
Rename pre-step
kdayday Dec 17, 2024
dcb39bd
Merge pull request #418 from kdayday/docs_bp
kdayday Dec 17, 2024
2461404
Add reproducibility example
kdayday Dec 20, 2024
a8e4bba
Clarify toml file
kdayday Dec 20, 2024
037d0e0
Fix formatter issues
kdayday Dec 20, 2024
ce1f976
Run formatter
kdayday Dec 20, 2024
f813192
Merge pull request #420 from kdayday/docs_bp
kdayday Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"

[compat]
InfrastructureSystems = "2"
Documenter = "1"
22 changes: 21 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using Documenter, InfrastructureSystems
import DataStructures: OrderedDict
using Literate
using DocumenterInterLinks

links = InterLinks(
"Documenter" => "https://documenter.juliadocs.org/stable/",
"Julia" => "https://docs.julialang.org/en/v1/",
"JuliaFormatter" => "https://domluna.github.io/JuliaFormatter.jl/stable/",
)

if haskey(ENV, "GITHUB_ACTIONS")
ENV["JULIA_DEBUG"] = "Documenter"
Expand All @@ -17,6 +24,19 @@ pages = OrderedDict(
"dev_guide/logging.md",
],
"Style Guide" => "style.md",
"Documentation Best Practices" => Any[
"Explanation" => "docs_best_practices/explanation.md",
"How to..." => Any[
"Complete Basic Requirements Checklist" => "docs_best_practices/how-to/requirements_checklist.md",
"Clean Up General Formatting" => "docs_best_practices/how-to/general_formatting.md",
"Write a Tutorial" => "docs_best_practices/how-to/write_a_tutorial.md",
"Write a How-To Guide" => "docs_best_practices/how-to/write_a_how-to.md",
"Organize APIs and Write Docstrings" => "docs_best_practices/how-to/write_docstrings_org_api.md",
"Troubleshoot Common Errors" => "docs_best_practices/how-to/troubleshoot.md",
"Compile and View Documentation Locally" => "docs_best_practices/how-to/compile.md",
"View Draft Documentation on Github" => "docs_best_practices/how-to/view_github.md",],
"Reference" => Any["docs_best_practices/reference/useful_links.md",],
],
"API" => "InfrastructureSystems.md"
)

Expand Down Expand Up @@ -51,7 +71,7 @@ makedocs(
size_threshold = nothing),
sitename = "InfrastructureSystems.jl",
pages = Any[p for p in pages],
warnonly = Documenter.except(),
plugins = [links],
)


Expand Down
4 changes: 3 additions & 1 deletion docs/src/InfrastructureSystems.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# [InfrastructureSystems API Reference](@id API_ref)

```@autodocs
Modules = [InfrastructureSystems]
Modules = [InfrastructureSystems,
InfrastructureSystems.Simulation,
InfrastructureSystems.Optimization]
```
Binary file added docs/src/assets/comp_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/assets/comp_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/src/dev_guide/logging.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Logging
# [Logging](@id log)

`InfrastructureSystems.jl` provides a `MultiLogger` object that allows customized
logging to console and file. Refer to the [logging
Expand Down
44 changes: 44 additions & 0 deletions docs/src/docs_best_practices/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Explanation

## History and Motivation

During the first phase of Sienna's (previously SIIP's) development, Sienna used a 3-part
documentation organization, based on the expected needs of different user personas:

- **Modeler**: Users that want to use existing functionality
- **Model Developer**: Users that want to develop custom structs, components, models, and/or workflows
- **Code Base Developers**: Users that want to add new core functionalities or fix bugs in the core capabilities

However, as Sienna's user base has expanded, it has become apparent that this previous
organization is no longer serving. As of 2024, a new effort is underway to clean up and
re-organize the Sienna documentation according to the 4-part [Diataxis](https://diataxis.fr/)
framework, a well-established, systematic approach to technical documentation split up into:

- [Tutorials](https://diataxis.fr/tutorials/)
- [How-to guides](https://diataxis.fr/how-to-guides/)
- [Reference](https://diataxis.fr/reference/)
- [Explanation](https://diataxis.fr/explanation/)

In addition, the current documentation has multiple quality issues, including misformatted
text, broken reference links, and documentation that has been written but is not visible to
users in the API ("missing docstrings"). While the [style guide](@ref style_guide)
has been available, the guide focuses primarily on the style of code itself, without
providing clear guidelines and best practices for other parts of the documentation besides
docstrings. In addition, the first stage of Sienna's development coincided with the initial
development of the [`Documenter.jl`](https://documenter.juliadocs.org/stable/) package.
Early versions of Sienna's packages were documented requiring `Documenter.jl` v0.27, and in
the meantime, `Documenter.jl` has released its v1.0 and onwards, which contain much
more rigorous checks for documentation quality. Sienna's packages have not kept up with
these improvements.

## Purpose of the Documentation Best Practices

We aim to remedy the historical issues above through a concerted clean up and
re-organization effort and compliance with `Documenter.jl` >v1.0's quality control checks,
following these best practice guidelines. These guidelines are not intended to reiterate
[Diataxis](https://diataxis.fr/), beyond regularly reminding contributers to refer to them
-- and contributers should read the [Diataxis](https://diataxis.fr/) website in its entirety
before getting started. Instead, the best practices are intended to bridge the gap where
there are Julia- or Sienna-specific recommendations, either to consistently implement the
Diataxis framework or to highlight common documentation issues throughout the Sienna
packages that need to be addressed as part of our concerted clean-up effort.
70 changes: 70 additions & 0 deletions docs/src/docs_best_practices/how-to/compile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Compile and View Documentation Locally

## Pre-Step a: Update Docs Environment (First Time)

The first time you compile documentation for a package, make sure the `docs/` environment
(i.e., `docs/Manifest.toml`, not the main `Manifest.toml` in the root of the repository)
is pointing to your local version of the package, so it compiles your local changes:

```
julia --project=docs
using Pkg
Pkg.develop(path = "..")
```

## Pre-Step b: Auto-Generate Structs (If Needed)

Most documentation changes are made directly to markdown (.md) files, but if you changed one
of Sienna's .json descriptor files, you must first
[follow the instructions here](@ref "Auto-Generation of Component Structs") to auto-generate
the structs from the .json to have your changes propagated into the markdown files used for
documentation.

**Example**: You updated `PowerSystems.jl`'
[`power_system_structs.json`](https://github.com/NREL-Sienna/PowerSystems.jl/blob/main/src/descriptors/power_system_structs.json)
file.

From a terminal at the root of the repository (i.e., `PowerSystems.jl`), run:

```
julia --project=.
using InfrastructureSystems
InfrastructureSystems.generate_structs(
"./src/descriptors/power_system_structs.json",
"./src/models/generated",
)
```

## Pre-Step c: Run the Formatter (Before Submitting a Pull Request)

To automatically format the documentation to conform with the [style guide](@ref style_guide),
run in a terminal at the root of the repository:

```
julia scripts/formatter/formatter_code.jl
```

Resolve any errors and re-run until error-free. See how to [Troubleshoot Common Errors](@ref)
for help.

This is not a necessary step to compile, but needs to be done at least once to pass pull
request checks.

## Step 1: Compile

To compile, run in a terminal at the root of the repository:

```
julia --project=docs docs/make.jl
```

Resolve any errors and re-run until error-free. See how to [Troubleshoot Common Errors](@ref)
for help.

## Step 2: View

Click on the newly-created `index.html` file (e.g.,
`SomeSiennaPackage/docs/build/index.html`) to view your locally compiled documentation in a
browser.

Visually verify formatting and that code blocks compile as expected.
84 changes: 84 additions & 0 deletions docs/src/docs_best_practices/how-to/general_formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Clean Up General Formatting

These recommendations are to make navigating our documentation effortless for users, while
addressing common markdown formatting issues in the existing Sienna documentation:

## Format in back-ticks

All package names, types, functions, methods, and parameters, etc. should formatted in
back-ticks:

!!! tip "Do"

```
`max_active_power`
```

compiles as `max_active_power`

!!! warning "Don't"

```
max_active_power
```

compiles as max_active_power

## [Put hyperlinks everywhere](@id hyperlinks)

All types, function, and methods should have hyperlinks to the correct docstring, accounting
for multiple methods of the same name due to Julia's multiple dispatch.
[`Documenter.jl`](https://documenter.juliadocs.org/stable/) will link to the first
occurrance in documentation. If that's not the one you're referring to, copy the entire
signature with types into the hyperlink reference.

!!! tip "Do"

```
[`get_time_series_values`](@ref)
```

Or

```
[`get_time_series_values` from a `ForecastCache`](@ref get_time_series_values(
owner::TimeSeriesOwners,
forecast::Forecast,
start_time::Dates.DateTime;
len::Union{Nothing, Int} = nothing,
ignore_scaling_factors = false,
))
```

!!! warning "Don't"


``get_time_series_values``
Or
`get_time_series_values`

## Add links to other Sienna packages

All other Sienna package names should have documentation (not Git repo) hyperlinks:

!!! tip "Do"

```[`PowerSystems.jl`](https://nrel-sienna.github.io/PowerSystems.jl/stable/)```

!!! warning "Don't"

```
`PowerSystems.jl`
```

Or

```
PSY
```

Or

```
[`PowerSystems.jl`](https://github.com/NREL-Sienna/PowerSystems.jl)
```
38 changes: 38 additions & 0 deletions docs/src/docs_best_practices/how-to/requirements_checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Complete Basic Requirements Checklist

Sienna packages should follow the [Diataxis](https://diataxis.fr/)
framework, be strictly compiled with [`Documenter.jl`](https://documenter.juliadocs.org/stable/)
v1.0 or greater, and be automatically formatted with
[`JuliaFormatter.jl`](https://domluna.github.io/JuliaFormatter.jl/stable/).

## For New Packages

The [`SiennaTemplate.jl`](https://github.com/NREL-Sienna/SiennaTemplate.jl) Git repo has the
required environments and formatting and documentation code. Start from this template.

## For Existing Packages

Existing Sienna packages will need to be updated with these requirements, but these will
only need to be addressed once:

1. Organize the top-level documentation to follow the [Diataxis](https://diataxis.fr/)
framework (plus a welcome page/section). This might be a significant undertaking. See:

+ How to [Write a How-to Guide](@ref)
+ How to [Write a Tutorial](@ref)
+ How to [Organize APIs and Write Docstrings](@ref)

2. Replace `compat` requirements of `Documenter = "0.27"` in `docs/` environment with
kdayday marked this conversation as resolved.
Show resolved Hide resolved
`Documenter = "1.0"`
3. Update the `docs/make.jl` file to call
[`Documenter.makedocs`](https://documenter.juliadocs.org/stable/lib/public/#Documenter.makedocs)
*without* the `warnonly` `kwarg` (i.e., all errors caught by `makedocs` must be resolved before
merging). [See an example here](https://github.com/NREL-Sienna/InfrastructureSystems.jl/blob/768438a40c46767560891ec493cf87ed232a2b2b/docs/make.jl#L47).

+ See How-to [Troubleshoot Common Errors](@ref) if this results in a host of errors.
4. Update the `scripts/formatter/formatter_code.jl` to format the markdown .md files in the
`docs/` folder, calling `format`() with the `kwarg` `format_markdown = true`. See
[these](https://github.com/NREL-Sienna/InfrastructureSystems.jl/blob/768438a40c46767560891ec493cf87ed232a2b2b/scripts/formatter/formatter_code.jl#L13)
[three](https://github.com/NREL-Sienna/InfrastructureSystems.jl/blob/768438a40c46767560891ec493cf87ed232a2b2b/scripts/formatter/formatter_code.jl#L8)
[links](https://github.com/NREL-Sienna/InfrastructureSystems.jl/blob/768438a40c46767560891ec493cf87ed232a2b2b/scripts/formatter/formatter_code.jl#L23)
for examples of the updated lines.
Loading
Loading