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

Generate # Extended help with all component descriptions #47

Merged
merged 9 commits into from
Jul 1, 2024

Conversation

MilesCranmer
Copy link
Contributor

This adds an automatically-generated # Extended help section with all component descriptions.

This won't appear in the normal docs for ?, only for ?? which is the extended help, as described in #46.

Using my package's NodeInterface as an example, here is the before:

(Expand)
'''
    NodeInterface
'''

An Interfaces.jl `Interface` with mandatory components `(:create_node, :copy, :hash, :any, :equality, :preserve_sharing, :constructorof, :eltype, :with_type_parameters, :default_allocator, :set_node!, :count_nodes, :tree_mapreduce)` and optional components `(:leaf_copy, :leaf_hash, :leaf_equal, :branch_copy, :branch_hash, :branch_equal, :count_depth, :is_node_constant, :count_constants, :filter_map, :has_constants, :get_constants, :set_constants!, :index_constants, :has_operators)`.

Defines the interface for [`AbstractExpressionNode`](@ref) which can include various operations such as copying, hashing, and checking equality, as well as tree-specific operations like map-reduce and node manipulation.
And the after:
'''
    NodeInterface
'''

An Interfaces.jl `Interface` with mandatory components `(:create_node, :copy, :hash, :any, :equality, :preserve_sharing, :constructorof, :eltype, :with_type_parameters, :default_allocator, :set_node!, :count_nodes, :tree_mapreduce)` and optional components `(:leaf_copy, :leaf_hash, :leaf_equal, :branch_copy, :branch_hash, :branch_equal, :count_depth, :is_node_constant, :count_constants, :filter_map, :has_constants, :get_constants, :set_constants!, :index_constants, :has_operators)`.

Defines the interface for [`AbstractExpressionNode`](@ref) which can include various operations such as copying, hashing, and checking equality, as well as tree-specific operations like map-reduce and node manipulation.

# Extended help

## Mandatory keys:

  * `create_node`: creates a new instance of the node type
  * `copy`: returns a copy of the tree
  * `hash`: returns the hash of the tree
  * `any`: checks if any element of the tree satisfies a condition
  * `equality`: checks equality of the tree with itself and its copy
  * `preserve_sharing`: checks if the node type preserves sharing
  * `constructorof`: gets the constructor function for a node type
  * `eltype`: gets the element type of the node
  * `with_type_parameters`: applies type parameters to the node type
  * `default_allocator`: gets the default allocator for the node type
  * `set_node!`: sets the node's value
  * `count_nodes`: counts the number of nodes in the tree
  * `tree_mapreduce`: applies a function across the tree

## Optional keys:

  * `leaf_copy`: copies a leaf node
  * `leaf_hash`: computes the hash of a leaf node
  * `leaf_equal`: checks equality of two leaf nodes
  * `branch_copy`: copies a branch node
  * `branch_hash`: computes the hash of a branch node
  * `branch_equal`: checks equality of two branch nodes
  * `count_depth`: calculates the depth of the tree
  * `is_node_constant`: checks if the node is a constant
  * `count_constants`: counts the number of constants
  * `filter_map`: applies a filter and map function to the tree
  * `has_constants`: checks if the tree has constants
  * `get_constants`: gets constants from the tree, returning a tuple of: (1) a flat vector of the constants, and (2) a reference object that can be used by `set_constants!` to efficiently set them back
  * `set_constants!`: sets constants in the tree, given: (1) a flat vector of constants, (2) the tree, and (3) the reference object produced by `get_constants`
  * `index_constants`: indexes constants in the tree
  * `has_operators`: checks if the tree has operators

For multiple methods, it generates a nested list.

For example, for the GroupInterface:
'''
    GroupInterface
'''

An Interfaces.jl `Interface` with mandatory components `(:neutral_check, :multiplication_check, :inversion_check)` and optional components `()`.

A group is a set of elements with a neutral element where you can perform multiplications and inversions.

The conditions checking the interface accept an `Arguments` object with two fields named `x` and `y`. The type of the first field `x` must be the type you wish to declare as implementing `GroupInterface`.

# Extended help

## Mandatory keys:

  * `neutral_check`:

      * neutral stable
  * `multiplication_check`:

      * multiplication stable
  * `inversion_check`:

      * inversion stable
      * inversion works

Copy link
Owner

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. Let's just mark these new methods as internal

src/documentation.jl Outdated Show resolved Hide resolved
src/documentation.jl Outdated Show resolved Hide resolved
src/interface.jl Outdated Show resolved Hide resolved
src/interface.jl Outdated Show resolved Hide resolved
@rafaqz
Copy link
Owner

rafaqz commented Jun 30, 2024

Maybe run the Base interfaces.jl test manually to see what's broken. Some may not have descriptions? (and that's allowed)

@MilesCranmer
Copy link
Contributor Author

Oh yeah it looks like it's the fact that some keys don't have descriptions. I'll make a patch.

@MilesCranmer
Copy link
Contributor Author

MilesCranmer commented Jun 30, 2024

Ok it is done. I also refactored things a bit nicer and made it more robust to any future edge cases

@MilesCranmer MilesCranmer requested a review from rafaqz June 30, 2024 13:19
@MilesCranmer

This comment was marked as resolved.

@MilesCranmer
Copy link
Contributor Author

MilesCranmer commented Jun 30, 2024

Ok I fixed the docs build by just splitting out the test into a separate file and including in a line with #src

julia --project=docs/ docs/make.jl
[ Info: generating markdown page from `~/PermaDocuments/Interfaces.jl/test/basic.jl`
[ Info: writing result to `~/PermaDocuments/Interfaces.jl/docs/src/basic.md`
[ Info: generating markdown page from `~/PermaDocuments/Interfaces.jl/test/advanced.jl`
[ Info: writing result to `~/PermaDocuments/Interfaces.jl/docs/src/advanced.md`
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: ExpandTemplates: expanding markdown templates.
[ Info: CrossReferences: building cross-references.
[ Info: CheckDocument: running document checks.
[ Info: Populate: populating indices.
[ Info: RenderDocument: rendering document.
[ Info: HTMLWriter: rendering HTML pages.
[ Info: Automatic `version="0.3.0"` for inventory from ../Project.toml
┌ Warning: Documenter could not auto-detect the building environment. Skipping deployment.
└ @ Documenter ~/.julia/packages/Documenter/qoyeC/src/deployconfig.jl:76

@rafaqz rafaqz merged commit 74628a7 into rafaqz:main Jul 1, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants