Skip to content

Commit

Permalink
Add noxfile for routine project maintenance (landlab#1469)
Browse files Browse the repository at this point in the history
* add a nox config file

* add nox as a dev requirement

* use nox for docs and lint workflows

* remove old make_changelog.py script

* remove lint from previously unlinted files

* add news fragment

* update black to 22.6.0 for pre-commit

* remove .so files when cleaning

* add towncrier folder for building docs

* add sphinx-jinja as a doc requirement

* style notebooks for black

* disable towncrier for linting; it's done elsewhere
  • Loading branch information
mcflugen authored Aug 13, 2022
1 parent 5c93da5 commit 7bffb6c
Show file tree
Hide file tree
Showing 29 changed files with 188 additions and 232 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ jobs:
- name: Show conda installation info
run: |
conda info
conda list
- name: Install dependencies
run: pip install -e ".[docs]"
run: pip install nox

- name: Build documentation
run: make -C docs clean html
run: nox -s docs
4 changes: 2 additions & 2 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:

- name: Lint
run: |
pip install flake8
flake8 landlab tests
pip install nox
nox -s lint
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.6.0
hooks:
- id: black
name: black
Expand Down
1 change: 0 additions & 1 deletion docs/build_func_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'''
"""
import re
from copy import copy

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion docs/build_grid_func_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Any changes made directly to the above files will be lost whenever this script
is run.
"""
import re
from copy import copy

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion docs/fix_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
with open("build/linkcheck/output.txt", "r") as f:
link_out = f.readlines()

#%%

for link in link_out:
if "redirected" in link:
file_name = os.path.join(_SRC, link.split(":")[0])
Expand Down
1 change: 0 additions & 1 deletion docs/landlab_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class LandlabLexer(RegexLexer):


def doctree_read(app, doctree):
env = app.builder.env
for node in doctree.traverse(addnodes.productionlist):
for production in node:
if not isinstance(production, addnodes.production):
Expand Down
13 changes: 3 additions & 10 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@

import os
import pathlib
import sys
from datetime import date

import landlab

docs_dir = os.path.dirname(__file__)

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
# os.pardir)))
sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, ".")

# -- General configuration -----------------------------------------------------

Expand All @@ -44,6 +35,7 @@
"sphinx.ext.napoleon",
"sphinx.ext.autosummary",
"sphinxcontrib.towncrier",
"sphinx_jinja",
]

if os.getenv("READTHEDOCS"):
Expand Down Expand Up @@ -370,4 +362,5 @@

towncrier_draft_autoversion_mode = "draft" # or: 'sphinx-release', 'sphinx-version'
towncrier_draft_include_empty = True
towncrier_draft_working_directory = pathlib.Path(docs_dir).parent.parent
# towncrier_draft_working_directory = pathlib.Path(docs_dir).parent.parent
towncrier_draft_working_directory = pathlib.Path(docs_dir).parent / "towncrier"
1 change: 1 addition & 0 deletions docs/towncrier/news
1 change: 1 addition & 0 deletions docs/towncrier/pyproject.toml
3 changes: 3 additions & 0 deletions news/1469.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added a *nox* file to help with routine project maintenance tasks like, for
example, running the tests, and checking for coding style.

1 change: 0 additions & 1 deletion notebooks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pathlib

import pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
" mg1,\n",
" number_of_watersheds=3,\n",
" main_channel_only=True,\n",
" minimum_channel_threshold=dxy ** 2,\n",
" minimum_channel_threshold=dxy**2,\n",
")\n",
"prf.run_one_step()\n",
"\n",
Expand Down Expand Up @@ -702,7 +702,7 @@
" mg2,\n",
" number_of_watersheds=3,\n",
" main_channel_only=True,\n",
" minimum_channel_threshold=dxy ** 2,\n",
" minimum_channel_threshold=dxy**2,\n",
")\n",
"prf2.run_one_step()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@
"## Assign storm conditions based on flag in Code Block 2\n",
"if storm_flag == \"Base\":\n",
" starting_precip_mmhr = 5.0\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10 ** -7)\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10**-7)\n",
" storm_duration = 7200.0\n",
"elif storm_flag == \"HigherIntensity\":\n",
" starting_precip_mmhr = 10.0\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10 ** -7)\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10**-7)\n",
" storm_duration = 3600.0\n",
"elif storm_flag == \"LongerDuration\":\n",
" starting_precip_mmhr = 2.5\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10 ** -7)\n",
" starting_precip_ms = starting_precip_mmhr * (2.77778 * 10**-7)\n",
" storm_duration = 14400.0"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"\n",
" # Death\n",
" if self.energy < 0:\n",
" #self.model.grid._remove_agent(self.pos, self)\n",
" # self.model.grid._remove_agent(self.pos, self)\n",
" self.model.grid.remove_agent(self)\n",
" self.model.schedule.remove(self)\n",
" living = False\n",
Expand Down Expand Up @@ -256,13 +256,13 @@
" self.energy += self.model.wolf_gain_from_food\n",
"\n",
" # Kill the sheep\n",
" #self.model.grid._remove_agent(self.pos, sheep_to_eat)\n",
" # self.model.grid._remove_agent(self.pos, sheep_to_eat)\n",
" self.model.grid.remove_agent(sheep_to_eat)\n",
" self.model.schedule.remove(sheep_to_eat)\n",
"\n",
" # Death or reproduction\n",
" if self.energy < 0:\n",
" #self.model.grid._remove_agent(self.pos, self)\n",
" # self.model.grid._remove_agent(self.pos, self)\n",
" self.model.grid.remove_agent(self)\n",
" self.model.schedule.remove(self)\n",
" else:\n",
Expand Down
6 changes: 3 additions & 3 deletions notebooks/tutorials/data_record/DataRecord_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@
" for i in range(0, dr_3.number_of_items):\n",
" # value of block erodibility:\n",
" if dr_3.dataset[\"boulder_litho\"].values[i] == \"limestone\":\n",
" k_b = 10 ** -5\n",
" k_b = 10**-5\n",
" elif dr_3.dataset[\"boulder_litho\"].values[i] == \"sandstone\":\n",
" k_b = 3 * 10 ** -6\n",
" k_b = 3 * 10**-6\n",
" elif dr_3.dataset[\"boulder_litho\"].values[i] == \"granite\":\n",
" k_b = 3 * 10 ** -7\n",
" k_b = 3 * 10**-7\n",
" else:\n",
" print(\"Unknown boulder lithology\")\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"mg3 = RasterModelGrid((10, 10))\n",
"_ = mg3.add_field(\n",
" \"topographic__elevation\",\n",
" mg3.x_of_node ** 2 + mg3.y_of_node ** 2 + mg3.y_of_node,\n",
" mg3.x_of_node**2 + mg3.y_of_node**2 + mg3.y_of_node,\n",
" at=\"node\",\n",
")\n",
"surf_plot(mg3, title=\"Grid 3: A more complicated surface\")"
Expand Down Expand Up @@ -448,7 +448,7 @@
"mg3a = RasterModelGrid((10, 10))\n",
"_ = mg3a.add_field(\n",
" \"topographic__elevation\",\n",
" mg3a.x_of_node ** 2 + mg3a.y_of_node ** 2 + mg3a.y_of_node,\n",
" mg3a.x_of_node**2 + mg3a.y_of_node**2 + mg3a.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -476,7 +476,7 @@
"mg3b = RasterModelGrid((10, 10))\n",
"_ = mg3b.add_field(\n",
" \"topographic__elevation\",\n",
" mg3b.x_of_node ** 2 + mg3b.y_of_node ** 2 + mg3b.y_of_node,\n",
" mg3b.x_of_node**2 + mg3b.y_of_node**2 + mg3b.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -504,7 +504,7 @@
"mg3c = RasterModelGrid((10, 10))\n",
"_ = mg3c.add_field(\n",
" \"topographic__elevation\",\n",
" mg3c.x_of_node ** 2 + mg3c.y_of_node ** 2 + mg3c.y_of_node,\n",
" mg3c.x_of_node**2 + mg3c.y_of_node**2 + mg3c.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand All @@ -530,7 +530,7 @@
"mg3d = RasterModelGrid((10, 10))\n",
"_ = mg3d.add_field(\n",
" \"topographic__elevation\",\n",
" mg3d.x_of_node ** 2 + mg3d.y_of_node ** 2 + mg3d.y_of_node,\n",
" mg3d.x_of_node**2 + mg3d.y_of_node**2 + mg3d.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand All @@ -556,7 +556,7 @@
"mg3e = RasterModelGrid((10, 10))\n",
"_ = mg3e.add_field(\n",
" \"topographic__elevation\",\n",
" mg3e.x_of_node ** 2 + mg3e.y_of_node ** 2 + mg3e.y_of_node,\n",
" mg3e.x_of_node**2 + mg3e.y_of_node**2 + mg3e.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -592,7 +592,7 @@
"mg3 = RasterModelGrid((10, 10))\n",
"_ = mg3.add_field(\n",
" \"topographic__elevation\",\n",
" mg3.x_of_node ** 2 + mg3.y_of_node ** 2 + mg3.y_of_node,\n",
" mg3.x_of_node**2 + mg3.y_of_node**2 + mg3.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -639,7 +639,7 @@
"mg3 = RasterModelGrid((10, 10))\n",
"_ = mg3.add_field(\n",
" \"topographic__elevation\",\n",
" mg3.x_of_node ** 2 + mg3.y_of_node ** 2 + mg3.y_of_node,\n",
" mg3.x_of_node**2 + mg3.y_of_node**2 + mg3.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -669,7 +669,7 @@
"mg3 = RasterModelGrid((10, 10))\n",
"_ = mg3.add_field(\n",
" \"topographic__elevation\",\n",
" mg3.x_of_node ** 2 + mg3.y_of_node ** 2 + mg3.y_of_node,\n",
" mg3.x_of_node**2 + mg3.y_of_node**2 + mg3.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down Expand Up @@ -697,7 +697,7 @@
"mg3 = RasterModelGrid((10, 10))\n",
"_ = mg3.add_field(\n",
" \"topographic__elevation\",\n",
" mg3.x_of_node ** 2 + mg3.y_of_node ** 2 + mg3.y_of_node,\n",
" mg3.x_of_node**2 + mg3.y_of_node**2 + mg3.y_of_node,\n",
" at=\"node\",\n",
")\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"surf_plot(mg, title=\"Grid 1\")"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"surf_plot(mg, title=\"Grid 1\")"
]
Expand Down Expand Up @@ -305,7 +305,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"D4\")\n",
"fa.run_one_step()\n",
Expand All @@ -328,7 +328,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Rho8\")\n",
"fa.run_one_step()\n",
Expand All @@ -351,7 +351,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Rho4\")\n",
"fa.run_one_step()\n",
Expand All @@ -374,7 +374,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Quinn\")\n",
"fa.run_one_step()\n",
Expand All @@ -397,9 +397,11 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(\n",
" mg, surface=\"topographic__elevation\", flow_metric=\"Freeman\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Freeman\")\n",
"fa.run_one_step()\n",
"plt.figure()\n",
"drainage_plot(mg, \"surface_water__discharge\", title=\"Discharge\")"
Expand All @@ -420,9 +422,11 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(\n",
" mg, surface=\"topographic__elevation\", flow_metric=\"Holmgren\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Holmgren\")\n",
"fa.run_one_step()\n",
"plt.figure()\n",
"drainage_plot(mg, \"surface_water__discharge\", title=\"Discharge\")"
Expand All @@ -443,7 +447,7 @@
"source": [
"mg = RasterModelGrid((10, 10))\n",
"_ = mg.add_field(\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node ** 2 + mg.y_of_node ** 2, at=\"node\"\n",
" \"topographic__elevation\", 3.0 * mg.x_of_node**2 + mg.y_of_node**2, at=\"node\"\n",
")\n",
"fa = PriorityFloodFlowRouter(mg, surface=\"topographic__elevation\", flow_metric=\"Dinf\")\n",
"fa.run_one_step()\n",
Expand Down
Loading

0 comments on commit 7bffb6c

Please sign in to comment.