From 1aa9f513cb2653631e329428ec51a7406ecda760 Mon Sep 17 00:00:00 2001 From: Thomas Pinder Date: Tue, 16 May 2023 20:35:01 +0100 Subject: [PATCH] Autogen code --- docs/contributing.md | 14 ++++++++------ docs/scripts/notebook_converter.py | 30 ++++++++++++++++++++++++++++++ mkdocs.yml | 6 ++++-- 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 docs/scripts/notebook_converter.py diff --git a/docs/contributing.md b/docs/contributing.md index 826a5b9b7..62a9c7f66 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1,4 +1,6 @@ -# How can I contribute? +# Contributing + +## How can I contribute? GPJax welcomes contributions from interested individuals or groups. There are many ways to contribute, including: @@ -15,13 +17,13 @@ many ways to contribute, including: - Extending or improving our [codebase](https://github.com/JaxGaussianProcesses/GPJax). -# Code of conduct +## Code of conduct As a contributor to GPJax, you can help us keep the community open and inclusive. Please read and follow our [Code of Conduct](https://github.com/JaxGaussianProcesses/GPJax/blob/master/.github/CODE_OF_CONDUCT.md). -# Opening issues and getting support +## Opening issues and getting support Please open issues on [Github Issue Tracker](https://github.com/JaxGaussianProcesses/GPJax/issues/new/choose). Here you can @@ -30,7 +32,7 @@ mention You can ask a question or start a discussion in the [Discussion section](https://github.com/JaxGaussianProcesses/GPJax/discussions) on Github. -# Contributing to the source code +## Contributing to the source code Submitting code contributions to GPJax is done via a [GitHub pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests). @@ -47,7 +49,7 @@ you through every detail! Before opening a pull request we recommend you check our [pull request checklist](#pull-request-checklist). -## Step-by-step guide: +### Step-by-step guide: 1. Click [here](https://github.com/JaxGaussianProcesses/GPJax/fork) to Fork GPJax's codebase (alternatively, click the 'Fork' button towards the top right of @@ -114,7 +116,7 @@ you through every detail! request' button to send your changes to the project's maintainers for review. -## Pull request checklist +### Pull request checklist We welcome both complete or "work in progress" pull requests. Before opening one, we recommended you check the following guidelines to ensure a smooth review diff --git a/docs/scripts/notebook_converter.py b/docs/scripts/notebook_converter.py new file mode 100644 index 000000000..6b09770d6 --- /dev/null +++ b/docs/scripts/notebook_converter.py @@ -0,0 +1,30 @@ +import jupytext +from glob import glob +import mkdocs_gen_files + + +notebooks = glob("docs/examples/*.py", recursive=True) + +code = {} +for notebook in notebooks: + if "utils" in notebook: + continue + ntbk = jupytext.read(notebook) + code_cells = [] + header = ntbk["cells"][0]["source"].split("\n")[0].replace("#", "").strip() + for c in ntbk["cells"]: + if c["cell_type"] == "code": + code_cells.append(c["source"]) + code[header] = "\n\n".join(code_cells) + + +with mkdocs_gen_files.open("give_me_the_code.md", "w") as f: + print("# Give me the code", file=f) + for k, v in code.items(): + print(f"## {k}", file=f) + print(file=f) + print("```python", file=f) + print(v, file=f) + print("```", file=f) + print(file=f) + mkdocs_gen_files.set_edit_path("give_me_the_code.md", "notebook_converter.py") diff --git a/mkdocs.yml b/mkdocs.yml index 1b477bc1a..4ffb331f0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -29,6 +29,7 @@ nav: - Kernels: examples/kernels.py - UCI regression: examples/yacht.py - Pathwise Sampling for Spatial Modelling: examples/spatial.py + - 💻 Raw tutorial code: give_me_the_code.md - 📕 Reference: api/ theme: @@ -77,6 +78,7 @@ plugins: - gen-files: scripts: - docs/scripts/gen_pages.py # or any other name or path + - docs/scripts/notebook_converter.py # or any other name or path - literate-nav: nav_file: SUMMARY.md - bibtex: @@ -86,8 +88,8 @@ plugins: - mkdocs-jupyter: execute: true allow_errors: false -# binder: true -# binder_service_name: "gh" + # binder: true + # binder_service_name: "gh" # binder_branch: "main" - mkdocstrings: watch: