|
| 1 | +Cloning the Repository and Building the Website Locally |
| 2 | +======================================================= |
| 3 | + |
| 4 | +## Cloning the GitHub Repository |
| 5 | + |
| 6 | +The GitHub repository for SimPEG User Tutorials can cloned from https://github.com/simpeg/user-tutorials/. |
| 7 | +If using the Git Bash shell: |
| 8 | + |
| 9 | +```bash |
| 10 | +git clone https://github.com/simpeg/user-tutorials |
| 11 | +cd user-tutorials |
| 12 | +``` |
| 13 | + |
| 14 | +## Setting Up Your Python Environment |
| 15 | + |
| 16 | +The notebooks are maintained so that they run correctly using the latest SimPEG release. Some notebooks may not |
| 17 | +run correctly if SimPEG is being imported from an earlier release or development branch. The website is built |
| 18 | +from the collection of Markdown files and Jupyter notebooks using [Myst][mystmd.org]. To build the website locally, |
| 19 | +you will need to [install `mystmd`][install-mystmd] |
| 20 | + |
| 21 | +For contributors, an `environment.yml` file has been provided in the root directory of the repository. |
| 22 | +To create the environment using conda: |
| 23 | + |
| 24 | +```bash |
| 25 | +conda env create -f environment.yml |
| 26 | +``` |
| 27 | + |
| 28 | +## How to build the website locally |
| 29 | + |
| 30 | +The SimPEG User Tutorials were created using [Myst][mystmd.org]. Myst is |
| 31 | +capable of building the website from content stored in [Jupyter |
| 32 | +Notebooks][jupyter]. |
| 33 | + |
| 34 | +We can build the website from the current content in the Jupyter Notebooks. |
| 35 | +This can be done in a few seconds with very slim resource requirements. |
| 36 | + |
| 37 | +Rerunning the notebooks is a more intensive task that will require significant |
| 38 | +amount of memory (specially for the computationally intensive notebooks) and it |
| 39 | +will take some time. |
| 40 | + |
| 41 | +Here you'll find instructions to: |
| 42 | + |
| 43 | +- [Build and the website locally](#build-and-serve-the-website-locally) |
| 44 | +- [Rerun notebooks in the repo](#rerun-notebooks) |
| 45 | + |
| 46 | +### Build and Serve the Website Locally |
| 47 | + |
| 48 | +#### Build and Serve |
| 49 | + |
| 50 | +The following command will build the website and serve it locally, so you can |
| 51 | +preview it. Follow the instructions that will be prompted by the command to see |
| 52 | +the website: |
| 53 | + |
| 54 | +```bash |
| 55 | +msyt start |
| 56 | +``` |
| 57 | + |
| 58 | +#### Build Only |
| 59 | + |
| 60 | +The following command will build the website and store the HTML files in |
| 61 | +a new `_build` folder: |
| 62 | + |
| 63 | +```bash |
| 64 | +msyt build --html |
| 65 | +``` |
| 66 | + |
| 67 | +#### Clean Cached Builds |
| 68 | + |
| 69 | +```bash |
| 70 | +myst clean --all |
| 71 | +``` |
| 72 | + |
| 73 | +### Rerun Notebooks |
| 74 | + |
| 75 | +Start by cloning this repository: |
| 76 | + |
| 77 | +```bash |
| 78 | +git clone https://github.com/simpeg/user-tutorials |
| 79 | +cd user-tutorials |
| 80 | +``` |
| 81 | + |
| 82 | +And create a `conda` environment using the provided `environment.yml` file: |
| 83 | + |
| 84 | +```bash |
| 85 | +conda env create -f environment.yml |
| 86 | +``` |
| 87 | + |
| 88 | +We can use `nbconvert` to rerun a notebook and overwrite its output cells |
| 89 | +in place. |
| 90 | +To rerun a single notebook, use: |
| 91 | + |
| 92 | +```bash |
| 93 | +jupyter nbconvert --to notebook --execute --inplace notebook.ipynb |
| 94 | +``` |
| 95 | + |
| 96 | +To rerun all notebooks, use: |
| 97 | + |
| 98 | +> [!CAUTION] |
| 99 | +> Rerunning all notebooks is a computationally intensive task. Some notebooks |
| 100 | +> require significant amount of memory to allocate large sensitivity matrices. |
| 101 | +
|
| 102 | +> [!IMPORTANT] |
| 103 | +> If you are using bash as your shell, make sure to run `shopt -s |
| 104 | +> globstar` to enable the `globstar` feature that allows the use of `**` for |
| 105 | +> filename expansion. |
| 106 | +
|
| 107 | +```bash |
| 108 | +jupyter nbconvert --to notebook --execute --inplace notebooks/**/*.ipynb |
| 109 | +``` |
| 110 | + |
| 111 | + |
| 112 | +[install-mystmd]: https://mystmd.org/guide/quickstart |
| 113 | +[jupyter]: https://jupyter.org |
| 114 | +[mystmd.org]: https://mystmd.org |
| 115 | + |
| 116 | + |
| 117 | +## Check Style of Notebooks |
| 118 | + |
| 119 | +We can check the code style of our notebooks using [`ruff`][ruff] and |
| 120 | +[`nbqa`][nbqa]. Simply run the following command to check the style of the |
| 121 | +notebooks: |
| 122 | + |
| 123 | +```bash |
| 124 | +nbqa ruff notebooks |
| 125 | +``` |
| 126 | + |
| 127 | +And run this to autoformat them: |
| 128 | + |
| 129 | +```bash |
| 130 | +nbqa ruff --fix notebooks |
| 131 | +``` |
| 132 | + |
| 133 | +Alternatively, you can use the targets we have in the `Makefile`, like `make |
| 134 | +check` and `make format`. Read more information about the available targets |
| 135 | +by running `make help`. |
0 commit comments