Skip to content

Commit 7815cdf

Browse files
committed
Fix Python linting issues and clean up obsolete files
Python code changes: - Convert Python 2 print statements to Python 3 print() functions - Fix syntax errors from incorrect backslash continuations - Sort imports with isort (black profile) - Preserve skeleton/exercise code as comments rather than fixing Linting configuration: - Add comprehensive ruff configuration in pyproject.toml with ignores for educational code patterns (star imports, single-letter variables, etc.) - Add isort configuration with black profile - Disable flake8 in pre-commit (redundant with ruff) - Add markdownlint configuration (.markdownlint.yaml) - Add markdownlint ignore file for build outputs Cleanup: - Remove reveal.js directories (no longer needed after slides removed) - Remove obsolete slide HTML files - Remove doc/Trash directory
1 parent 15c7a35 commit 7815cdf

3,614 files changed

Lines changed: 23945 additions & 188566 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.markdownlint.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# markdownlint configuration
2+
# See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
3+
4+
# MD013 - Line length (disabled - documentation often has long lines)
5+
MD013: false
6+
7+
# MD024 - Multiple headings with the same content (allowed for books)
8+
MD024: false
9+
10+
# MD033 - Inline HTML (allowed)
11+
MD033: false
12+
13+
# MD041 - First line should be a top-level heading (disabled for partial files)
14+
MD041: false
15+
16+
# MD046 - Code block style (allow both fenced and indented)
17+
MD046: false
18+
19+
# MD007 - Unordered list indentation
20+
MD007:
21+
indent: 2
22+
23+
# MD029 - Ordered list item prefix (allow any number)
24+
MD029:
25+
style: "one_or_ordered"
26+
27+
# MD060 - Table column style (disabled - formatting is matter of preference)
28+
MD060: false

.markdownlintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Vendored third-party libraries
2+
**/node_modules/
3+
4+
# Build outputs
5+
doc/pub/

.pre-commit-config.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# See https://pre-commit.com for more information
2+
default_stages: [pre-commit]
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v6.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/pycqa/isort
12+
rev: 7.0.0
13+
hooks:
14+
# Run isort to check only (don't modify files)
15+
- id: isort
16+
name: "Check imports are sorted"
17+
args: [--check-only, --filter-files]
18+
stages: [pre-commit]
19+
- repo: https://github.com/astral-sh/ruff-pre-commit
20+
# Ruff version.
21+
rev: v0.14.14
22+
hooks:
23+
# Run the linter to check only (don't modify files)
24+
- id: ruff-check
25+
name: "Check code is linted with ruff"
26+
# Disabled flake8 - ruff covers the same checks with better performance
27+
# - repo: https://github.com/PyCQA/flake8
28+
# rev: 7.3.0
29+
# hooks:
30+
# - id: flake8
31+
# name: "Check code is linted with flake8"
32+
# additional_dependencies: [flake8-pyproject]
33+
- repo: https://github.com/crate-ci/typos
34+
rev: v1.33.1
35+
hooks:
36+
- id: typos
37+
name: "Check files for typos"
38+
stages: [pre-commit]
39+
- repo: https://github.com/DavidAnson/markdownlint-cli2
40+
rev: v0.20.0
41+
hooks:
42+
- id: markdownlint-cli2
43+
name: "Check markdown files"
44+
stages: [pre-commit]
45+
#
46+
# These stages modify the files applying fixes where possible
47+
# Since this may be undesirable they will not run automatically
48+
# These stages can be run with
49+
# pre-commit run --hook-stage manual
50+
#
51+
- repo: https://github.com/pycqa/isort
52+
rev: 7.0.0
53+
hooks:
54+
# Run isort to check only (don't modify files)
55+
- id: isort
56+
name: "Fix imports with isort"
57+
args: [--filter-files]
58+
stages: [manual]
59+
- repo: https://github.com/astral-sh/ruff-pre-commit
60+
# Ruff version.
61+
rev: v0.14.14
62+
hooks:
63+
# Run the linter to check only (don't modify files)
64+
- id: ruff-check
65+
name: "Fix linting errors with ruff check --fix"
66+
args: [--fix]
67+
stages: [manual]
68+
- repo: https://github.com/crate-ci/typos
69+
rev: v1.33.1
70+
hooks:
71+
- id: typos
72+
name: "Fix typos"
73+
args: [-w]
74+
stages: [manual]
75+
- repo: https://github.com/DavidAnson/markdownlint-cli2
76+
rev: v0.20.0
77+
hooks:
78+
- id: markdownlint-cli2
79+
name: "Fix markdown files"
80+
args: [--fix]
81+
stages: [manual]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ bash make.sh
135135

136136
## Directory Structure
137137

138-
```
138+
```text
139139
devito_book/
140140
├── src/ # Source code for book examples
141141
│ └── X/ # Source code from chapter X
@@ -185,6 +185,7 @@ The build script automatically fixes encoding issues by converting from `utf8x`
185185
### Build Logs
186186

187187
Check these files for detailed error information:
188+
188189
- `book.log` - LaTeX compilation log
189190
- `book.dlog` - DocOnce processing log
190191

@@ -210,5 +211,6 @@ This work is licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/
210211
## Acknowledgments
211212

212213
This book is part of a series on computational science. See also:
214+
213215
- [A Primer on Scientific Programming with Python](https://github.com/hplgit/primer)
214216
- [Scaling of Differential Equations](https://github.com/hplgit/scaling-book)

doc/.src/book/scripts.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import sys, re, os, shutil, glob
1+
import glob
2+
import os
3+
import re
4+
import shutil
5+
import sys
26

3-
chapters = "vib wave diffu trunc nonlin advec softeng2 formulas".split()
7+
chapters = ["vib", "wave", "diffu", "trunc", "nonlin", "advec", "softeng2", "formulas"]
48
chaptersdir = 'chapters'
59

6-
ignored_files = '*.o *.so *.a *.pyc *.bak *.swp *~ .*~ *.old tmp* temp* .#* \\#* *.log *.dvi *.aux *.blg *.idx *.nav *.out *.toc *.snm *.vrb *.cproject *.project .DS_Store Trash'.split()
10+
ignored_files = ['*.o', '*.so', '*.a', '*.pyc', '*.bak', '*.swp', '*~', '.*~', '*.old', 'tmp*', 'temp*', '.#*', '\\#*', '*.log', '*.dvi', '*.aux', '*.blg', '*.idx', '*.nav', '*.out', '*.toc', '*.snm', '*.vrb', '*.cproject', '*.project', '.DS_Store', 'Trash']
711

812
def chapter_visitor(action=None, chapters=chapters):
913
"""Visit dirs in chapters and call/perform action."""
@@ -13,10 +17,11 @@ def chapter_visitor(action=None, chapters=chapters):
1317
# Wrap Unix commands and run
1418
def action_function():
1519
for command in action:
16-
print command
20+
print(command)
1721
failure = os.system(command)
1822
if failure:
19-
print 'failure in execution...'; sys.exit(1)
23+
print('failure in execution...')
24+
sys.exit(1)
2025
elif callable(action):
2126
action_function = action
2227

@@ -25,12 +30,12 @@ def action_function():
2530
for chapter in chapters:
2631
destination = os.path.join(prefix, chapter)
2732
if os.path.isdir(destination):
28-
print 'visiting directory', destination
33+
print('visiting directory', destination)
2934
os.chdir(destination)
3035
action_function()
3136
os.chdir(thisdir)
3237
else:
33-
print '\n*** error: directory %s does not exist!' % destination
38+
print('\n*** error: directory %s does not exist!' % destination)
3439
sys.exit(1)
3540

3641

@@ -60,13 +65,13 @@ def make_links(chapters=chapters):
6065
prefix = os.path.join(os.pardir, chaptersdir)
6166
for chapter in chapters:
6267
destination = os.path.join(prefix, chapter)
63-
subdirs = [tp + '-' + chapter for tp in 'fig', 'src', 'mov', 'exer']
68+
subdirs = [tp + '-' + chapter for tp in ('fig', 'src', 'mov', 'exer')]
6469
for subdir in subdirs:
6570
if not os.path.islink(subdir):
6671
dest_subdir = os.path.join(destination, subdir)
6772
if os.path.isdir(dest_subdir):
6873
os.symlink(dest_subdir, subdir)
69-
print 'created local link %s to %s' % (subdir, destination)
74+
print('created local link %s to %s' % (subdir, destination))
7075

7176
# Sometimes manual additions are needed here, e.g.,
7277
#os.symlink(os.path.join(prefix, 'tech', 'fig2'), 'fig2')
@@ -97,14 +102,14 @@ def pack_src(root='src', tarfile='book-examples.tar.gz', chapters=chapters):
97102
for file_spec in ignored_files:
98103
for filename in glob.glob(file_spec):
99104
os.remove(filename)
100-
print 'removed', 'src-%s/%s' % (chapter, filename)
105+
print('removed', 'src-%s/%s' % (chapter, filename))
101106
os.chdir(thisdir)
102107
# Copy files
103108
shutil.copytree(destination, chapter)
104-
print '\ndirectory tree with source code files for the book:', root
109+
print('\ndirectory tree with source code files for the book:', root)
105110
os.chdir(os.pardir)
106111
os.system('tar czf %s %s' % (tarfile, root))
107-
print 'tarfile:', tarfile
112+
print('tarfile:', tarfile)
108113

109114
def externaldocuments():
110115
# Find all candidate documents in ../chapters/*
@@ -124,13 +129,13 @@ def externaldocuments():
124129
other_mainfiles.remove(mainfile)
125130
# Strip off ../chapters to ../
126131
other_mainfiles = ['../' + mainfile[12:] for mainfile in mainfiles]
127-
f = open(mainfile + '.do.txt', 'r')
132+
f = open(mainfile + '.do.txt')
128133
text = f.read()
129134
f.close()
130135
text = re.sub('^# Externaldocuments:.*', '# Externaldocuments: ' +
131136
', '.join(other_mainfiles), text, flags=re.MULTILINE)
132-
print 'subst in', mainfile
137+
print('subst in', mainfile)
133138
f = open(mainfile + '.do.txt', 'w')
134139
f.write(text)
135140
f.close()
136-
print 'updated # Externaldocuments in', mainfile, 'with\n ', ', '.join(other_mainfiles)
141+
print('updated # Externaldocuments in', mainfile, 'with\n ', ', '.join(other_mainfiles))

0 commit comments

Comments
 (0)