|
1 | 1 | Installing Sphinx
|
2 | 2 | =================
|
| 3 | +This guide will cover how to install Sphinx **locally** on your laptop. |
| 4 | +When you need to write a lot of documentation, it's a **good idea** to do it all locally. |
| 5 | +We will go over: |
3 | 6 |
|
4 |
| - |
5 |
| -Local Installation |
6 |
| -================== |
7 |
| - |
8 |
| -.. tip:: |
9 |
| - When you need to write a lot of documentation, it's a **good idea to do it all locally.** |
| 7 | +1. Installing Sphinx using a virtual environment |
| 8 | +2. How to build documentation locally using Sphinx |
10 | 9 |
|
11 | 10 |
|
12 | 11 | 1. Cloning the Repo
|
@@ -87,123 +86,4 @@ While in the virtual environment, run the following command:
|
87 | 86 |
|
88 | 87 | sphinx-autobuild docs _build
|
89 | 88 |
|
90 |
| -You can then point your web browser to: http://127.0.0.1:8000/ |
91 |
| - |
92 |
| -Remote Build on GitHub |
93 |
| -====================== |
94 |
| -The :code:`_build` directory **should not be pushed to GitHub**. |
95 |
| -Instead we will use a GitHub Workflow to automatically build documentation that is pushed to the repository. |
96 |
| -The built documentation will then be automatically served up on a webpage in :code:`GitHub Pages` |
97 |
| - |
98 |
| -1. Set up GitHub Pages |
99 |
| ----------------------- |
100 |
| -GitHub Pages allow users to view web pages generated by our documentation. |
101 |
| -While there already a page set up for the :code`sphinx-documentation-demo` project, you will need to do the following steps for a new project: |
102 |
| - |
103 |
| -1a. Navigate to Page settings |
104 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
105 |
| -.. figure:: images/guide_install_repo_settings.png |
106 |
| - :class: sd-border-2 |
107 |
| - |
108 |
| - Click the Settings tab in the project you want to add to GitHub Pages. |
109 |
| - |
110 |
| - |
111 |
| -.. figure:: images/guide_install_repo_page_tab.png |
112 |
| - :class: sd-border-2 |
113 |
| - |
114 |
| - Click the Pages tab (in the left sidebar) in the Settings page. |
115 |
| - |
116 |
| - |
117 |
| -1b. Select branch to use with GitHub Pages |
118 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
119 |
| -.. warning:: |
120 |
| - |
121 |
| - The GitHub repo must be **public** in order for it to be accessible via GitHub Pages. |
122 |
| - |
123 |
| -.. figure:: images/guide_install_page_branch.png |
124 |
| - :class: sd-border-2 |
125 |
| - |
126 |
| - When documentation is successfully deployed, you will see a link that looks like :code:`A`. For a new repo, this will not be active. |
127 |
| - You will need to set the branch (see :code:`B`). |
128 |
| - This demo uses a separate branch called :code:`gh-pages` to deploy documentation. |
129 |
| - |
130 |
| -2. Using GitHub Workflow to Build Documentation |
131 |
| ------------------------------------------------ |
132 |
| -GitHub can automatically discover workflows located in the :code:`.github/workflows` directory within the project directory. |
133 |
| -We will be using a workflow to build documentation whenever a **new commit is pushed to the repository**. |
134 |
| - |
135 |
| -2a. Example Workflow |
136 |
| -~~~~~~~~~~~~~~~~~~~~ |
137 |
| -We will be reviewing the workflow that :code:`sphinx-documentation-demo` uses. |
138 |
| - |
139 |
| -You can find the workflow in :code:`sphinx-documentation-demo/.github/workflows/documentation.yml` |
140 |
| - |
141 |
| -.. code-block:: |
142 |
| - :emphasize-lines: 16,19,24,26 |
143 |
| - :linenos: |
144 |
| -
|
145 |
| - name: documentation |
146 |
| -
|
147 |
| - on: [push, pull_request, workflow_dispatch] |
148 |
| -
|
149 |
| - permissions: |
150 |
| - contents: write |
151 |
| -
|
152 |
| - jobs: |
153 |
| - docs: |
154 |
| - runs-on: ubuntu-latest |
155 |
| - steps: |
156 |
| - - uses: actions/checkout@v3 |
157 |
| - - uses: actions/setup-python@v3 |
158 |
| - - name: Install dependencies |
159 |
| - run: | |
160 |
| - pip install sphinx pydata-sphinx-theme sphinx-design sphinx-copybutton sphinx-autoapi |
161 |
| - - name: Sphinx build |
162 |
| - run: | |
163 |
| - sphinx-build docs _build |
164 |
| - - name: Deploy to GitHub Pages |
165 |
| - uses: peaceiris/actions-gh-pages@v3 |
166 |
| - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
167 |
| - with: |
168 |
| - publish_branch: gh-pages |
169 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
170 |
| - publish_dir: _build/ |
171 |
| - force_orphan: true |
172 |
| -
|
173 |
| -
|
174 |
| -* **Line 16.** Install dependencies |
175 |
| - * This tells GitHub to install sphinx and its dependencies to the ubuntu image. |
176 |
| - * **Note**: After you add a new sphinx extension to :code:`pyproject.toml` and to :code:`docs/conf.py`, you'll also need to add the dependency to the list on line 16. |
177 |
| -* **Line 19.** Build Docs |
178 |
| - * This runs :code:`sphinx-build` on the :code:`docs/` directory (in the repo) and creates the :code:`_build/` directory. |
179 |
| -* Line 24. Publish to branch |
180 |
| - * After building the docs, this line tells GitHub to publish the changes to the :code:`gh-pages` branch. |
181 |
| - * **Note**: this needs to be the same branch that GitHub Pages is set to publish with. |
182 |
| -* **Line 26.** Specify directory to publish |
183 |
| - * This informs GitHub Pages where the static HTML documentation (built by :code:`sphinx-build`) is located. |
184 |
| - |
185 |
| - |
186 |
| -3. Verifying GitHub Workflow Actions |
187 |
| ------------------------------------- |
188 |
| -Using the previously mentioned workflow, a GitHub Action will be triggered whenever a commit is pushed to the repo. |
189 |
| -You can monitor running jobs from your GitHub Repository. |
190 |
| - |
191 |
| -.. figure:: images/guide_install_github_actions_tab.png |
192 |
| - :class: sd-border-2 |
193 |
| - |
194 |
| - Click on the :code:`Actions` tab. |
195 |
| - |
196 |
| -.. figure:: images/guide_install_actions_build.png |
197 |
| - :class: sd-border-2 |
198 |
| - |
199 |
| - Current and previous workflow runs are listed in the Actions tab. |
200 |
| - The color of the icon indicates the current status of the run. |
201 |
| - You may notice a :code:`pages build and deployment` job running. This is reponsible for building the docs. |
202 |
| - |
203 |
| -.. figure:: images/guide_install_actions_error.png |
204 |
| - :class: sd-border-2 |
205 |
| - |
206 |
| - A red icon indicates that the run has failed. You can click on a run to get debug info for each step. |
207 |
| - Featured in this figure is a very common error: sphinx is missing an extension because it was not installed in the :code:`documentation.yml` workflow. |
208 |
| - |
209 |
| - To fix this, :code:`sphinx-copybutton` had to be added to line 16 in :code:`documentation.yml` (see :ref:`2a. Example Workflow`) |
| 89 | +You can then point your web browser to: http://127.0.0.1:8000/ |
0 commit comments