Skip to content

Commit

Permalink
Add Pre-commit hooks (#23)
Browse files Browse the repository at this point in the history
* pre-commit hooks

* ruff formatting

* ignore E402, remove meta.yaml reference
  • Loading branch information
cyschneck authored May 10, 2024
1 parent f436dc0 commit 581f6d8
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 91 deletions.
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ci:
autofix_prs: false
autoupdate_schedule: monthly

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]

- repo: https://github.com/myint/docformatter # To format the doc strings to conform PEP257
rev: v1.7.5
hooks:
- id: docformatter
args: [--in-place]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/pre-commit/pre-commit-hooks # Some common pre-commit hooks
rev: v4.6.0
hooks:
- id: check-yaml # Checks the syntax of .yaml files.
args: [--allow-multiple-documents]
- id: end-of-file-fixer # Makes sure files end with a newline.
- id: trailing-whitespace # Checks for any tabs or spaces after the last non-whitespace character on the line.
- id: check-docstring-first # Checks that code comes after the docstrings.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

`make clean html`

`open _build/html/index.html`
`open _build/html/index.html`
2 changes: 1 addition & 1 deletion _static/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
footer {
color: black;
}
}
2 changes: 1 addition & 1 deletion applications/data_analysis/data_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Data Analysis
:maxdepth: 1
:hidden:

sample.ipynb
sample.ipynb
10 changes: 7 additions & 3 deletions applications/data_analysis/sample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"from matplotlib import rcParams, cycler\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.ion()"
]
},
Expand All @@ -73,9 +74,12 @@
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"custom_lines = [\n",
" Line2D([0], [0], color=cmap(0.0), lw=4),\n",
" Line2D([0], [0], color=cmap(0.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.0), lw=4),\n",
"]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
Expand Down
2 changes: 1 addition & 1 deletion applications/file_io/file_io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ File I/O
:maxdepth: 1
:hidden:

sample.ipynb
sample.ipynb
10 changes: 7 additions & 3 deletions applications/file_io/sample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"from matplotlib import rcParams, cycler\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.ion()"
]
},
Expand All @@ -73,9 +74,12 @@
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"custom_lines = [\n",
" Line2D([0], [0], color=cmap(0.0), lw=4),\n",
" Line2D([0], [0], color=cmap(0.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.0), lw=4),\n",
"]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
Expand Down
10 changes: 7 additions & 3 deletions applications/plot_types/contour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"from matplotlib import rcParams, cycler\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.ion()"
]
},
Expand All @@ -73,9 +74,12 @@
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"custom_lines = [\n",
" Line2D([0], [0], color=cmap(0.0), lw=4),\n",
" Line2D([0], [0], color=cmap(0.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.0), lw=4),\n",
"]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
Expand Down
2 changes: 1 addition & 1 deletion applications/plot_types/plot_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Plot Types
:maxdepth: 1
:hidden:

contour.ipynb
contour.ipynb
98 changes: 37 additions & 61 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
#
# -- Project information -----------------------------------------------------

import os
import sys
import pathlib
import yaml
from sphinx.application import Sphinx
from sphinx.util import logging
from textwrap import dedent, indent

print("sys.path:", sys.path)

Expand All @@ -28,12 +23,12 @@
# 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('.'))
# sys.path.insert(0, os.path.abspath('.'))

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

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -57,28 +52,11 @@
'processEscapes': True,
},
'HTML-CSS': {
'linebreaks': {
'automatic': True,
'width': 'container'
},
'fonts': {
'availableFonts': ['TeX'],
'preferredFont': 'TeX',
'webFont': 'TeX'
}
'linebreaks': {'automatic': True, 'width': 'container'},
'fonts': {'availableFonts': ['TeX'], 'preferredFont': 'TeX', 'webFont': 'TeX'},
},
'CommonHTML': {
'linebreaks': {
'automatic': True,
'width': 'container'
}
},
'SVG': {
'linebreaks': {
'automatic': True,
'width': 'container'
}
}
'CommonHTML': {'linebreaks': {'automatic': True, 'width': 'container'}},
'SVG': {'linebreaks': {'automatic': True, 'width': 'container'}},
}

mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
Expand Down Expand Up @@ -150,20 +128,19 @@
}

# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'GeoCAT-applications'
project = 'GeoCAT-applications'

import datetime

current_year = datetime.datetime.now().year
copyright = u'{}, University Corporation for Atmospheric Research'.format(
current_year)
author = u'GeoCAT'
copyright = '{}, University Corporation for Atmospheric Research'.format(current_year)
author = 'GeoCAT'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -174,9 +151,9 @@

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -185,18 +162,18 @@

# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand All @@ -205,10 +182,10 @@
# print(f'STYLES: {styles}')

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []

# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# keep_warnings = False

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand Down Expand Up @@ -236,16 +213,15 @@
use_repository_button=True,
use_issues_button=True,
home_page_in_toc=False,
extra_footer=
"<em>The National Center for Atmospheric Research is sponsored by the National Science Foundation. Any opinions, findings and conclusions or recommendations expressed in this material do not necessarily reflect the views of the National Science Foundation.</em>",
extra_footer="<em>The National Center for Atmospheric Research is sponsored by the National Science Foundation. Any opinions, findings and conclusions or recommendations expressed in this material do not necessarily reflect the views of the National Science Foundation.</em>",
)

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []


# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
Expand All @@ -265,64 +241,64 @@
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
# html_extra_path = []

# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
#html_last_updated_fmt = None
# html_last_updated_fmt = None

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}

# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True

# If false, no index is generated.
#html_use_index = True
# html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# html_file_suffix = None

# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
#html_search_language = 'en'
# html_search_language = 'en'

# A dictionary with options for the search language support, empty by default.
# 'ja' uses this config value.
# 'zh' user can custom change `jieba` dictionary path.
#html_search_options = {'type': 'default'}
# html_search_options = {'type': 'default'}

# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
#html_search_scorer = 'scorer.js'
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = 'geocat-applications-docs'
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dependencies:
- sphinx-book-theme
- myst-nb
- sphinx-design
- nbsphinx
- nbsphinx
Loading

0 comments on commit 581f6d8

Please sign in to comment.