Skip to content

Commit abfbd15

Browse files
committed
Merge branch 'mcflugen/test-notebooks' of github.com:landlab/tutorials into mcflugen/test-notebooks
2 parents 0631985 + 2c0fd4d commit abfbd15

5 files changed

Lines changed: 156 additions & 68 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ install:
3535
- conda install landlab jupyter -c landlab
3636
- conda info -a && conda list
3737
script:
38-
- ./run_notebook.py **/*.ipynb --skip='*_unexpanded*' --skip='*intro*' --skip='flow*' --skip='fields*'
38+
- ./run_notebook.py **/*.ipynb --skip='*_unexpanded*' --skip='*intro*' --skip='flow*'
3939
virtualenv:
4040
system_site_packages: false

CONTRIBUTING.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Contributing to landlab tutorials
2+
3+
Thank you for contributing to the landlab tutorials! We appreciate
4+
your help as this is largely as volunteer effort! :heart: :heart: :heart:
5+
6+
# How to contribute
7+
8+
## Reporting Bugs
9+
10+
Before creating a bug report, please do at least a cursory check that the
11+
bug has not already been reported. If it has, add a comment to the existing
12+
issue instead of opening a new one.
13+
14+
### Submitting a Bug Report
15+
16+
Bugs are tracked as
17+
[GitHub issues](https://guides.github.com/features/issues/). After you've
18+
determined you've found a new bug, please open a
19+
[new issue](https://github.com/landlab/tutorials/issues).
20+
21+
Explain the problem and include additional details to help maintainers
22+
reproduce the problem. Here are some items that will make it easier
23+
to track down the source of the problem.
24+
25+
* **Use a clear and descriptive title** for the issue that identifies the
26+
problem.
27+
* **Describe the exact steps that reproduce the problem**.
28+
* **If possible, provide an example that demonstrates the step** as,
29+
for example, a bash script along with input files.
30+
* **Describe the behavior you are seeing after these steps**.
31+
* **Describe the behavior you expect to see after these steps**.
32+
33+
Additionally, the answers to the following questions about your run
34+
environment will be helpful.
35+
36+
* **Which version of landlab are you using?** This could be a specific
37+
git sha or a release number.
38+
* **What is he name and version of you OS?**
39+
* **What compiler are you using?**
40+
* **How did you build landlab (if using the development version)?**
41+
42+
43+
## Submitting Changes
44+
45+
:tada: Whoa! This is great! We love it when folks contibute code! :tada:
46+
47+
Changes to landlab tutorials should be submitted as
48+
[pull requests](http://help.github.com/pull-requests/)).
49+
50+
* Create a GitHub issue that describes what you propose to do.
51+
* Create a topic branch that contains your changes.
52+
* Open a new [GitHub pull request](https://github.com/landlab/tutorials/pull/new/master).
53+
* Ensure the PR description clearly describes the problem and solution.
54+
Include the relevant issue number.
55+
56+
## Styleguides
57+
58+
Use the [PEP8 style guide](https://www.python.org/dev/peps/pep-0008/).
59+
You may want to use tools like
60+
[Prospector](http://prospector.landscape.io/en/master/) to help out
61+
with this.
62+
63+
### Git Commit Messages
64+
65+
* Use the present tense ("Add feature" not "Added feature")
66+
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
67+
* Limit the first line to 72 characters or less
68+
* Reference issues and pull requests liberally
69+
* Consider starting the commit message with an applicable emoji:
70+
* :art: `:art:` when improving the format/structure of the code
71+
* :racehorse: `:racehorse:` when improving performance
72+
* :non-potable_water: `:non-potable_water:` when plugging memory leaks
73+
* :memo: `:memo:` when writing docs
74+
* :penguin: `:penguin:` when fixing something on Linux
75+
* :apple: `:apple:` when fixing something on macOS
76+
* :checkered_flag: `:checkered_flag:` when fixing something on Windows
77+
* :bug: `:bug:` when fixing a bug
78+
* :fire: `:fire:` when removing code or files
79+
* :green_heart: `:green_heart:` when fixing the CI build
80+
* :white_check_mark: `:white_check_mark:` when adding tests
81+
* :shirt: `:shirt:` when removing linter warnings
82+
83+
## Adding new tutorials
84+
85+
If you would like to create a new tutorial that we have just a few
86+
conventions that we would like you to follow.
87+
88+
* Create a new folder that will hold your tutorial notebook
89+
and data used by your tutorial.
90+
* Start with the blank tutorial template provided in this repository.
91+
* Notice that your first cell of code should import `print_function`
92+
from `__future__`. Your tutorial will need to be compatible with
93+
both Python 2.7 and 3.4+.
94+
* If you will be plotting anything, be sure to use include ipython
95+
magic command in the first cell to indicate how plots should
96+
be rendered.
97+
* Your tutorial must be able to run without error for the **most
98+
recent landlab release**.
99+
100+
Thanks! :heart: :heart: :heart:
101+
102+
The landlab team

fields/working_with_fields.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@
171171
"name": "stdout",
172172
"output_type": "stream",
173173
"text": [
174-
"ERROR: The field already exists.\n"
174+
"ERROR: This field name already exists!\n"
175175
]
176176
}
177177
],
178178
"source": [
179179
"try:\n",
180180
" no_1c = mg.add_field('node', 'field__number_one', input_array, copy=False, units='m')\n",
181181
"except FieldError:\n",
182-
" print('ERROR: The field already exists.')"
182+
" print('ERROR: This field name already exists!')"
183183
]
184184
},
185185
{

run_notebook.py

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,45 @@ def run_notebook(notebook):
4444
os.remove(script_file)
4545

4646

47+
def print_summary(summary):
48+
print('-' * 70)
49+
for notebook, result in summary:
50+
if result is None:
51+
status('SKIP: ' + notebook)
52+
elif result:
53+
success(notebook)
54+
else:
55+
error(notebook)
56+
print('-' * 70)
57+
58+
59+
def print_success_or_failure(summary):
60+
failures = [name for name, result in summary if result is False]
61+
passes = [name for name, result in summary if result is True]
62+
63+
if failures:
64+
print('FAILED (failures={nfails})'.format(nfails=len(failures)))
65+
else:
66+
print('OK Ran {ntests} tests'.format(ntests=len(passes)))
67+
68+
return len(failures)
69+
70+
71+
def check_notebook(notebook):
72+
try:
73+
run_notebook(notebook)
74+
except subprocess.CalledProcessError:
75+
return False
76+
else:
77+
return True
78+
79+
4780
def main():
4881
import argparse
4982
parser = argparse.ArgumentParser()
5083
parser.add_argument('notebook', type=str, nargs='+',
5184
help='Notebook to test.')
52-
parser.add_argument('--skip', type=str, action='append',
85+
parser.add_argument('--skip', type=str, action='append', default=[],
5386
help='Notebooks to skip.')
5487

5588
args = parser.parse_args()
@@ -61,38 +94,14 @@ def main():
6194
summary = []
6295
for notebook in args.notebook:
6396
if notebook in skip:
64-
summary.append((notebook, 'SKIP'))
65-
status('SKIP: ' + notebook)
97+
result = notebook, None
6698
else:
67-
try:
68-
run_notebook(notebook)
69-
except subprocess.CalledProcessError:
70-
summary.append((notebook, 'FAIL'))
71-
error(notebook)
72-
else:
73-
summary.append((notebook, 'PASS'))
74-
success(notebook)
75-
76-
print('-' * 70)
77-
print('Summary:')
78-
for notebook, result in summary:
79-
if result == 'FAIL':
80-
error(notebook)
81-
elif result == 'PASS':
82-
success(notebook)
83-
elif result == 'SKIP':
84-
status('SKIP: ' + notebook)
85-
print('-' * 70)
86-
87-
failures = [name for name, result in summary if result == 'FAIL']
88-
passes = [name for name, result in summary if result == 'PASS']
99+
result = notebook, check_notebook(notebook)
100+
print_summary([result])
101+
summary.append(result)
89102

90-
if failures:
91-
print('FAILED (failures={nfails})'.format(nfails=len(failures)))
92-
else:
93-
print('OK Ran {ntests} tests'.format(ntests=len(passes)))
94-
95-
return len(failures)
103+
print_summary(summary)
104+
return print_success_or_failure(summary)
96105

97106

98107
if __name__ == '__main__':

tutorial_template.ipynb

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {
6-
"deletable": true,
7-
"editable": true
8-
},
5+
"metadata": {},
96
"source": [
107
"<a href=\"http://landlab.github.io\"><img style=\"float: left\" src=\"https://raw.githubusercontent.com/landlab/tutorials/master/landlab_header.png\"></a>\n"
118
]
129
},
1310
{
1411
"cell_type": "markdown",
15-
"metadata": {
16-
"deletable": true,
17-
"editable": true
18-
},
12+
"metadata": {},
1913
"source": [
2014
"# Using the Landlab flexure component\n",
2115
"\n",
@@ -32,10 +26,7 @@
3226
},
3327
{
3428
"cell_type": "markdown",
35-
"metadata": {
36-
"deletable": true,
37-
"editable": true
38-
},
29+
"metadata": {},
3930
"source": [
4031
"A bit of magic so that we can plot within this notebook."
4132
]
@@ -44,22 +35,17 @@
4435
"cell_type": "code",
4536
"execution_count": null,
4637
"metadata": {
47-
"collapsed": true,
48-
"deletable": true,
49-
"editable": true
38+
"collapsed": true
5039
},
5140
"outputs": [],
5241
"source": [
53-
"%matplotlib auto\n",
54-
"import numpy as np"
42+
"from __future__ import print_function\n",
43+
"%matplotlib inline"
5544
]
5645
},
5746
{
5847
"cell_type": "markdown",
59-
"metadata": {
60-
"deletable": true,
61-
"editable": true
62-
},
48+
"metadata": {},
6349
"source": [
6450
"## This\n",
6551
"\n",
@@ -68,10 +54,7 @@
6854
},
6955
{
7056
"cell_type": "markdown",
71-
"metadata": {
72-
"deletable": true,
73-
"editable": true
74-
},
57+
"metadata": {},
7558
"source": [
7659
"## That\n",
7760
"\n",
@@ -80,10 +63,7 @@
8063
},
8164
{
8265
"cell_type": "markdown",
83-
"metadata": {
84-
"deletable": true,
85-
"editable": true
86-
},
66+
"metadata": {},
8767
"source": [
8868
"## The other thing\n",
8969
"\n",
@@ -92,10 +72,7 @@
9272
},
9373
{
9474
"cell_type": "markdown",
95-
"metadata": {
96-
"deletable": true,
97-
"editable": true
98-
},
75+
"metadata": {},
9976
"source": [
10077
"### Click here for more <a href=\"https://github.com/landlab/landlab/wiki/Tutorials\">Landlab tutorials</a>"
10178
]
@@ -121,5 +98,5 @@
12198
}
12299
},
123100
"nbformat": 4,
124-
"nbformat_minor": 0
101+
"nbformat_minor": 1
125102
}

0 commit comments

Comments
 (0)