Skip to content

Use processes to run literate examples #309

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

Closed
wants to merge 11 commits into from

Conversation

theogf
Copy link
Member

@theogf theogf commented Jun 24, 2021

This PR is aiming as using difference processes for each markdown file in #303
I created a new branch in case everything goes to 💩...

theogf and others added 2 commits June 24, 2021 17:44
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@theogf
Copy link
Member Author

theogf commented Jun 24, 2021

No idea why but it seems to work.

docs/make.jl Outdated
Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true)
"""
run(
addenv(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe withenv would be a bit more idiomatic?

@@ -17,44 +17,35 @@ const BLACKLIST = ["deep-kernel-learning", "support-vector-machine"]
ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true)
mkpath(EXAMPLES_OUT)

# preprocessor for Literate example scripts:
# - add Documenter @setup snippet that activates each example's own project environment
function preprocess(content)
Copy link
Member

Choose a reason for hiding this comment

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

I guess it would still be useful to preprocess the examples in a similar way as done in https://github.com/devmotion/CalibrationErrors.jl/blob/c73b2abe19b349586ca1448b55c7e697b814c03c/docs/make.jl#L19-L34 and https://github.com/JuliaGaussianProcesses/AbstractGPs.jl/blob/9b14c286e5885c2e94edf5bc3502347126b23276/docs/make.jl#L16-L23, such that the documentation links to the notebook and vice versa.

Copy link
Member Author

Choose a reason for hiding this comment

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

This can eventually be added later. I think the main point right now is to have examples running

docs/make.jl Outdated
using Literate
Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true)
"""
run(
Copy link
Member

Choose a reason for hiding this comment

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

Can we parallelize this such that examples are executed in parallel?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we could! Does GH Actions allows this? I could not find anything in the docs

Copy link
Member

Choose a reason for hiding this comment

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

I thought we could just use Julia's parallelization capabilities by e.g. spawning multiple processes in parallel. It seems a bit tricky to use GH actions for it since we would have to collect all outputs and only update the gh-pages branch once after everything was run and the documentation was built.

end

cmd = Base.julia_cmd()
docs_env = @__DIR__
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to inherit anything? Maybe it would be cleaner to just install Literate manually (or even better, add it to the dependencies of the example's Project.toml such that it is pinned and tracked as well) and not inherit anything.

Then one could even include the notebook run in the external process as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest I don't fully understand what this does... I just copied the example from https://discourse.julialang.org/t/multiple-environments-in-documenter/63436/4

Copy link
Member

Choose a reason for hiding this comment

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

It builds a stacked environment and adds both the packages in docs/ and examples/current_example/ to the load path (the latter are prioritized). However, I don't think we have to inherit anything if we add the Literate dependency to examples/current_example/. Then we could just run the external process, instantiate the example environment (without any additional special stuff), and generate both the Markdown and the notebook.

docs/make.jl Outdated
Dict("JULIA_LOAD_PATH" => load_path),
),
)
Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just include this in the external process as well? (see https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/pull/309/files#r658620202).

Comment on lines +35 to 37
withenv("JULIA_LOAD_PATH" => load_path) do
run(`$(cmd) --project=$(exampledir) -e $(code)`)
end
Copy link
Member

Choose a reason for hiding this comment

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

Without stacked environments this is just

Suggested change
withenv("JULIA_LOAD_PATH" => load_path) do
run(`$(cmd) --project=$(exampledir) -e $(code)`)
end
run(`$(cmd) --project=$(exampledir) -e $(code)`)

Copy link
Member Author

Choose a reason for hiding this comment

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

Please feel free to apply the correct edits, I am moving in the dark here 😅

@st--
Copy link
Member

st-- commented Jun 29, 2021

This has been superseded by #314 - thanks for getting it started!

@st-- st-- closed this Jun 29, 2021
@st-- st-- deleted the tgf/use_literate_processes branch June 29, 2021 10:02
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.

3 participants