Skip to content

Commit d2e8bac

Browse files
mkuehbachatomprobe-tcphyy-nx
authored
Consistent styling, formatting, and linting for all python code in the repo (#1626)
* bump version for isort, include all python source code files in styling, formatting, and linting, add precommit script * Update README with linting tools details Added information about linting tools used in the project. --------- Co-authored-by: mkuehbach <markus.kuehbach@physik.hu-berlin.de> Co-authored-by: Aaron S. Brewster <asbrewster@lbl.gov>
1 parent 5173e44 commit d2e8bac

27 files changed

Lines changed: 380 additions & 282 deletions

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 26.3.1
4+
hooks:
5+
- id: black
6+
7+
- repo: https://github.com/pycqa/flake8
8+
rev: 7.3.0
9+
hooks:
10+
- id: flake8
11+
12+
- repo: https://github.com/pycqa/isort
13+
rev: 8.0.0
14+
hooks:
15+
- id: isort
16+
17+
# - repo: https://github.com/streetsidesoftware/cspell-cli
18+
# rev: v9.7.0
19+
# hooks:
20+
# - id: cspell # spellchecking
21+
# pass_filenames: false
22+
# args:
23+
# - --config
24+
# - cspell.json
25+
# - applications/**/*
26+
# - base_classes/**/*
27+
# - contributed_definitions/**/*

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ install ::
4747
$(PYTHON) -m pip install -r requirements.txt
4848

4949
style ::
50-
$(PYTHON) -m black --check dev_tools
51-
$(PYTHON) -m flake8 dev_tools
52-
$(PYTHON) -m isort --check dev_tools
50+
$(PYTHON) -m black --check .
51+
$(PYTHON) -m flake8 .
52+
$(PYTHON) -m isort --check .
5353

5454
autoformat ::
55-
$(PYTHON) -m black dev_tools
56-
$(PYTHON) -m isort dev_tools
55+
$(PYTHON) -m black .
56+
$(PYTHON) -m isort .
5757

5858
test ::
5959
$(PYTHON) -m pytest dev_tools

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ to be made before commiting the change:
1313
1. check whether the change does not violate any syntax rules
1414
2. verify whether the change looks as intended in the HTML documentation
1515

16-
First install the test and build requirements with this command (only run once)
16+
First install the test and build requirements with this command (only run once). This will install linting tools such as black and flake8 as well.
1717

1818
make install
1919

@@ -75,4 +75,8 @@ package/ | directory for packaging this content
7575
utils/ | various tools used in the definitions tree
7676
www/ | launch (home) page of NeXus WWW site
7777
xslt/ | various XML stylesheet transformations
78-
dev_tools/ | developer tools for testing and building
78+
dev_tools/ | developer tools for testing and building
79+
80+
## Linting
81+
82+
We use flake8 and black for linting our Python code. When running `git commit` these tools will automatically apply formatting.

applications/stress/gauge_volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
import numpy as np
32

43
import matplotlib.pyplot as plt
4+
import numpy as np
55
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
66

77
fig = plt.figure(figsize=(10, 10))

galleries/nxdata/plot_hist1d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
x = [0.5, 1.5, 2.5, 4, 5, 6.5, 7, 8]
3636
y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6]
3737

38+
import matplotlib.pyplot as plt # noqa E402
39+
3840
# Plot
3941
import numpy as np # noqa E402
40-
import matplotlib.pyplot as plt # noqa E402
4142

4243
plt.style.use("_mpl-gallery")
4344

0 commit comments

Comments
 (0)