-
Notifications
You must be signed in to change notification settings - Fork 41
Examples in the docs: base PR for cleaning up notebook workflow #303
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
Changes from all commits
1b1a560
7cabf13
d2cefec
60acddb
1831892
a594008
271d3d7
ef894a4
beb4adb
00ccba9
feda9e0
e30169f
901b5d0
a1718a3
66706c0
bddbea8
c4a36f8
384ac9c
80deae7
004d45e
cd0bc2b
75db97d
8c657bc
7ac29c6
001dfc3
a60e230
b2faceb
14ad37d
715e0a5
09990f8
4f34f37
f2db1ea
c8298ec
754a8db
8641c78
407d6f0
3e452ae
262ceef
495bf19
34c97fa
87da659
e851307
b3c8aa6
6fd8175
16ba774
11119c2
f034c63
2fa2f1b
6b3238b
1ea5c6c
241cf62
df1c526
cac9e7d
f2d8dcc
d060958
2b1627b
a91edc9
1daf1c3
b262ac0
4cce78e
64d5ef7
bf47391
853b437
eff7c11
a44d48f
fa0033b
1fd657d
735b437
03a6840
7aebf83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,4 @@ | |
| /Manifest.toml | ||
| /test/Manifest.toml | ||
| coverage/ | ||
| src/update_v0.8.0 | ||
| .DS_store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| build/ | ||
| site/ | ||
| src/examples/ | ||
| src/examples/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| [deps] | ||
| Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
| KernelFunctions = "ec8451be-7e33-11e9-00cf-bbf324bd1392" | ||
| Kronecker = "2c470bb0-bcc8-11e8-3dad-c9649493f05e" | ||
| PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" | ||
|
|
||
| [compat] | ||
| Documenter = "0.27" | ||
| KernelFunctions = "0.10" | ||
| PDMats = "0.11" | ||
| Kronecker = "0.4" | ||
| julia = "1.3" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # How to build the docs locally | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to get improvements to the workflow. :) |
||
|
|
||
| If you just want to modify or add an example, you can [build just the example](../examples/README.md) without having to build the full documentation locally. | ||
|
|
||
| If you want to build the documentation, navigate to this (docs/) directory and open a Julia REPL. | ||
|
|
||
| ## Instantiation | ||
|
|
||
| First activate the documentation environment: | ||
| ```julia | ||
| julia> ] activate . | ||
| ``` | ||
| Alternatively, you can start Julia with `julia --project=.`. | ||
|
|
||
| Then install all packages: | ||
| ```julia | ||
| julia> ] instantiate | ||
| ``` | ||
| By default, this will use the development version of KernelFunctions in the parent directory. | ||
|
|
||
| ## Build | ||
|
|
||
| To build the documentation, run (after activating the documentation environment) | ||
| ```julia | ||
| julia> include("make.jl") | ||
| ``` | ||
| You can speed up the process if you do not execute the examples and comment out the | ||
| relevant sections in `docs/make.jl`. | ||
|
|
||
| The output is in the `docs/build/` directory and best viewed in a browser. | ||
| The documentation uses pretty URLs which can be a hindrance if you browse the documentation locally. | ||
| The [Documenter documentation](https://juliadocs.github.io/Documenter.jl/stable/man/guide/#Building-an-Empty-Document) suggests that | ||
|
|
||
| > You can run a local web server out of the `docs/build` directory. One way to accomplish | ||
| > this is to install the [LiveServer](https://github.com/tlienart/LiveServer.jl) Julia | ||
| > package. You can then start the server with `julia -e 'using LiveServer; serve(dir="docs/build")'`. | ||
| > Alternatively, if you have Python installed, you can start one with | ||
| > `python3 -m http.server --bind localhost` (or `python -m SimpleHTTPServer` with Python 2). | ||
|
|
||
| If you make any changes, you can run | ||
| ```julia | ||
| julia> include("make.jl") | ||
| ``` | ||
| again to rebuild the documentation. | ||
|
|
||
| # How to contribute to the docs | ||
|
|
||
| ## To add additional docs dependencies | ||
|
|
||
| To add additional dependencies, run (after activating the documentation environment) | ||
| ```julia | ||
| julia> ] add NewDependency | ||
| ``` | ||
| or, as a shell one-liner: | ||
| ```shell | ||
| julia --project=. -e 'using Pkg; Pkg.add("NewDependency")' | ||
| ``` | ||
| and commit the changes to Project.toml and Manifest.toml. | ||
|
|
||
|
|
||
| ## To add examples | ||
|
|
||
| See [../examples](../examples/README.md) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ const OUTDIR = ARGS[2] | |
| # Activate environment | ||
| using Pkg: Pkg | ||
| Pkg.activate(dirname(SCRIPTJL)) | ||
| # Note that each example's Project.toml must include Literate as a dependency | ||
| Pkg.instantiate() | ||
| using Literate: Literate | ||
|
|
||
|
|
@@ -23,14 +24,13 @@ function preprocess(content) | |
| # | ||
| #md # [](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb) | ||
| #md # | ||
| # You are seeing the | ||
| # *You are seeing the | ||
| #md # HTML output generated by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) and | ||
| #nb # notebook output generated by | ||
| # [Literate.jl](https://github.com/fredrikekre/Literate.jl) from the | ||
| # [Julia source file](@__REPO_ROOT_URL__/examples/@__NAME__/script.jl). | ||
| # The corresponding | ||
| #md # notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb). | ||
| #nb # HTML output can be viewed [here](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev/examples/@__NAME__/). | ||
| #md # The corresponding notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).* | ||
| #nb # The rendered HTML can be viewed [in the docs](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev/examples/@__NAME__/).* | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How difficult would it be to change the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not difficult but a bit annoying it seems. Literate automatically derives the url for the repo and nbviewer when running it with Github actions which are used to replace
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for looking into this. Would you be willing to write it up as an issue in the Literate.jl repo ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, thank you @fredrikekre ! |
||
| # | ||
| """, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # run examples | ||
| ### Process examples | ||
| const EXAMPLES_SRC = joinpath(@__DIR__, "..", "examples") | ||
| const EXAMPLES_OUT = joinpath(@__DIR__, "src", "examples") | ||
| const LITERATEJL = joinpath(@__DIR__, "literate.jl") | ||
|
|
@@ -24,10 +24,12 @@ end | |
| # Check that all examples were run successfully | ||
| isempty(processes) || success(processes) || error("some examples were not run successfully") | ||
|
|
||
| # Build documentation | ||
| using KernelFunctions | ||
| ### Build documentation | ||
| using Documenter | ||
|
|
||
| using KernelFunctions | ||
| using PDMats, Kronecker # we have to load all optional packages to generate the full API documentation | ||
|
|
||
| # Print `@debug` statements (https://github.com/JuliaDocs/Documenter.jl/issues/955) | ||
| if haskey(ENV, "GITHUB_ACTIONS") | ||
| ENV["JULIA_DEBUG"] = "Documenter" | ||
|
|
@@ -39,10 +41,7 @@ DocMeta.setdocmeta!( | |
| :DocTestSetup, | ||
| quote | ||
| using KernelFunctions | ||
| using LinearAlgebra | ||
| using Random | ||
| using PDMats: PDMats | ||
|
Comment on lines
-42
to
-44
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these not needed anymore for the doctests?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clearly not :) |
||
| end; | ||
| end; # we have to load all packages used (implicitly) within jldoctest blocks in the API docstrings | ||
| recursive=true, | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Example notebooks | ||
|
|
||
| The examples in this directory are stored in [Literate.jl](https://github.com/fredrikekre/Literate.jl) format. | ||
|
|
||
| To run them locally, navigate to the directory with the example that you want to run and | ||
| start the Julia REPL and activate the project environment of the example: | ||
| ```julia | ||
| julia> ] activate . | ||
| ``` | ||
| Alternatively, you can start Julia with `julia --project=.`. Then install all required | ||
| packages with | ||
| ```julia | ||
| julia> ] instantiate | ||
| ``` | ||
| Afterwards simply run | ||
| ```julia | ||
| julia> include("script.jl") | ||
| ``` | ||
| In particular when editing an example, it can be convenient to (re-)run only some parts of | ||
| an example. | ||
| Many editors with Julia support such as VSCode, Juno, and Emacs support the evaluation of individual lines or code chunks. | ||
|
|
||
st-- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| You can convert a notebook to markdown and Jupyter notebook formats, respectively, by executing | ||
| ```julia | ||
| julia> using Literate | ||
| julia> Literate.markdown("script.jl", "output_directory") | ||
| julia> Literate.notebook("script.jl", "output_directory") | ||
| ``` | ||
| (see the [Literate.jl docs](https://fredrikekre.github.io/Literate.jl/v2/) for additional options) or run | ||
| ```shell | ||
| julia docs/literate.jl examples/myexample/script.jl output_directory | ||
| ``` | ||
| which also executes the code and generates embedded plots etc. in the same way as in building the KernelFunctions documentation. | ||
|
|
||
st-- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Add a new example | ||
|
|
||
| Create a new subdirectory in here, and put your code in a file called `script.jl` so that it will get picked up by the automatic docs build. | ||
|
|
||
| Every example uses a separate project environment. Therefore you should also create a new | ||
| project environment in the directory of the example that contains all packages required by your script. | ||
| Note that the dependencies of your example *must* include the `Literate` package. | ||
|
|
||
| From a Julia REPL started in your example script's directory, you can run | ||
| ```julia | ||
| julia> ] activate . | ||
| julia> ] add Literate | ||
| julia> ] add KernelFunctions | ||
| julia> # add any other example-specific dependencies | ||
| ``` | ||
| to generate the project files. | ||
|
|
||
| Make sure to commit both the `Project.toml` and the `Manifest.toml` file when you want to contribute your example in a pull request. | ||
Uh oh!
There was an error while loading. Please reload this page.