Skip to content

Commit 2a4b808

Browse files
authored
Merge pull request #23 from ColmTalbot/formatting
Add auto-formatting and pre-commits
2 parents 795420e + 34b8693 commit 2a4b808

22 files changed

+619
-502
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# .git-blame-ignore-revs
2+
# add pre-commits
3+
73de5cd8b6c155d48ccd45e52449278e6c00657e

.pre-commit-config.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
repos:
2+
- repo: https://github.com/ambv/black
3+
rev: 22.10.0
4+
hooks:
5+
- id: black
6+
language_version: python3
7+
- repo: https://github.com/ambv/black
8+
rev: 22.10.0
9+
hooks:
10+
- id: black-jupyter
11+
language_version: python3
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.3.0
14+
hooks:
15+
- id: check-merge-conflict # prevent committing files with merge conflicts
16+
- repo: https://github.com/codespell-project/codespell
17+
rev: v2.2.2
18+
hooks:
19+
- id: codespell # Spellchecker
20+
args: [-L, "nd,hist", "--skip", "*.ipynb"]
21+
- repo: https://github.com/pre-commit/mirrors-isort
22+
rev: v5.10.1
23+
hooks:
24+
- id: isort # sort imports alphabetically and separates import into sections
25+
args: [-w=88, -m=3, --tc, -sp=setup.cfg ]
26+
- repo: local
27+
hooks:
28+
- id: flynt
29+
name: flynt
30+
entry: flynt
31+
args: [--fail-on-change]
32+
types: [python]
33+
language: python
34+
additional_dependencies:
35+
- flynt
36+
- repo: https://github.com/ColmTalbot/nbstrip
37+
rev: v0.1.1
38+
hooks:
39+
- id: nbstrip
40+
args: [-i, -v]

bin/generate_gamma_data.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
label_1 = f"{ell1}{m1}"
3131
for ell2, m2 in lms:
3232
label_2 = f"{ell2}{m2}"
33-
gammalmlm = np.array([
34-
angles.analytic_gamma((ell1, m1), (ell2, m2), ell)
35-
for ell in range(2, 21)
36-
])
33+
gammalmlm = np.array(
34+
[angles.analytic_gamma((ell1, m1), (ell2, m2), ell) for ell in range(2, 21)]
35+
)
3736
delta_m = m1 - m2
3837
new[str(delta_m)][label_1 + label_2] = np.real(gammalmlm)
3938
for key in new:

docs/conf.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#
1919
import os
2020
import sys
21+
2122
import gwmemory
22-
sys.path.insert(0, os.path.abspath('../'))
23+
24+
sys.path.insert(0, os.path.abspath("../"))
2325

2426
# -- General configuration ------------------------------------------------
2527

@@ -30,34 +32,39 @@
3032
# Add any Sphinx extension module names here, as strings. They can be
3133
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3234
# ones.
33-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.mathjax', 'numpydoc',
34-
'nbsphinx', 'sphinx.ext.autosummary']
35+
extensions = [
36+
"sphinx.ext.autodoc",
37+
"sphinx.ext.mathjax",
38+
"numpydoc",
39+
"nbsphinx",
40+
"sphinx.ext.autosummary",
41+
]
3542

3643
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
44+
templates_path = ["_templates"]
3845

3946
# The suffix(es) of source filenames.
4047
# You can specify multiple suffix as a list of string:
4148
#
42-
source_suffix = ['.rst', '.md', '.txt']
49+
source_suffix = [".rst", ".md", ".txt"]
4350
# source_suffix = '.txt'
4451

4552
# The master toctree document.
46-
master_doc = 'index'
53+
master_doc = "index"
4754

4855
# General information about the project.
49-
project = u'GWMemory'
50-
copyright = u'2018, Colm Talbot'
51-
author = u'Colm Talbot'
56+
project = "GWMemory"
57+
copyright = "2018, Colm Talbot"
58+
author = "Colm Talbot"
5259

5360

5461
# The version info for the project you're documenting, acts as replacement for
5562
# |version| and |release|, also used in various other places throughout the
5663
# built documents.
5764
#
5865
# The short X.Y version.
59-
fullversion = gwmemory.__version__.split(':')[0]
60-
version = '.'.join(fullversion.split('.')[:2])
66+
fullversion = gwmemory.__version__.split(":")[0]
67+
version = ".".join(fullversion.split(".")[:2])
6168
# The full version, including alpha/beta/rc tags.
6269
release = fullversion
6370

@@ -71,10 +78,10 @@
7178
# List of patterns, relative to source directory, that match files and
7279
# directories to ignore when looking for source files.
7380
# This patterns also effect to html_static_path and html_extra_path
74-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'requirements.txt']
81+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "requirements.txt"]
7582

7683
# The name of the Pygments (syntax highlighting) style to use.
77-
pygments_style = 'sphinx'
84+
pygments_style = "sphinx"
7885

7986
# If true, `todo` and `todoList` produce output, else they produce nothing.
8087
todo_include_todos = False
@@ -85,7 +92,7 @@
8592
# The theme to use for HTML and HTML Help pages. See the documentation for
8693
# a list of builtin themes.
8794
#
88-
html_theme = 'sphinx_rtd_theme'
95+
html_theme = "sphinx_rtd_theme"
8996

9097
# Theme options are theme-specific and customize the look and feel of a theme
9198
# further. For a list of options available for each theme, see the
@@ -96,28 +103,28 @@
96103
# Add any paths that contain custom static files (such as style sheets) here,
97104
# relative to this directory. They are copied after the builtin static files,
98105
# so a file named "default.css" will overwrite the builtin "default.css".
99-
html_static_path = ['_static']
106+
html_static_path = ["_static"]
100107

101108
# Custom sidebar templates, must be a dictionary that maps document names
102109
# to template names.
103110
#
104111
# This is required for the alabaster theme
105112
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
106113
html_sidebars = {
107-
'**': [
108-
'about.html',
109-
'navigation.html',
110-
'relations.html', # needs 'show_related': True theme option to display
111-
'searchbox.html',
112-
'donate.html',
114+
"**": [
115+
"about.html",
116+
"navigation.html",
117+
"relations.html", # needs 'show_related': True theme option to display
118+
"searchbox.html",
119+
"donate.html",
113120
]
114121
}
115122

116123

117124
# -- Options for HTMLHelp output ------------------------------------------
118125

119126
# Output file base name for HTML help builder.
120-
htmlhelp_basename = 'gwmemorydoc'
127+
htmlhelp_basename = "gwmemorydoc"
121128

122129

123130
# -- Options for LaTeX output ---------------------------------------------
@@ -126,15 +133,12 @@
126133
# The paper size ('letterpaper' or 'a4paper').
127134
#
128135
# 'papersize': 'letterpaper',
129-
130136
# The font size ('10pt', '11pt' or '12pt').
131137
#
132138
# 'pointsize': '10pt',
133-
134139
# Additional stuff for the LaTeX preamble.
135140
#
136141
# 'preamble': '',
137-
138142
# Latex figure (float) alignment
139143
#
140144
# 'figure_align': 'htbp',
@@ -144,19 +148,15 @@
144148
# (source start file, target name, title,
145149
# author, documentclass [howto, manual, or own class]).
146150
latex_documents = [
147-
(master_doc, 'gwmemory.tex', u'GWMemory Documentation',
148-
u'Colm Talbot', 'manual'),
151+
(master_doc, "gwmemory.tex", "GWMemory Documentation", "Colm Talbot", "manual"),
149152
]
150153

151154

152155
# -- Options for manual page output ---------------------------------------
153156

154157
# One entry per manual page. List of tuples
155158
# (source start file, name, description, authors, manual section).
156-
man_pages = [
157-
(master_doc, 'GWMemory', u'GWMemory Documentation',
158-
[author], 1)
159-
]
159+
man_pages = [(master_doc, "GWMemory", "GWMemory Documentation", [author], 1)]
160160

161161

162162
# -- Options for Texinfo output -------------------------------------------
@@ -165,9 +165,15 @@
165165
# (source start file, target name, title, author,
166166
# dir menu entry, description, category)
167167
texinfo_documents = [
168-
(master_doc, 'GWMemory', u'GWMemory Documentation',
169-
author, 'Colm Talbot', 'Arbitrary gravitational-wave memory waveforms.',
170-
'Miscellaneous'),
168+
(
169+
master_doc,
170+
"GWMemory",
171+
"GWMemory Documentation",
172+
author,
173+
"Colm Talbot",
174+
"Arbitrary gravitational-wave memory waveforms.",
175+
"Miscellaneous",
176+
),
171177
]
172178

173179
numpydoc_show_class_members = False

examples/Comparison.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,19 @@
105105
"for ii, mode in enumerate(modes):\n",
106106
" gwmem = h_mem[mode]\n",
107107
" sxsmem = h_mem_sxs[mode]\n",
108-
" overlap = np.vdot(gwmem, sxsmem) / np.vdot(gwmem, gwmem) ** 0.5 / np.vdot(sxsmem, sxsmem) ** 0.5\n",
108+
" overlap = (\n",
109+
" np.vdot(gwmem, sxsmem)\n",
110+
" / np.vdot(gwmem, gwmem) ** 0.5\n",
111+
" / np.vdot(sxsmem, sxsmem) ** 0.5\n",
112+
" )\n",
109113
"\n",
110114
" ax = axes[ii // 3, ii % 3]\n",
111115
" ax.plot(times, gwmem.real, label=\"GWMemory\")\n",
112116
" ax.plot(times_sxs, sxsmem.real, linestyle=\":\", label=\"SXS\")\n",
113117
" ax.annotate(f\"Mode: ({mode[0]}, {mode[1]})\", (0.03, 0.75), xycoords=\"axes fraction\")\n",
114-
" ax.annotate(f\"Mismatch: {1 - overlap.real:.1e}\", (0.35, 0.75), xycoords=\"axes fraction\")\n",
118+
" ax.annotate(\n",
119+
" f\"Mismatch: {1 - overlap.real:.1e}\", (0.35, 0.75), xycoords=\"axes fraction\"\n",
120+
" )\n",
115121
"axes[0, 0].legend(loc=\"lower left\")\n",
116122
"axes[-1, 0].set_xlabel(\"$t [M]$\")\n",
117123
"axes[-1, 1].set_xlabel(\"$t [M]$\")\n",

0 commit comments

Comments
 (0)