Skip to content

Commit 4ad3ef9

Browse files
authored
Merge pull request #155 from scipp/pre-commit-in-ci
Use pre-commit in ci
2 parents e144cc9 + 131ce05 commit 4ad3ef9

Some content is hidden

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

63 files changed

+263
-187
lines changed

.github/workflows/pr_and_main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
python-version: 3.8
2929
- run: python -m pip install --upgrade pip
30-
- run: python -m pip install -r requirements/static.txt
30+
- run: python -m pip install -r requirements/ci.txt
3131
- run: tox -e static
3232
- uses: stefanzweifel/git-auto-commit-action@v4
3333
with:

.pre-commit-config.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-json
7+
exclude: asv.conf.json
8+
- id: check-toml
9+
- id: check-yaml
10+
exclude: conda/meta.yaml
11+
- id: detect-private-key
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
args: [ --markdown-linebreak-ext=md ]
15+
exclude: '\.svg'
16+
- repo: https://github.com/pycqa/isort
17+
rev: 5.10.1
18+
hooks:
19+
- id: isort
20+
name: isort (python)
21+
- repo: https://github.com/pre-commit/mirrors-yapf
22+
rev: v0.32.0
23+
hooks:
24+
- id: yapf
25+
args: [ "-i", "-r" ]
26+
types: [ "python" ]
27+
additional_dependencies: [ "toml" ]
28+
- repo: https://github.com/kynan/nbstripout
29+
rev: 0.6.0
30+
hooks:
31+
- id: nbstripout
32+
types: [ "jupyter" ]
33+
args: [ "--drop-empty-cells",
34+
"--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'" ]
35+
- repo: https://github.com/pycqa/flake8
36+
rev: 4.0.1
37+
hooks:
38+
- id: flake8
39+
types: ["python"]
40+
additional_dependencies: ["flake8-bugbear==22.10.27"]
41+
- repo: https://github.com/pycqa/bandit
42+
rev: 1.7.4
43+
hooks:
44+
- id: bandit
45+
additional_dependencies: ["bandit[toml]"]
46+
args: ["-c", "pyproject.toml"]
47+
- repo: https://github.com/codespell-project/codespell
48+
rev: v2.2.2
49+
hooks:
50+
- id: codespell
51+
additional_dependencies:
52+
- tomli
53+
- repo: https://github.com/pre-commit/pygrep-hooks
54+
rev: v1.9.0
55+
hooks:
56+
- id: python-no-eval
57+
exclude: "object_list.py"
58+
- id: python-no-log-warn
59+
- id: python-use-type-annotations
60+
- id: rst-backticks
61+
- id: rst-directive-colons
62+
- id: rst-inline-touching-normal
63+
- id: text-unicode-replacement-char

docs/about/release-notes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Breaking changes
154154
* A major rewrite of the reflectometry code was undertaken `#61 <https://github.com/scipp/ess/pull/61>`_:
155155

156156
* The reflectometry and Amor Data classes were removed in favour of a formalism consisting of free-functions that accept Scipp DataArrays and Datasets.
157-
* Moved the chopper class from the `wfm` submodule to free functions in its own ``choppers`` module.
157+
* Moved the chopper class from the ``wfm`` submodule to free functions in its own ``choppers`` module.
158158
* The unit conversion (computing wavelength and Q) now use ``transform_coords``.
159159
* The Amor reduction notebook from ``ess-notebooks`` has been imported into the ``ess`` repository.
160160

docs/conf.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33

44
import doctest
5-
from datetime import date
6-
import ess
7-
85
import os
96
import sys
10-
7+
from datetime import date
118
from typing import Any, Dict, Optional
9+
10+
import sphinx_book_theme
1211
from docutils.nodes import document
1312
from sphinx.application import Sphinx
14-
import sphinx_book_theme
13+
14+
import ess
1515

1616
sys.path.insert(0, os.path.abspath('.'))
1717

docs/instruments/amor/amor_reduction.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@
611611
"metadata": {},
612612
"source": [
613613
"The reference is assumed to be a perfect scatterer, therefore where there is no reflectivity in the reference measurement is it taken to be a region of `'Q'` space that cannot be accessed by the instrument. \n",
614-
"This leads to the number of detectors feeding data into each $Q$-bin being variable, this is particularly noticable at low-$Q$, there there are only a few pixels detecting neutrons. \n",
614+
"This leads to the number of detectors feeding data into each $Q$-bin being variable, this is particularly noticeable at low-$Q$, there there are only a few pixels detecting neutrons. \n",
615615
"Therefore, in order to account for this variability as a function of $Q$, we mask those pixels (performed in `normalize_by_supermirror`) where no neutrons were detected and perform an average over the remaining `'detector_id'` to reduce the data. "
616616
]
617617
},
@@ -630,7 +630,7 @@
630630
"id": "d5b8ab01-4924-451e-95fb-a04365373c54",
631631
"metadata": {},
632632
"source": [
633-
"To obtain the final resolution, the three components of the resolution function are combined and multipled by the midpoints of the $Q$-bins. "
633+
"To obtain the final resolution, the three components of the resolution function are combined and multiplied by the midpoints of the $Q$-bins. "
634634
]
635635
},
636636
{

docs/instruments/loki/sans2d_reduction.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"# Custom SANS2D position offsets\n",
149149
"sample_pos_z_offset = 0.053 * sc.units.m\n",
150150
"bench_pos_y_offset = 0.001 * sc.units.m\n",
151-
"# There is some uncertainity here\n",
151+
"# There is some uncertainty here\n",
152152
"monitor4_pos_z_offset = -6.719 * sc.units.m\n",
153153
"\n",
154154
"# Geometry transformation\n",
@@ -189,7 +189,7 @@
189189
"The next step is to mask noisy and saturated pixels,\n",
190190
"as well as a time-of-flight range that contains spurious artifacts from the beamline components.\n",
191191
"\n",
192-
"**Note:** We use programatic masks here and not those stored in xml files.\n",
192+
"**Note:** We use programmatic masks here and not those stored in xml files.\n",
193193
"\n",
194194
"### Mask bad pixels\n",
195195
"\n",

docs/instruments/loki/sans2d_to_I_of_Q.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
"# Custom SANS2D position offsets\n",
175175
"sample_pos_z_offset = 0.053 * sc.units.m\n",
176176
"bench_pos_y_offset = 0.001 * sc.units.m\n",
177-
"# There is some uncertainity here\n",
177+
"# There is some uncertainty here\n",
178178
"monitor4_pos_z_offset = -6.719 * sc.units.m\n",
179179
"\n",
180180
"# Geometry transformation based on the found beam center position \n",
@@ -216,7 +216,7 @@
216216
"The next step is to mask noisy and saturated pixels,\n",
217217
"as well as a time-of-flight range that contains spurious artifacts from the beamline components.\n",
218218
"\n",
219-
"**Note:** We use programatic masks here and not those stored in xml files.\n",
219+
"**Note:** We use programmatic masks here and not those stored in xml files.\n",
220220
"\n",
221221
"### Mask bad pixels\n",
222222
"\n",

docs/techniques/reflectometry/reference.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Corrections
2121
corrections.normalize_by_counts
2222
corrections.beam_on_sample
2323

24-
IO
24+
IO
2525
--
2626

27-
.. autosummary::
27+
.. autosummary::
2828
:toctree: ../../generated
29-
30-
io.save_ort
29+
30+
io.save_ort

docs/techniques/wfm/reducing-wfm-data.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"\n",
105105
"For the events in both `sample` and `vanadium`,\n",
106106
"we define a wavelength for the neutrons as well as a birth time,\n",
107-
"which will be a random time between the pulse $t_0$ and the end of the useable pulse $t_0$ + pulse_length."
107+
"which will be a random time between the pulse $t_0$ and the end of the usable pulse $t_0$ + pulse_length."
108108
]
109109
},
110110
{

docs/version.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33

4-
import git
4+
import argparse
55
import sys
66
from typing import List
7-
from packaging.version import parse, Version, InvalidVersion
8-
import argparse
7+
8+
import git
9+
from packaging.version import InvalidVersion, Version, parse
910

1011

1112
def _get_releases() -> List[Version]:

pyproject.toml

+19-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ build-backend = "setuptools.build_meta"
77

88
[tool.setuptools_scm]
99

10+
[tool.bandit]
11+
# Excluding tests because bandit doesn't like `assert`.
12+
exclude_dirs = ["docs/conf.py", "docs/make_docs.py", "tests", "install", "tools"]
13+
14+
[tool.codespell]
15+
ignore-words-list = "elemt"
16+
skip = "./.git,./install,./build,./.tox,*/*_cache,*/.virtual_documents,*/.ipynb_checkpoints,*.pdf,*.svg"
17+
18+
[tool.isort]
19+
skip_gitignore = true
20+
line_length = 88
21+
multi_line_output = 2 # for compatibility with yapf
22+
23+
[tool.mypy]
24+
mypy_path = "src"
25+
ignore_missing_imports = true
26+
1027
[tool.pytest.ini_options]
1128
minversion = "7.0"
1229
testpaths = "tests"
@@ -22,8 +39,5 @@ filterwarnings = [
2239
'ignore:\n Sentinel is not a public part of the traitlets API:DeprecationWarning',
2340
'ignore:Keyword `trait` is deprecated in traitlets 5.0, use `value_trait` instead:DeprecationWarning',
2441
'ignore:Keyword `traits` is deprecated in traitlets 5.0, use `per_key_traits` instead:DeprecationWarning',
25-
'ignore:Passing None into shape arguments as an alias for ():DeprecationWarning',]
26-
27-
[tool.mypy]
28-
mypy_path = "src"
29-
ignore_missing_imports = true
42+
'ignore:Passing None into shape arguments as an alias for ():DeprecationWarning',
43+
]

requirements/static.in

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
flake8
2-
nbstripout
3-
toml
4-
tox
5-
yapf
1+
pre-commit

requirements/static.txt

+17-60
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,27 @@
1-
# SHA1:1ae14843fff4b22dd16da520170445443705c399
21
#
3-
# This file is autogenerated by pip-compile-multi
2+
# This file is autogenerated by pip-compile with python 3.8
43
# To update, run:
54
#
6-
# pip-compile-multi
5+
# pip-compile requirements/static.in
76
#
8-
attrs==22.2.0
9-
# via jsonschema
10-
cachetools==5.2.0
11-
# via tox
12-
chardet==5.1.0
13-
# via tox
14-
colorama==0.4.6
15-
# via tox
7+
cfgv==3.3.1
8+
# via pre-commit
169
distlib==0.3.6
1710
# via virtualenv
18-
fastjsonschema==2.16.2
19-
# via nbformat
2011
filelock==3.9.0
21-
# via
22-
# tox
23-
# virtualenv
24-
flake8==6.0.0
25-
# via -r requirements/static.in
26-
jsonschema==4.17.3
27-
# via nbformat
28-
jupyter-core==5.1.2
29-
# via nbformat
30-
mccabe==0.7.0
31-
# via flake8
32-
nbformat==5.7.1
33-
# via nbstripout
34-
nbstripout==0.6.1
35-
# via -r requirements/static.in
36-
packaging==22.0
37-
# via
38-
# pyproject-api
39-
# tox
12+
# via virtualenv
13+
identify==2.5.13
14+
# via pre-commit
15+
nodeenv==1.7.0
16+
# via pre-commit
4017
platformdirs==2.6.2
41-
# via
42-
# jupyter-core
43-
# tox
44-
# virtualenv
45-
pluggy==1.0.0
46-
# via tox
47-
pycodestyle==2.10.0
48-
# via flake8
49-
pyflakes==3.0.1
50-
# via flake8
51-
pyproject-api==1.2.1
52-
# via tox
53-
pyrsistent==0.19.3
54-
# via jsonschema
55-
toml==0.10.2
56-
# via -r requirements/static.in
57-
tomli==2.0.1
58-
# via
59-
# pyproject-api
60-
# tox
61-
tox==4.1.3
18+
# via virtualenv
19+
pre-commit==2.21.0
6220
# via -r requirements/static.in
63-
traitlets==5.8.0
64-
# via
65-
# jupyter-core
66-
# nbformat
21+
pyyaml==6.0
22+
# via pre-commit
6723
virtualenv==20.17.1
68-
# via tox
69-
yapf==0.32.0
70-
# via -r requirements/static.in
24+
# via pre-commit
25+
26+
# The following packages are considered to be unsafe in a requirements file:
27+
# setuptools

src/ess/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
except ImportError:
1010
__version__ = "0.0.0-unknown"
1111

12-
from .logging import get_logger
1312
from . import logging
13+
from .logging import get_logger

src/ess/amor/__init__.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
# flake8: noqa: F401
4-
from . import data
5-
from . import conversions
6-
from . import calibrations
7-
from . import normalize
8-
from . import resolution
9-
from .beamline import make_beamline, instrument_view_components
4+
from . import calibrations, conversions, data, normalize, resolution, tools
5+
from .beamline import instrument_view_components, make_beamline
106
from .instrument_view import instrument_view
117
from .load import load
12-
from . import tools

src/ess/amor/beamline.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
import scipp as sc
44
from scipp.constants import g
5+
56
from ..choppers import make_chopper
67
from ..logging import log_call
78

src/ess/amor/calibrations.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
import scipp as sc
4+
45
from ..reflectometry import orso
56

67

src/ess/amor/conversions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
import scipp as sc
4+
45
from ..reflectometry.conversions import specular_reflection as spec_relf_graph
56

67

src/ess/amor/instrument_view.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
import scipp as sc
4-
from scipp.plotting.objects import Plot
54
import scippneutron as scn
5+
from scipp.plotting.objects import Plot
6+
67
from .beamline import instrument_view_components
78

89

0 commit comments

Comments
 (0)