You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+107-4Lines changed: 107 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ This is a community resource. We welcome contributions in the form of issues and
9
9
* If you find a typo, feel free to [submit a pull request](https://github.com/pyOpenSci/python-package-guide/pulls) to modify the text directly. Or, if you are less comfortable with pull requests, feel free to open an issue.
10
10
* If you want to see a larger change to the content of the guide book, please submit an issue first!
11
11
12
-
## How this guide structured
12
+
## How this guide is structured
13
13
14
14
Most of this repository is structured for **Sphinx**, a documentation engine built in `Python`. We are using the Sphinx Book Theme and the `myST` syntax to create each page in this book.
15
15
@@ -31,18 +31,121 @@ To do so, follow these steps:
31
31
1. Install `nox`
32
32
33
33
```
34
-
pip install nox
34
+
python -m pip install nox
35
35
```
36
36
2. Build the documentation:
37
37
38
38
```
39
-
nox -s docs
39
+
python -m nox -s docs
40
40
```
41
41
42
42
This should create a local environment in a `.nox` folder, build the documentation (as specified in the `noxfile.py` configuration), and the output will be in `_build/html`.
43
+
The site can then be viewed locally by opening the top level `index.html` in your web browser. The exact location of this file will depend on you system, but the output of the following command could be copied into an address bar
44
+
45
+
```
46
+
echo "file://$(pwd)/_build/html/index.html"
47
+
```
43
48
44
49
To build live documentation that updates when you update local files, run the following command:
45
50
46
51
```
47
-
nox -s docs-live
52
+
python -m nox -s docs-live
53
+
```
54
+
55
+
When build like this, the output will tell you a localhost address where the site can be viewed, generally http://127.0.0.1:8000.
56
+
57
+
## Code examples
58
+
59
+
This guide uses the [literalinclude Sphinx directive](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-literalinclude)
60
+
whenever possible to keep code and prose separate. Code for use in the documentation is kept in the `examples/` folder.
61
+
62
+
### Referencing code in documentation
63
+
64
+
If an example is present elsewhere in the documentation that you want to use, you can copy the `literalinclude`
65
+
directive verbatim and the examples will stay in sync.
66
+
67
+
If you already see code in the examples folder that you can use for new documentation, a new `literalinclude` can be
68
+
made to extract it into the site. Only a relative path to the code is required for a working `literalinclude`, but you
69
+
should in almost all cases also provide a `:language:` and `:lines:`. The former makes code examples prettier, and the
70
+
later can protect your example from future modifications to the code.
71
+
72
+
**Pro tip**: As an alternative to `:lines:` there are also the `:start-after:`, `:start-at:`, `:end-before:`, and
73
+
`:end-at:` options. And if the example code is Python, `:pyobject:` can be an even more future-proof way to keep the
74
+
same documentation content even through code refactors.
75
+
76
+
If you need example code that doesn't yet exist in `examples/` see (#creating-code-for-documentation).
77
+
78
+
### Creating code for documentation
79
+
80
+
Whenever you come across a place that could benefit from a code block, instead of writing it in-line with a code fence
81
+
(`` ``` `` blocked text) you can write it as a file in its own format. Your example may even already exist; see
82
+
(#referencing-code-in-documentation).
83
+
84
+
If you need a net new example and it doesn't fit into any existing example files, you can create a new file and
85
+
reference it in a `literalinclude`. If it makes sense for that file to live within one of the existing example
86
+
projects please add it there; otherwise create a new folder in the examples.
87
+
88
+
If an existing example is incomplete or a new example makes sense to be added to an existing file, go ahead and add it,
89
+
but take care to not break the rest of the guide. Whenever possible, extend the example rather that rewrite it. So for
90
+
instance, add new functions to the end of the file, new methods after all existing ones in a class.
91
+
92
+
Example code is checked for correctness, so adding a new example may require adding additional tests for coverage, and
93
+
will require fixing any failing tests.
94
+
95
+
***WARNING***: great care should be taken when modifying existing example code, especially any modification beyond
96
+
appending to the end of the file. All code examples are (potentially) shared examples. This makes for more consistent
97
+
examples in the guide but can mean action-at-a-distance when modifying the examples for one particular use case.
98
+
If you find yourself modifying existing examples try running this command and then checking those pages in a new build.
-**dependencies:** dependencies are optional but we strongly suggest you include them in your pyproject.toml. Dependencies will be installed by pip when your project is installed creating a better user-experience.
@@ -194,7 +196,7 @@ Then specify dependency groups as follows:
0 commit comments