Skip to content

Commit fdae3df

Browse files
committed
Fix: add info about hatch scripts
1 parent d068e95 commit fdae3df

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-0
lines changed

docs/conf.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Below we grab the current date and time using python
2+
# this is used to them support the copyright date always being the current year
3+
# when you build your docs
4+
import subprocess
5+
from datetime import datetime
6+
7+
current_year = datetime.now().year
8+
organization_name = "pyOpenSci"
9+
10+
11+
project = "pyosPackage"
12+
copyright = f"{current_year}, {organization_name}"
13+
author = "pyOpenSci Community"
14+
15+
# *********** RELEASE NUMBER **************
16+
# This is optional - if you want the release of your docs to align with your
17+
# package release cycle then the code below will get the recent tag and use
18+
# that to generate your documentation release value.
19+
try:
20+
release_value = (
21+
subprocess.check_output(["git", "describe", "--tags"])
22+
.decode("utf-8")
23+
.strip()
24+
)
25+
release_value = release_value[:4]
26+
except subprocess.CalledProcessError:
27+
release_value = "0.1" # Default value in case there's no tag
28+
29+
# Update the release value
30+
release = release_value
31+
32+
33+
release = "1.10"
34+
35+
# -- General configuration ---------------------------------------------------
36+
# Extensions add additional functionality to your documentation.
37+
# TODO: describe each extension below
38+
extensions = [
39+
"sphinx_design",
40+
"sphinx_copybutton",
41+
"sphinx.ext.intersphinx",
42+
# This allows you to create :::{todo} sections that will not be rendered
43+
# in the live docs
44+
"sphinx.ext.todo",
45+
"myst_parser",
46+
]
47+
48+
49+
templates_path = ["_templates"]
50+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
51+
52+
# ****** setup MYST ******
53+
# colon fence for card support in md
54+
myst_enable_extensions = [
55+
"colon_fence",
56+
"deflist",
57+
"attrs_block",
58+
]
59+
myst_heading_anchors = 3
60+
myst_footnote_transition = False
61+
62+
# -- Options for HTML output -------------------------------------------------
63+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
64+
65+
html_theme = "pydata_sphinx_theme"
66+
html_static_path = ["_static"]

docs/documentation/setup-sphinx.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Sphinx documentation
2+
3+
This package uses Sphinx to create documentation.
4+
5+
We like sphinx because it is a community driven project with a community
6+
driven theme that the scientific Python community works on:
7+
8+
`pydata_sphinx_theme`
9+
10+
:::{note}
11+
MkDocs is the other most common documentation tool used in the Python
12+
ecosystem.
13+
:::
14+
15+
## Setup your documentation
16+
17+
You can chose to create sphinx documentation using sphinx-quickstart.
18+
Below is the Sphinx-quickstart workflow used to create these docs. However,
19+
inevitably you will likely customize the documentation setup. So you may also
20+
want to just copy this repository's structure.
21+
22+
```
23+
➜ sphinx-quickstart
24+
Welcome to the Sphinx 5.3.0 quickstart utility.
25+
26+
Please enter values for the following settings (just press Enter to
27+
accept a default value, if one is given in brackets).
28+
29+
Selected root path: .
30+
31+
You have two options for placing the build directory for Sphinx output.
32+
Either, you use a directory "_build" within the root path, or you separate
33+
"source" and "build" directories within the root path.
34+
> Separate source and build directories (y/n) [n]: n
35+
36+
The project name will occur in several places in the built documentation.
37+
> Project name: pyosPackage
38+
> Author name(s): pyOpenSci Community
39+
> Project release []: 1.10
40+
41+
If the documents are to be written in a language other than English,
42+
you can select a language here by its language code. Sphinx will then
43+
translate text that it generates into that language.
44+
45+
For a list of supported codes, see
46+
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.
47+
> Project language [en]: en
48+
```
49+
50+
The `conf.py` file is the core that you use to configure your sphinx docs.
51+
The conf.py file in this package is setup

docs/hatch-envs-scripts.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Hatch scripts and environments
2+
3+
* Hatch has a nox / tox / make like feature that allows you to:
4+
5+
1. Define `Python` environments with a set of tools that you wish to have installed.
6+
2. Define commands that you wish to run in that environment.
7+
8+
All of the configuration for this goes into your `pyproject.toml` file.
9+
10+
## How to set this up
11+
12+
To set this up you first need to define an environment in your `pyproject.toml`
13+
with all of the dependencies that the environment needs.
14+
15+
Below you can see we have defined an environment called `docs`.
16+
17+
:::{literalinclude} ../pyproject.toml
18+
:language: toml
19+
:start-at: [tool.hatch.envs.docs]
20+
:end-before: [tool.hatch.envs.docs.scripts]
21+
:::
22+
23+
Once you have an environment setup, you can then create commands that you wish
24+
hatch to run for you within that environment. Below you setup two commands:
25+
26+
1. Build sphinx docs using the `sphinx-build` command.
27+
2. Build sphinx docs in "live" mode which allows them to be updated every time
28+
that you save
29+
30+
:::{literalinclude} ../pyproject.toml
31+
:language: toml
32+
:start-at: [tool.hatch.envs.docs.scripts]
33+
:end-before: [tool.hatch.envs.test]
34+
:::

docs/index.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Welcome to pyosPackage's documentation
2+
3+
:::{toctree}
4+
:maxdepth: 2
5+
:caption: Contents:
6+
7+
home <self>
8+
hatch scripts <hatch-envs-scripts>
9+
Setup Sphinx <documentation/setup-sphinx>
10+
:::
11+
12+
:::{toctree}
13+
:maxdepth: 2
14+
:caption: Contents:
15+
16+
:::
17+
18+
This guidebook uses myst as the primary documentation syntax.
19+
20+
more about myst here....
21+
22+
If you see syntax like the syntax below, you are looking at rst.
23+
24+
```
25+
.. toctree::
26+
:maxdepth: 2
27+
:caption: Contents:
28+
```
29+
30+
:::{note}
31+
you can remove the `make.bat` and `Makefile` files included with sphinx build.
32+
:::

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ Issues = "https://github.com/pyopensci/pyospackage/issues"
3030
Source = "https://github.com/pyopensci/pyospackage"
3131

3232

33+
[tool.hatch.envs.docs]
34+
dependencies = [
35+
"sphinx",
36+
"sphinx-autobuild",
37+
"sphinx-inline-tabs",
38+
# Note that the tool you install has dashes- between the name, vs _underscores
39+
# when you call the theme in sphinx's conf.py
40+
"pydata-sphinx-theme",
41+
"sphinx-design",
42+
"sphinx-copybutton",
43+
"myst-nb",
44+
"myst-parser",
45+
]
46+
47+
48+
[tool.hatch.envs.docs.scripts]
49+
# Build your docs statically - html output
50+
# hatch run docs:docs-html
51+
docs-html = "sphinx-build docs/ docs/_build"
52+
# hatch run docs:docs-html
53+
docs-live = "sphinx-autobuild docs/ docs/_build"
54+
# TODO: add step to clean docs directory
55+
56+
3357
[tool.hatch.envs.test]
3458
dependencies = [
3559
"pytest",

0 commit comments

Comments
 (0)