Skip to content

Commit 8fc5452

Browse files
committed
Use pyproject.toml for isort and black
1 parent 48e5ea1 commit 8fc5452

34 files changed

+339
-817
lines changed

dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ sphinx_rtd_theme >= 0.4
77
pytest >= 6,<8
88
flaky >= 3,<4
99
black
10+
isort
1011
wheel

docs/conf.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616
#
1717
import os
1818
import sys
19+
1920
import matplotlib
2021

2122
matplotlib.use("agg") # required for Readthedocs
2223

2324
currentpath = os.path.dirname(__file__)
2425
sys.path.append(os.path.join(currentpath, ".."))
2526

26-
import iris
27-
28-
# -- General configuration ------------------------------------------------
29-
3027
# If your documentation needs a minimal Sphinx version, state it here.
3128
#
3229
# needs_sphinx = '1.5'
3330
from datetime import datetime
31+
3432
import alabaster
33+
import iris
34+
35+
# -- General configuration ------------------------------------------------
36+
3537

3638
year = datetime.now().year
3739

example_plugins/example1.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
==============
55
"""
66

7-
from iris import AbstractRawDataset, ExperimentalParameter
87
import numpy as np
8+
from iris import AbstractRawDataset, ExperimentalParameter
99

1010

1111
class MinimalRawDataset(AbstractRawDataset):
@@ -33,9 +33,7 @@ def __init__(self, source=None, metadata=dict()):
3333
# Metadata can be filled as a dictionary before
3434
# initialization. # Attributes which are not
3535
# ExperimentalParameters are ignored.
36-
metadata.update(
37-
{"temperature": 100, "exposure": 1, "this_will_be_ignored": True}
38-
)
36+
metadata.update({"temperature": 100, "exposure": 1, "this_will_be_ignored": True})
3937
super().__init__(source, metadata)
4038

4139
# Metadata can also be changed attribute by attribute

installer/build.py

+14-28
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
Inspired from the Spyder installer script:
66
https://github.com/spyder-ide/spyder/tree/master/installers/Windows
77
"""
8-
from pathlib import Path
9-
import sys
10-
import subprocess
11-
from functools import wraps
12-
import logging
13-
import tempfile
8+
import argparse
149
import importlib.util as iutil
10+
import logging
1511
import shutil
16-
import argparse
12+
import subprocess
13+
import sys
14+
import tempfile
15+
from functools import wraps
16+
from pathlib import Path
1717

1818
logging.basicConfig(encoding="utf-8", level=logging.INFO)
1919

@@ -45,9 +45,7 @@
4545
directory=build/nsis/
4646
"""
4747

48-
parser = argparse.ArgumentParser(
49-
prog="build.py", description="Iris Windows installer build script."
50-
)
48+
parser = argparse.ArgumentParser(prog="build.py", description="Iris Windows installer build script.")
5149
parser.add_argument(
5250
"exe_name",
5351
metavar="TARGET",
@@ -108,22 +106,14 @@ def generate_pynsist_config(python_exe, filename, exe_name):
108106
freeze = check_output(f"{python_exe} -m pip freeze --all").decode("latin1")
109107
# PyQt5/PyQt5-sip requirements are baked in the template string
110108
requirements = [
111-
line
112-
for line in freeze.splitlines()
113-
if package_name(line) not in {"iris-ued", "PyQt5", "PyQt5-sip"}
109+
line for line in freeze.splitlines() if package_name(line) not in {"iris-ued", "PyQt5", "PyQt5-sip"}
114110
]
115111
packages = [package_name(p) for p in requirements]
116112

117-
python_version = (
118-
check_output(f"{env_python} --version").decode("latin1").split(" ")[-1].strip()
119-
)
113+
python_version = check_output(f"{env_python} --version").decode("latin1").split(" ")[-1].strip()
120114

121-
iris_version = check_output(
122-
f'{python_exe} -c "import iris; print(iris.__version__)"'
123-
).decode("latin1")
124-
iris_authors = check_output(
125-
f'{python_exe} -c "import iris; print(iris.__author__)"'
126-
).decode("latin1")
115+
iris_version = check_output(f'{python_exe} -c "import iris; print(iris.__version__)"').decode("latin1")
116+
iris_authors = check_output(f'{python_exe} -c "import iris; print(iris.__author__)"').decode("latin1")
127117

128118
pynsist_cfg_payload = PYNSIST_CFG_TEMPLATE.format(
129119
version=iris_version,
@@ -153,14 +143,10 @@ def generate_pynsist_config(python_exe, filename, exe_name):
153143
# Generating configuration file BEFORE installing pynsist ensures that
154144
# we bundle the requirements for iris
155145
cfg_path = work_dir / "pynsist.cfg"
156-
generate_pynsist_config(
157-
python_exe=env_python, filename=cfg_path, exe_name=exe_name
158-
)
146+
generate_pynsist_config(python_exe=env_python, filename=cfg_path, exe_name=exe_name)
159147
print(open(cfg_path, "rt").read())
160148

161-
run(
162-
f"{env_python} -m pip install -r {INSTALLER_REQUIREMENTS_FILE} --no-warn-script-location"
163-
)
149+
run(f"{env_python} -m pip install -r {INSTALLER_REQUIREMENTS_FILE} --no-warn-script-location")
164150

165151
run(f"{env_python} -m nsist {cfg_path}")
166152

iris/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
__license__ = "GPLv3"
55
__version__ = "5.3.5"
66

7-
from .raw import AbstractRawDataset, check_raw_bounds, open_raw
8-
from .dataset import DiffractionDataset, MigrationWarning, MigrationError
9-
from .powder import PowderDiffractionDataset
7+
from . import plugins
8+
from .dataset import DiffractionDataset, MigrationError, MigrationWarning
109
from .meta import ExperimentalParameter
1110
from .plugins import install_plugin, load_plugin
12-
13-
from . import plugins
11+
from .powder import PowderDiffractionDataset
12+
from .raw import AbstractRawDataset, check_raw_bounds, open_raw

iris/__main__.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import argparse
44
import sys
55
import webbrowser
6-
from pathlib import Path
76
from multiprocessing import freeze_support
7+
from pathlib import Path
88

99
from iris import __version__
1010
from iris.gui import run
@@ -24,17 +24,13 @@
2424
parser = argparse.ArgumentParser(prog="iris", description=DESCRIPTION, epilog=EPILOG)
2525
parser.add_argument("-v", "--version", action="version", version=__version__)
2626

27-
subparsers = parser.add_subparsers(
28-
title="Subcommands", help="Available sub-commands", dest="subcmd"
29-
)
27+
subparsers = parser.add_subparsers(title="Subcommands", help="Available sub-commands", dest="subcmd")
3028

3129
# Parser to open a path
3230
# To facilitate format determination, we need flags specifying whether the
3331
# path points to a raw, compact, or reduced dataset
3432
open_parser = subparsers.add_parser("open", help=OPEN_HELP)
35-
open_parser.add_argument(
36-
"path", help="Path to the dataset", type=Path, nargs="?", default=None
37-
)
33+
open_parser.add_argument("path", help="Path to the dataset", type=Path, nargs="?", default=None)
3834
dset_modes = open_parser.add_mutually_exclusive_group(required=True)
3935
dset_modes.add_argument(
4036
"--raw",

iris/dataset.py

+16-49
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77
from warnings import warn
88

99
import h5py
10+
import npstreams as ns
1011
import numpy as np
1112
from scipy.ndimage import gaussian_filter
12-
13-
import npstreams as ns
14-
from skued import (
15-
__version__,
16-
nfold,
17-
autocenter,
18-
ArbitrarySelection,
19-
Selection,
20-
)
13+
from skued import ArbitrarySelection, Selection, __version__, autocenter, nfold
2114

2215
from .meta import HDF5ExperimentalParameter, MetaHDF5Dataset
2316

@@ -44,9 +37,7 @@ def write_access_needed(f):
4437
@wraps(f)
4538
def newf(self, *args, **kwargs):
4639
if self.mode != "r+":
47-
raise PermissionError(
48-
f"The dataset {self.filename} has not been opened with write access."
49-
)
40+
raise PermissionError(f"The dataset {self.filename} has not been opened with write access.")
5041
return f(self, *args, **kwargs)
5142

5243
return newf
@@ -91,26 +82,14 @@ class DiffractionDataset(h5py.File, metaclass=MetaHDF5Dataset):
9182
"acquisition_date", str, default=""
9283
) # Acquisition date, no specific format
9384
energy = HDF5ExperimentalParameter("energy", float, default=90) # keV
94-
pump_wavelength = HDF5ExperimentalParameter(
95-
"pump_wavelength", int, default=800
96-
) # nanometers
97-
fluence = HDF5ExperimentalParameter(
98-
"fluence", float, default=0
99-
) # milliJoules / centimeters ^ 2
100-
time_zero_shift = HDF5ExperimentalParameter(
101-
"time_zero_shift", float, default=0
102-
) # picoseconds
103-
temperature = HDF5ExperimentalParameter(
104-
"temperature", float, default=293
105-
) # kelvins
85+
pump_wavelength = HDF5ExperimentalParameter("pump_wavelength", int, default=800) # nanometers
86+
fluence = HDF5ExperimentalParameter("fluence", float, default=0) # milliJoules / centimeters ^ 2
87+
time_zero_shift = HDF5ExperimentalParameter("time_zero_shift", float, default=0) # picoseconds
88+
temperature = HDF5ExperimentalParameter("temperature", float, default=293) # kelvins
10689
exposure = HDF5ExperimentalParameter("exposure", float, default=1) # seconds
10790
scans = HDF5ExperimentalParameter("scans", tuple, default=(1,))
108-
camera_length = HDF5ExperimentalParameter(
109-
"camera_length", float, default=0.23
110-
) # meters
111-
pixel_width = HDF5ExperimentalParameter(
112-
"pixel_width", float, default=14e-6
113-
) # meters
91+
camera_length = HDF5ExperimentalParameter("camera_length", float, default=0.23) # meters
92+
pixel_width = HDF5ExperimentalParameter("pixel_width", float, default=14e-6) # meters
11493
aligned = HDF5ExperimentalParameter("aligned", bool, default=False)
11594
normalized = HDF5ExperimentalParameter("normalized", bool, default=False)
11695
notes = HDF5ExperimentalParameter("notes", str, default="")
@@ -234,9 +213,7 @@ def from_collection(
234213

235214
if ckwargs is None:
236215
ckwargs = {"compression": "lzf", "shuffle": True, "fletcher32": True}
237-
ckwargs[
238-
"chunks"
239-
] = True # For some reason, if no chunking, writing to disk is SLOW
216+
ckwargs["chunks"] = True # For some reason, if no chunking, writing to disk is SLOW
240217

241218
first, patterns = ns.peek(patterns)
242219
if dtype is None:
@@ -498,16 +475,12 @@ def mask_apply(self, func):
498475
if r.dtype != bool:
499476
raise TypeError(f"Diffraction pattern masks must be boolean, not {r.dtype}")
500477
if r.shape != old_mask.shape:
501-
raise ValueError(
502-
f"Expected diffraction pattern mask with shape {old_mask.shape}, but got {r.shape}"
503-
)
478+
raise ValueError(f"Expected diffraction pattern mask with shape {old_mask.shape}, but got {r.shape}")
504479
self.experimental_parameters_group["valid_mask"][:] = func(self.valid_mask)
505480

506481
@write_access_needed
507482
@update_equilibrium_pattern
508-
def symmetrize(
509-
self, mod, center=None, kernel_size=None, callback=None, processes=1
510-
):
483+
def symmetrize(self, mod, center=None, kernel_size=None, callback=None, processes=1):
511484
"""
512485
Symmetrize diffraction images based on n-fold rotational symmetry.
513486
@@ -610,9 +583,7 @@ def shift_time_zero(self, shift):
610583
"""
611584
differential = shift - self.time_zero_shift
612585
self.time_zero_shift = shift
613-
self.experimental_parameters_group["time_points"][:] = (
614-
self.time_points + differential
615-
)
586+
self.experimental_parameters_group["time_points"][:] = self.time_points + differential
616587

617588
def _get_time_index(self, timedelay):
618589
"""
@@ -632,9 +603,7 @@ def _get_time_index(self, timedelay):
632603
time_index = np.argmin(np.abs(self.time_points - timedelay))
633604
actual_timedelay = self.time_points[time_index]
634605
if actual_timedelay != timedelay:
635-
warn(
636-
f"Time-delay {timedelay}ps not available. Using closest-timedelay {actual_timedelay}ps instead"
637-
)
606+
warn(f"Time-delay {timedelay}ps not available. Using closest-timedelay {actual_timedelay}ps instead")
638607
return time_index
639608

640609
def diff_eq(self):
@@ -691,9 +660,7 @@ def _recompute_diff_eq(self):
691660
else:
692661
diff_eq = ns.average((intensity[:, :, i] for i in range(t0_index)), axis=2)
693662

694-
eq_dset = self.diffraction_group.require_dataset(
695-
name="equilibrium", shape=diff_eq.shape, dtype=float
696-
)
663+
eq_dset = self.diffraction_group.require_dataset(name="equilibrium", shape=diff_eq.shape, dtype=float)
697664
eq_dset[:] = diff_eq
698665

699666
def diff_data(self, timedelay, relative=False, out=None):
@@ -866,7 +833,7 @@ def _autocenter(self):
866833
# diffraction center rather than fail the autocenter routine.
867834
# See #26.
868835
if np.allclose(image * self.valid_mask, 0):
869-
r, c = image.shape[0]//2, image.shape[1]//2
836+
r, c = image.shape[0] // 2, image.shape[1] // 2
870837
else:
871838
r, c = autocenter(im=image, mask=self.valid_mask)
872839

iris/gui/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
import pyqtgraph as pg
1414
from PyQt5 import QtGui, QtWidgets
15+
from qdarkstyle import load_stylesheet_pyqt5
1516

1617
from ..raw import open_raw
17-
from .gui import Iris, IMAGE_FOLDER
18-
from qdarkstyle import load_stylesheet_pyqt5
18+
from .gui import IMAGE_FOLDER, Iris
1919

2020

2121
@contextmanager
@@ -29,9 +29,7 @@ def gui_environment():
2929
Note that interactions with the screen (e.g. mask creation) assumes that the image-axis order is
3030
row-major.
3131
"""
32-
old_qt_lib = os.environ.get(
33-
"PYQTGRAPH_QT_LIB", "PyQt5"
34-
) # environment variable might not exist
32+
old_qt_lib = os.environ.get("PYQTGRAPH_QT_LIB", "PyQt5") # environment variable might not exist
3533
os.environ["PYQTGRAPH_QT_LIB"] = "PyQt5"
3634

3735
old_image_axis_order = pg.getConfigOption("imageAxisOrder")

0 commit comments

Comments
 (0)