Skip to content
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

resolve some TODOs #42

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions episodes/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@

:::: challenge

TODO

Create a new file called `CONTRIBUTING.md` and populate it with a few sentences.

- What are the most important things for a new contributor to know?
- What should a user do if they encounter a bug?
- What are the common questions that a new developer might have when they work on this research software?

::::

## Software project governance
Expand All @@ -76,7 +78,7 @@

For many working in a research context, there are additional considerations to ensure that institutional policies, ethics, and data protection regulations are carefully observed. These protocols are outside the scope of this document, but these factors should be clearly communicated to all contributors.

:::: tip

Check warning on line 81 in episodes/contributors.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[unknown div] tip

Many open-source research software projects adopt the [Contributor Covenant](https://www.contributor-covenant.org/), which can also be customised to suit the needs of your collaborators.

Expand Down
15 changes: 14 additions & 1 deletion episodes/docstrings.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ Use the `help()` function to view the documentation string for a function.

::::::::::::::::: solution

TODO
Let's view the help text for an in-built [function `abs()`](https://docs.python.org/3/library/functions.html#abs) that finds the absolute value of a number.

```python
help(abs)
```

The following text will be printed to the screen@

```output
Help on built-in function abs in module builtins:

abs(x, /)
Return the absolute value of the argument.
```

::::::::::::::::::::::::::

Expand Down
108 changes: 82 additions & 26 deletions episodes/sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

:::::::::::::::::::::::::::::::::::::: questions

- What is a documentation website for research software?
- How do I present **comprehensive information** to users of my research software?
- How do I generate a website containing a user guide to my code?
- What should my documentation site contain?
- What should a good documentation website contain?
- How do I publish my software documentation on the internet?

::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::: objectives

- Learn about documentation websites for software packages.
- Learn about **documentation websites** for software packages.
- Gain basic familiarity with some common website generation tools.
- Understand the basics of structuring a documentation website.
- Be able to set up a static site deployment workflow.
Expand Down Expand Up @@ -106,6 +106,13 @@

:::


### Documentation sites for R packages

It's also possible to generate a documentation site to accompany R packages that you create.
For more information about this, please refer to the book *R Packages* by Hadley Wickham, which
has a chapter on [documentation websites](https://r-pkgs.org/website.html).

### Sphinx

[Sphinx](https://www.sphinx-doc.org/) is a tool for building documentation websites that is commonly used amongst developers of Python packages, although it's also compatible with other programming languages. It doesn't currently support packages written using the R statistical language.
Expand All @@ -124,12 +131,32 @@

##### Installing Sphinx

Navigate to the root folder of your code project. Create a virtual environment using [venv](https://docs.python.org/3/library/venv.html) which is a separate area in which to install the Sphinx package.
Navigate to the root folder of your code project.
Create a virtual environment using [venv](https://docs.python.org/3/library/venv.html) which is a separate area in which to install the Sphinx package.
This command will create a virtual environment in a directory called `.venv/`

::: group-tab

### Windows

```bash
python -m venv .venv
```

### Linux

```bash
python3 -m venv .venv
```

### macOS

```bash
python -m venv .venv
```

:::

This will create a subdirectory that contains the packages we'll need to complete the exercises in this section.

Run the activation script to enable the virtual environment. The specific command needed to activate the virtual environment depends on the operating system you are using.
Expand All @@ -154,14 +181,14 @@
source .venv/bin/activate
```

:::

Use the Python package manager [pip](https://pip.pypa.io/en/stable/) to [install Sphinx](https://www.sphinx-doc.org/en/master/usage/installation.html).

```bash
pip install sphinx
```

:::

##### Start a new Sphinx project

Sphinx includes a command to set up a new project called [sphinx-quickstart](https://www.sphinx-doc.org/en/master/man/sphinx-quickstart.html). Navigate to your project's root folder and run the following command.
Expand All @@ -178,15 +205,19 @@

::: callout

To find out more about the Sphinx configuration files, please read their guide to [defining document structure](https://www.sphinx-doc.org/en/master/usage/quickstart.html#defining-document-structure) on the Sphinx documentation.
### Sphinx options

To find out more about the Sphinx configuration files,
please read their guide to [defining document structure](https://www.sphinx-doc.org/en/master/usage/quickstart.html#defining-document-structure) on the Sphinx documentation.

:::

#### Building the site

In this context, building means taking our collection of Sphinx files and converting them into the source code files that define a website. Sphinx will create HyperText Markup Language (HTML) files, which is the markup language for pages that display in a web browser commonly used on the internet.
In this context, _building_ means taking our collection of Sphinx files and converting them into the source code files that define a website.
Sphinx will create _HyperText Markup Language_ (HTML) files, which is the markup language for pages that display in a web browser commonly used on the internet.

To build our site, we run the [sphinx-build](https://www.sphinx-doc.org/en/master/man/sphinx-build.html) command using the `-M` option to select HTML syntax as the output format.
To build our site, we run the [sphinx-build](https://www.sphinx-doc.org/en/master/man/sphinx-build.html) command using the `-M` option to select <abbr title="HyperText Markup Language">HTML</abbr> syntax as the output format.

```bash
sphinx-build -M html docs docs/_build
Expand All @@ -196,7 +227,7 @@

The file `docs/_build/html/index.html` contains the home page of your new documentation site! Open that file to view your handiwork.

![The Sphinx homepage for our documentation site](fig/sphinx-build-screenshot.png "Sphinx")

Check warning on line 230 in episodes/sites.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: fig/sphinx-build-screenshot.png

#### Autodoc

Expand All @@ -205,10 +236,9 @@
##### Configuring Autodoc

Let's set up the options for `autodoc`.
(If you struggle with these steps, please refer to the [template project](https://github.com/Joe-Heffer-Shef/oddsong).)

If you struggle with these steps, please refer to the [template project](https://github.com/Joe-Heffer-Shef/oddsong).

Add the following lines to `docs/conf.py`
Add the following lines to `docs/conf.py` which

```python
# Our Python code may be imported from the parent directory
Expand All @@ -217,15 +247,42 @@
sys.path.insert(0, os.path.abspath('..'))
```

This ensures that Sphinx can access our Python code.
This ensures that Sphinx can access our Python code by pointing at the root directory of our project.
The `..` syntax means "one folder up", which means `autodoc` will search in the root directory for code to import.

:::: spoiler

### What does this code mean?

The Python code uses [`sys.path`](https://docs.python.org/3/library/sys.html#sys.path), a list of locations to search for code.
By modifying the Python _module search path_, we allow `autodoc` to locate and import our code modules from a specific directory that is not in the default search path.

Next, edit `docs/index.rst` and add the following lines:
This is often necessary when working with project structures that involve multiple directories, helping the interpreter to find code that isn't installed in the standard library location.

::::

Next, edit `docs/index.rst` and add the following lines to instruct Sphinx to automatically generation documentation for our Python module.

```rst
.. automodule:: oddsong.song
:members:
```

:::: spoiler

### What does this code mean?

This [reStructuredText (reST)](https://docutils.sourceforge.io/rst.html) markup language has the following elements:

- `..` indicates a _directive_ within a <abbr title="reStructuredText">reST</abbr> document that is used to configure Sphinx.
- `automodule::` indicates a specific directive to use `autodoc` to automatically generate documentation for a module.
- `oddsong.song` is the path to our Python module, for which documentation will be created.
- `:members:` is an optional argument for the automodule directive that instructs Sphinx to include documentation for all members (functions, classes, variables) defined within the specified module.

For more information about <abbr title="reStructuredText">reST</abbr>, please read the [Introduction to reStructuredText](https://www.writethedocs.org/guide/writing/reStructuredText/) by _Write The Docs_.

::::

Now, when we build our site, Sphinx will scan the contents of the `oddsong` Python module and automatically generate a useful reference guide to our functions.

```bash
Expand All @@ -234,27 +291,18 @@

The result looks something like this:

![Python documentation string rendered as HTML](fig/oddsong-autodoc.png "A Python function documentation string")

Check warning on line 294 in episodes/sites.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: fig/oddsong-autodoc.png

::::::::::::::::::::::::::::::::::::: challenge

## Automatically generated content

Try using `autodoc`.
## Automatically generate content

:::::::::::::::: solution
Try using `autodoc` to analyise your own code and build a documentation site by following the steps above.

TODO
After the `sphinx-build` command has completed successfully, browse the contents of the `docs/_build/html` folder and discuss what you find.

:::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::

### Documentation sites for R packages

It's also possible to generate a documentation site to accompany R packages that you create.
For more information about this, please refer to the book *R Packages* by Hadley Wickham, which
has a chapter on [documentation websites](https://r-pkgs.org/website.html).

## Publishing

Now that you've started writing your documentation website, there are various ways to upload it to the internet so that others can read it.
Expand All @@ -271,3 +319,11 @@
- Documentation websites may be deployed to a hosting platform.

::::::::::::::::::::::::::::::::::::::::::::::::

## Further resources

Please review the following material which provides more information about some of the topics covered in this episode.

- Sphinx [Getting Started](https://www.sphinx-doc.org/en/master/usage/quickstart.html)
- _Write the Docs_ [Introduction to reStructuredText](https://www.writethedocs.org/guide/writing/reStructuredText/)
- GitHub documentation [About wikis](https://docs.github.com/en/communities/documenting-your-project-with-wikis/about-wikis)
Loading