Skip to content

Commit eb72cdf

Browse files
docs: updated API and CONTRIBUTING (#645)
* docs: updated API and CONTRIBUTING * docs: move contributing in nav * docs: remove venv * feat: added docs building to nox * docs: improve description --------- Co-authored-by: Andrzej Novak <[email protected]>
1 parent 1bd8614 commit eb72cdf

File tree

10 files changed

+190
-333
lines changed

10 files changed

+190
-333
lines changed

CONTRIBUTING.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# Contributing to mplhep
22

3-
We are happy to accept contributions to `mplhep` via Pull Requests to the GitHub
4-
repo. To get started fork the repo.
3+
We are happy to accept contributions to `mplhep` via Pull Requests to the GitHub repo. To get started fork the repo.
54

65
## Bug Reports
76

8-
Please open an issue.
7+
Please open an [issue](https://github.com/scikit-hep/mplhep/issues).
98

109
## Installing the development environment
1110

12-
```
11+
```bash
1312
python -m pip install --upgrade --editable ".[all]"
1413
```
15-
1614
Also conveniently accessible as `bash install.sh`.
1715

1816
## Pull Requests
@@ -30,35 +28,66 @@ If you would like to make a pull request please:
3028

3129
### Running the tests
3230

33-
You can run the unit tests (which should be fast!) via the following command.
31+
You can run the unit tests (which should be fast!) via the following command:
32+
33+
**With pytest**
3434

3535
```bash
3636
pytest --mpl --ignore=tests/test_notebooks.py
3737
```
3838

39-
Note: This ignores the notebook tests (which are run via
40-
[papermill](https://github.com/nteract/papermill) and run somewhat slow. Make
41-
sure to run the complete suite before submitting a PR
39+
Note: This ignores the notebook tests (which are run via [papermill](https://github.com/nteract/papermill)) and run somewhat slow.
40+
41+
Make sure to run the complete suite before submitting a PR
4242

4343
```bash
4444
python -m pytest -r sa --mpl --mpl-results-path=pytest_results -n 4
4545
```
4646

47+
**With nox**
48+
49+
```bash
50+
nox -s tests
51+
```
52+
4753
### Making a pull request
4854

49-
We follow [Conventional Commit](https://www.conventionalcommits.org/) for commit
50-
messages and PR titles. Since we merge PR's using squash commits, it's fine if
51-
the final commit messages (proposed in the PR body) follow this convention.
55+
We follow [Conventional Commit](https://www.conventionalcommits.org/) for commit messages and PR titles. Since we merge PR's using squash commits, it's fine if the final commit messages (proposed in the PR body) follow this convention.
5256

5357
### Generating Reference Visuals
5458

55-
If you modified expected outcomes of the tests. New baseline visuals can be
56-
generated using this command:
59+
If you modified expected outcomes of the tests. New baseline visuals can be generated using this command:
60+
61+
**With pytest**
5762

5863
```bash
5964
python -m pytest -r sa --mpl -n 4 --mpl-generate-path=tests/baseline
6065
```
6166

62-
Only include the actually modified baseline images in your PR! Running `git add
63-
-a` and the like will sometimes result in including images which are visually
64-
identically but not the same bit-wise.
67+
**With nox**
68+
69+
```bash
70+
nox -s generate_examples_figures
71+
```
72+
73+
Only include the actually modified baseline images in your PR! Running `git add -a` and the like will sometimes result in including images which are visually identically but not the same bit-wise.
74+
75+
### Linting and Formatting
76+
77+
We use `pre-commit` to manage code formatting and linting. Make sure to run it before committing your changes:
78+
79+
**With pre-commit**
80+
81+
```bash
82+
pre-commit run --all-files
83+
```
84+
85+
**With nox**
86+
87+
```bash
88+
nox -s lint
89+
```
90+
91+
## Contributing to the documentation
92+
93+
The documentation is built using [MkDocs](https://www.mkdocs.org/) and the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme. To contribute to the documentation, please look at the [`new_docs/CONTRIBUTING_DOC.md`](CONTRIBUTING_DOC.md) file for instructions.

new_docs/CONTRIBUTING.md renamed to new_docs/CONTRIBUTING_DOC.md

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
1-
# Style-Specific Guide Generation
1+
# Documentation
22

3-
This directory contains an automated system for generating a single `guide.md` file with tabs for each experiment style from a template.
3+
The documentation for `mplhep` is built using [MkDocs](https://www.mkdocs.org/) with the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme.
44

5-
## Overview
5+
To build the documentation locally, run the following command from the root directory of the repository:
6+
7+
**With MkDocs:**
8+
9+
Additional requirements for building the docs are listed in `new_docs/requirements_docs.txt` and can be installed via:
10+
11+
```bash
12+
pip install -r new_docs/requirements_docs.txt
13+
```
14+
Then run:
15+
16+
```bash
17+
mkdocs build # Builds the documentation into the site/ directory
18+
mkdocs serve # Serves the documentation locally
19+
```
20+
21+
**With Nox:**
22+
23+
```bash
24+
nox -s docs # Builds the documentation into the site/ directory
25+
nox -s docs -- --fast # Builds the documentation quickly without rendering code blocks (much faster building time)
26+
nox -s docs -- --serve (--fast) # Serves the documentation locally
27+
```
28+
29+
## Style-Specific Guide Generation
30+
31+
This directory contains an automated system for generating the documentation files with tabs for each experiment style from a template.
32+
33+
### Overview
634

735
Instead of manually maintaining separate guide files for each experiment style or manually maintaining one file with all the tabs, we use a template-based approach:
836

937
1. **Template Files**: `docs/*_template.md` contains the contents with tab placeholders ({{TABS_START}}/{{TABS_END}})
1038
2. **Generation Script**: `generate_style_guides.py` expands tabs with style-specific code for each experiment
1139
3. **MkDocs Hook**: `docs_hooks.py` automatically runs the script before each build
12-
4. **Generated Files**: Single `docs/*.md` without the `_template`, with tabs for CMS, ATLAS, LHCb, ALICE, DUNE, and plothist
40+
4. **Generated Files**: `docs/*.md` without the `_template`, with tabs for CMS, ATLAS, LHCb, ALICE, DUNE, and plothist
1341

14-
## Files
42+
### Files
1543

1644
- `docs/*_template.md` - Templates with `{{TABS_START}}/{{TABS_END}}` markers
1745
- `generate_style_guides.py` - Script to generate guide.md with experiment tabs
1846
- `docs_hooks.py` - MkDocs hook that runs the generation script automatically
1947

20-
## How It Works
48+
### How It Works
2149

22-
### Template Structure
50+
#### Template Structure
2351

2452
The template uses special markers to denote tabbed sections:
2553

@@ -42,7 +70,7 @@ The template uses special markers to denote tabbed sections:
4270

4371
This generates tabs for all 6 styles (CMS, ATLAS, LHCb, ALICE, DUNE, plothist).
4472

45-
### Placeholders
73+
#### Placeholders
4674

4775
Within tabbed sections, these placeholders get replaced per style:
4876

@@ -55,7 +83,7 @@ Within tabbed sections, these placeholders get replaced per style:
5583
- `{{LABEL_CODE_LUMI}}` - Label code with luminosity
5684
- `{{MAGIC_CODE}}` - mpl_magic() call if needed (ATLAS, ALICE only)
5785

58-
### Generation Script
86+
#### Generation Script
5987

6088
Run manually:
6189
```bash
@@ -66,41 +94,50 @@ python generate_style_guides.py
6694
python generate_style_guides.py --template my_template.md --output my_output/guide.md
6795
```
6896

69-
### Automatic Generation
97+
#### Automatic Generation
7098

7199
The MkDocs hook automatically runs the generation script before every build:
72100

101+
**With MkDocs:**
102+
73103
```bash
74104
mkdocs build # Guide is generated automatically
75105
mkdocs serve # Guide is generated on startup
76106
```
77107

78-
## Making Changes
108+
**With Nox:**
109+
110+
```bash
111+
nox -s docs # Guide is generated automatically
112+
nox -s docs -- --serve # Guide is generated on startup
113+
```
114+
115+
### Making Changes
79116

80-
### To update the templates:
117+
#### To update the templates:
81118

82119
1. Edit `docs/*_template.md`
83120
2. For content that should be the same across all styles, edit it directly
84121
3. For content that varies by style, use `{{TABS_START}}` ... `{{TABS_END}}` markers
85122
4. Test generation: `python generate_style_guides.py`
86-
5. Build docs: `mkdocs build` or `mkdocs serve`
123+
5. Build docs via MkDocs or Nox to see changes
87124
6. `docs/*.md` without the `_template` files will be regenerated automatically
88125

89-
### To add a new style:
126+
#### To add a new style:
90127

91128
1. Add style configuration to `generate_style_guides.py` in the `STYLES` dict
92129
2. Add the style name to `STYLE_ORDER` list
93130
3. Run the generation script
94131

95-
### To modify style-specific code:
132+
#### To modify style-specific code:
96133

97134
1. Edit the appropriate entry in the `STYLES` dict in `generate_style_guides.py`
98135
2. Regenerate: `python generate_style_guides.py`
99136

100-
## Example Template Usage
137+
### Example Template Usage
101138

102139
```markdown
103-
### Simple Example
140+
#### Simple Example
104141

105142
This shows a basic histogram with different styles:
106143

@@ -151,7 +188,7 @@ This generates:
151188
...
152189
```
153190

154-
## Benefits
191+
### Benefits
155192

156193
1. **Single Source of Truth**: Edit one template, update all style tabs
157194
2. **Consistency**: All style tabs have identical structure and examples
@@ -160,31 +197,31 @@ This generates:
160197
5. **Flexible**: Easy to add new styles or modify existing ones
161198
6. **Clean**: Template is much simpler than manually maintaining all tabs
162199

163-
## Troubleshooting
200+
### Troubleshooting
164201

165-
### Guide not updating
202+
#### Guide not updating
166203

167204
Make sure you're editing `docs/*_template.md`.
168205

169-
### Build errors
206+
#### Build errors
170207

171208
Check that all placeholders in the template are defined in the `STYLES` dict in `generate_style_guides.py`.
172209

173-
### Missing mpl_magic calls
210+
#### Missing mpl_magic calls
174211

175212
ATLAS and ALICE styles need `mh.mpl_magic(soft_fail=True)` after labels. This is handled automatically via the `MAGIC_CODE` placeholder which includes proper indentation.
176213

177-
### Testing changes
214+
#### Testing changes
178215

179216
Always test locally before committing:
180217
```bash
181218
python generate_style_guides.py
182-
mkdocs build
219+
mkdocs build / nox -s docs
183220
# Check the generated file
184221
less docs/guide.md
185222
```
186223

187-
### Manual regeneration
224+
#### Manual regeneration
188225

189226
If the hook doesn't run for some reason:
190227
```bash

new_docs/docs/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../CONTRIBUTING.md

new_docs/docs/CONTRIBUTING_DOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CONTRIBUTING_DOC.md

0 commit comments

Comments
 (0)