diff --git a/.azure-pipelines/bootstrap.py b/.azure-pipelines/bootstrap.py index 4b92febcb..d475d7709 100644 --- a/.azure-pipelines/bootstrap.py +++ b/.azure-pipelines/bootstrap.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import multiprocessing.pool import os diff --git a/.azure-pipelines/flake8-validation.py b/.azure-pipelines/flake8-validation.py index da560aab3..4b6b02738 100644 --- a/.azure-pipelines/flake8-validation.py +++ b/.azure-pipelines/flake8-validation.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import subprocess diff --git a/.azure-pipelines/syntax-validation.py b/.azure-pipelines/syntax-validation.py index 9359ad84a..2d74948ac 100644 --- a/.azure-pipelines/syntax-validation.py +++ b/.azure-pipelines/syntax-validation.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import ast import os import sys diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88ae4ec8c..c81510afb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,54 @@ repos: +# Syntax validation and some basic sanity checks +- repo: /~https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-merge-conflict + - id: check-ast + fail_fast: True + - id: check-json + - id: check-added-large-files + args: ['--maxkb=200'] + - id: check-yaml + args: ['--allow-multiple-documents'] + - id: no-commit-to-branch + name: "Don't commit to 'main' directly" # Automatically sort imports -- repo: /~https://github.com/PyCQA/isort.git - rev: 5.9.2 +- repo: /~https://github.com/PyCQA/isort + rev: 5.10.1 hooks: - id: isort + args: [ + '-a', 'from __future__ import annotations', # 3.7-3.11 + '--rm', 'from __future__ import absolute_import', # -3.0 + '--rm', 'from __future__ import division', # -3.0 + '--rm', 'from __future__ import generator_stop', # -3.7 + '--rm', 'from __future__ import generators', # -2.3 + '--rm', 'from __future__ import nested_scopes', # -2.2 + '--rm', 'from __future__ import print_function', # -3.0 + '--rm', 'from __future__ import unicode_literals', # -3.0 + '--rm', 'from __future__ import with_statement', # -2.6 + ] # Automatic source code formatting - repo: /~https://github.com/psf/black - rev: 21.6b0 + rev: 22.1.0 hooks: - id: black args: [--safe, --quiet] files: \.pyi?$|SConscript$|^libtbx_config$ types: [file] +- repo: /~https://github.com/pre-commit/mirrors-clang-format + rev: v13.0.1 + hooks: + - id: clang-format + files: \.c(c|pp|xx)?$|\.h(pp)?$ + # Linting - repo: /~https://github.com/PyCQA/flake8 - rev: 3.9.2 + rev: 4.0.1 hooks: - id: flake8 - -# Syntax validation and some basic sanity checks -- repo: /~https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 - hooks: - - id: check-ast - - id: check-yaml - args: ['--allow-multiple-documents'] - - id: check-merge-conflict - - id: check-added-large-files - args: ['--maxkb=200'] - - id: no-commit-to-branch - name: "Don't commit to main directly" + additional_dependencies: ['flake8-comprehensions==3.8.0'] diff --git a/build.py b/build.py index d0bf9dc45..c610bae40 100644 --- a/build.py +++ b/build.py @@ -6,6 +6,8 @@ offloads the unresolved build phases. """ +from __future__ import annotations + import ast import itertools import re diff --git a/cmake/read_env.py b/cmake/read_env.py index c9f8ba793..663c54887 100644 --- a/cmake/read_env.py +++ b/cmake/read_env.py @@ -8,6 +8,8 @@ path anyway). """ +from __future__ import annotations + import json import os import pickle diff --git a/conftest.py b/conftest.py index fb24c80f4..931760503 100644 --- a/conftest.py +++ b/conftest.py @@ -3,6 +3,8 @@ # write and run pytest tests, and an overview of the available features. # +from __future__ import annotations + import os import socket diff --git a/libtbx_refresh.py b/libtbx_refresh.py index 3c23f8fba..91efd75fa 100644 --- a/libtbx_refresh.py +++ b/libtbx_refresh.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import inspect import os import random diff --git a/newsfragments/468.misc b/newsfragments/468.misc new file mode 100644 index 000000000..8d506a3ce --- /dev/null +++ b/newsfragments/468.misc @@ -0,0 +1 @@ +Update pre-commit environments diff --git a/setup.cfg b/setup.cfg index 67efe2e37..8c0ba29aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,3 +25,5 @@ select = E401,E711,E712,E713,E714,E721,E722,E901, F401,F402,F403,F405,F541,F631,F632,F633,F811,F812,F821,F822,F841,F901, W191,W291,W292,W293,W602,W603,W604,W605,W606, + # flake8-comprehensions, /~https://github.com/adamchainz/flake8-comprehensions + C4, diff --git a/setup.py b/setup.py index fb5d52e36..3cff4e912 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path import setuptools diff --git a/src/dxtbx/command_line/debug_memory.py b/src/dxtbx/command_line/debug_memory.py index 308a330c1..eedece000 100644 --- a/src/dxtbx/command_line/debug_memory.py +++ b/src/dxtbx/command_line/debug_memory.py @@ -17,7 +17,7 @@ def run(args=None): parser.add_argument("image_frame", help="An image to reload repeatedly") options = parser.parse_args(args) - powers = [2 ** n for n in range(20)] + powers = [2**n for n in range(20)] for j in range(powers[-1] + 1): dxtbx.load(options.image_frame) diff --git a/src/dxtbx/command_line/radial_average.py b/src/dxtbx/command_line/radial_average.py index 0aed5fcfd..4a277095a 100644 --- a/src/dxtbx/command_line/radial_average.py +++ b/src/dxtbx/command_line/radial_average.py @@ -346,7 +346,7 @@ def load_func(x): results = results.select(xvals <= params.plot_x_max) xvals = xvals.select(xvals <= params.plot_x_max) if params.x_axis == "resolution": - xvals = 1 / (xvals ** 2) + xvals = 1 / (xvals**2) if params.normalize: plt.plot( xvals.as_numpy_array(), @@ -400,7 +400,7 @@ def resolution(x, pos): / (2 * flex.asin((math.pi / 180) * tt.select(nonzero) / 2)), ) vals = resolution - vals = 1 / (vals ** 2) + vals = 1 / (vals**2) elif params.x_axis == "two_theta": vals = tt diff --git a/src/dxtbx/datablock.py b/src/dxtbx/datablock.py index 61acc0767..ab37c389f 100644 --- a/src/dxtbx/datablock.py +++ b/src/dxtbx/datablock.py @@ -162,79 +162,42 @@ def abspath_or_none(filename): if isinstance(iset, dxtbx.imageset.ImageSequence): if iset.reader().is_single_file_reader(): result["imageset"].append( - dict( - [ - ("__id__", "ImageSequence"), - ( - "master", - os.path.abspath(iset.reader().master_path()), - ), - ( - "mask", - abspath_or_none(iset.external_lookup.mask.filename), - ), - ( - "gain", - abspath_or_none(iset.external_lookup.gain.filename), - ), - ( - "pedestal", - abspath_or_none( - iset.external_lookup.pedestal.filename - ), - ), - ( - "dx", - abspath_or_none(iset.external_lookup.dx.filename), - ), - ( - "dy", - abspath_or_none(iset.external_lookup.dy.filename), - ), - ("beam", b.index(iset.get_beam())), - ("detector", d.index(iset.get_detector())), - ("goniometer", g.index(iset.get_goniometer())), - ("scan", s.index(iset.get_scan())), - ("images", list(iset.indices())), - ("params", iset.params()), - ] - ) + { + "__id__": "ImageSequence", + "master": os.path.abspath(iset.reader().master_path()), + "mask": abspath_or_none(iset.external_lookup.mask.filename), + "gain": abspath_or_none(iset.external_lookup.gain.filename), + "pedestal": abspath_or_none( + iset.external_lookup.pedestal.filename + ), + "dx": abspath_or_none(iset.external_lookup.dx.filename), + "dy": abspath_or_none(iset.external_lookup.dy.filename), + "beam": b.index(iset.get_beam()), + "detector": d.index(iset.get_detector()), + "goniometer": g.index(iset.get_goniometer()), + "scan": s.index(iset.get_scan()), + "images": list(iset.indices()), + "params": iset.params(), + } ) else: result["imageset"].append( - dict( - [ - ("__id__", "ImageSequence"), - ("template", os.path.abspath(iset.get_template())), - ( - "mask", - abspath_or_none(iset.external_lookup.mask.filename), - ), - ( - "gain", - abspath_or_none(iset.external_lookup.gain.filename), - ), - ( - "pedestal", - abspath_or_none( - iset.external_lookup.pedestal.filename - ), - ), - ( - "dx", - abspath_or_none(iset.external_lookup.dx.filename), - ), - ( - "dy", - abspath_or_none(iset.external_lookup.dy.filename), - ), - ("beam", b.index(iset.get_beam())), - ("detector", d.index(iset.get_detector())), - ("goniometer", g.index(iset.get_goniometer())), - ("scan", s.index(iset.get_scan())), - ("params", iset.params()), - ] - ) + { + "__id__": "ImageSequence", + "template": os.path.abspath(iset.get_template()), + "mask": abspath_or_none(iset.external_lookup.mask.filename), + "gain": abspath_or_none(iset.external_lookup.gain.filename), + "pedestal": abspath_or_none( + iset.external_lookup.pedestal.filename + ), + "dx": abspath_or_none(iset.external_lookup.dx.filename), + "dy": abspath_or_none(iset.external_lookup.dy.filename), + "beam": b.index(iset.get_beam()), + "detector": d.index(iset.get_detector()), + "goniometer": g.index(iset.get_goniometer()), + "scan": s.index(iset.get_scan()), + "params": iset.params(), + } ) else: imageset = {} diff --git a/src/dxtbx/format/FormatCBFFull.py b/src/dxtbx/format/FormatCBFFull.py index 326ed2aac..0bb76089f 100644 --- a/src/dxtbx/format/FormatCBFFull.py +++ b/src/dxtbx/format/FormatCBFFull.py @@ -25,7 +25,6 @@ def cbf_read_buffer(handle, buffer, flags): return handle.read_buffer(buffer, flags) - else: from dxtbx.format.image import cbf_read_buffer diff --git a/src/dxtbx/format/FormatEigerStream.py b/src/dxtbx/format/FormatEigerStream.py index 7482c898d..f434046ed 100644 --- a/src/dxtbx/format/FormatEigerStream.py +++ b/src/dxtbx/format/FormatEigerStream.py @@ -155,7 +155,7 @@ def get_raw_data(self, index): print("Get raw data") if info["type"] == "uint16": - bad_sel = data == 2 ** 16 - 1 + bad_sel = data == 2**16 - 1 data[bad_sel] = -1 return flex.int(data) diff --git a/src/dxtbx/format/FormatMRC.py b/src/dxtbx/format/FormatMRC.py index 4aa51ac77..0b9b06226 100644 --- a/src/dxtbx/format/FormatMRC.py +++ b/src/dxtbx/format/FormatMRC.py @@ -190,10 +190,10 @@ def _detector(self): camera = self._header_dictionary.get("camera", b"").lower() if b"ceta" in camera: gain = 26.0 - saturation = 8000 * binning ** 2 + saturation = 8000 * binning**2 elif b"falcon" in camera: gain = 1.0 - saturation = 8000 * binning ** 2 + saturation = 8000 * binning**2 else: gain = 1.0 saturation = 1e6 diff --git a/src/dxtbx/format/FormatNXmx.py b/src/dxtbx/format/FormatNXmx.py index 34e02b129..9bde064ba 100644 --- a/src/dxtbx/format/FormatNXmx.py +++ b/src/dxtbx/format/FormatNXmx.py @@ -77,9 +77,9 @@ def get_raw_data(self, index): # if 32 bit then it is a signed int, I think if 8, 16 then it is # unsigned with the highest two values assigned as masking values if self._bit_depth_readout == 32: - top = 2 ** 31 + top = 2**31 else: - top = 2 ** self._bit_depth_readout + top = 2**self._bit_depth_readout for data in raw_data: d1d = data.as_1d() d1d.set_selected(d1d == top - 1, -1) diff --git a/src/dxtbx/format/FormatNexusEigerDLS.py b/src/dxtbx/format/FormatNexusEigerDLS.py index 3d75f8562..c806e8147 100644 --- a/src/dxtbx/format/FormatNexusEigerDLS.py +++ b/src/dxtbx/format/FormatNexusEigerDLS.py @@ -99,9 +99,9 @@ def get_raw_data(self, index): # if 32 bit then it is a signed int, I think if 8, 16 then it is # unsigned with the highest two values assigned as masking values if self._bit_depth_image == 32: - top = 2 ** 31 + top = 2**31 else: - top = 2 ** self._bit_depth_image + top = 2**self._bit_depth_image d1d = data.as_1d() d1d.set_selected(d1d == top - 1, -1) d1d.set_selected(d1d == top - 2, -2) diff --git a/src/dxtbx/format/FormatSER.py b/src/dxtbx/format/FormatSER.py index f4431a682..d04357f6f 100644 --- a/src/dxtbx/format/FormatSER.py +++ b/src/dxtbx/format/FormatSER.py @@ -281,7 +281,7 @@ def _detector(self): pixel_size = 0.028, 0.028 binning = 2 binning = self._header_dictionary.get("Binning", binning) - saturation = 8000 * binning ** 2 + saturation = 8000 * binning**2 trusted_range = (-1000, saturation) distance = float(self._header_dictionary.get("Camera length [m]", 2)) * 1000 diff --git a/src/dxtbx/format/nexus.py b/src/dxtbx/format/nexus.py index ed529f21d..8ce263cad 100644 --- a/src/dxtbx/format/nexus.py +++ b/src/dxtbx/format/nexus.py @@ -592,7 +592,7 @@ def load_model(self, index=None): self.index = index def get_wavelength(wavelength): - if wavelength.shape in (tuple(), (1,)): + if wavelength.shape in ((), (1,)): wavelength_value = wavelength[()] else: wavelength_value = wavelength[index] diff --git a/src/dxtbx/masking/__init__.py b/src/dxtbx/masking/__init__.py index 85d22694f..4eb3d1d1f 100644 --- a/src/dxtbx/masking/__init__.py +++ b/src/dxtbx/masking/__init__.py @@ -122,10 +122,10 @@ def dls_i23_kappa(goniometer): alpha = flex.double_range(180, 370, step=10) * math.pi / 180 r = flex.double(alpha.size(), 33) - x = flex.sqrt(flex.pow2(r * flex.sin(alpha)) + 89.02 ** 2) * flex.cos( + x = flex.sqrt(flex.pow2(r * flex.sin(alpha)) + 89.02**2) * flex.cos( (50 * math.pi / 180) - flex.atan(r / 89.02 * flex.sin(alpha)) ) - y = flex.sqrt(flex.pow2(r * flex.sin(alpha)) + 89.02 ** 2) * flex.sin( + y = flex.sqrt(flex.pow2(r * flex.sin(alpha)) + 89.02**2) * flex.sin( (50 * math.pi / 180) - flex.atan(r / 89.02 * flex.sin(alpha)) ) z = -r * flex.cos(alpha) diff --git a/src/dxtbx/model/experiment_list.py b/src/dxtbx/model/experiment_list.py index 8e85bc63f..d206825de 100644 --- a/src/dxtbx/model/experiment_list.py +++ b/src/dxtbx/model/experiment_list.py @@ -1087,7 +1087,7 @@ def _groupby_template_is_none( for _, group in itertools.groupby( enumerate(records), key=lambda x: -1 if x[1].template is None else x[0] ): - yield list(x[1] for x in group) + yield [x[1] for x in group] def _openingpathiterator(pathnames: Iterable[str]): diff --git a/src/dxtbx/sequence_filenames.py b/src/dxtbx/sequence_filenames.py index bc4614b13..d6c056408 100644 --- a/src/dxtbx/sequence_filenames.py +++ b/src/dxtbx/sequence_filenames.py @@ -164,7 +164,7 @@ def find_matching_images(image_name): matching_images = [] - for j in range(0, 10 ** len_digits): + for j in range(0, 10**len_digits): if template_str % j in files_in_directory: matching_images.append(os.path.join(directory, template_str % j)) diff --git a/src/dxtbx/util/dlsnxs2cbf.py b/src/dxtbx/util/dlsnxs2cbf.py index ba7a8f3fd..904ca1418 100644 --- a/src/dxtbx/util/dlsnxs2cbf.py +++ b/src/dxtbx/util/dlsnxs2cbf.py @@ -167,9 +167,9 @@ def make_cbf( # if 32 bit then it is a signed int, I think if 8, 16 then it is # unsigned with the highest two values assigned as masking values if bit_depth_readout == 32: - top = 2 ** 31 + top = 2**31 else: - top = 2 ** bit_depth_readout + top = 2**bit_depth_readout d1d = data.as_1d() d1d.set_selected(d1d == top - 1, -1) d1d.set_selected(d1d == top - 2, -2) diff --git a/tests/command_line/test_average.py b/tests/command_line/test_average.py index 7ee988d50..38d1c901e 100644 --- a/tests/command_line/test_average.py +++ b/tests/command_line/test_average.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import procrunner import pytest diff --git a/tests/command_line/test_dlsnxs2cbf.py b/tests/command_line/test_dlsnxs2cbf.py index e3bcce470..5bf7673fd 100644 --- a/tests/command_line/test_dlsnxs2cbf.py +++ b/tests/command_line/test_dlsnxs2cbf.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import shutil import warnings diff --git a/tests/command_line/test_print_header.py b/tests/command_line/test_print_header.py index e25a092f2..593126a76 100644 --- a/tests/command_line/test_print_header.py +++ b/tests/command_line/test_print_header.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import procrunner diff --git a/tests/command_line/test_show_mask_info.py b/tests/command_line/test_show_mask_info.py index 5bb68122f..4adad867d 100644 --- a/tests/command_line/test_show_mask_info.py +++ b/tests/command_line/test_show_mask_info.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import procrunner diff --git a/tests/format/test_FormatCBFFullPilatusDLS6MSN126.py b/tests/format/test_FormatCBFFullPilatusDLS6MSN126.py index d06bd67d1..d46f9318d 100644 --- a/tests/format/test_FormatCBFFullPilatusDLS6MSN126.py +++ b/tests/format/test_FormatCBFFullPilatusDLS6MSN126.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.format.FormatCBFFullPilatusDLS6MSN126 import FormatCBFFullPilatusDLS6MSN126 diff --git a/tests/format/test_FormatCBFMiniEigerDLS16MSN160.py b/tests/format/test_FormatCBFMiniEigerDLS16MSN160.py index de0a1340b..60093dca5 100644 --- a/tests/format/test_FormatCBFMiniEigerDLS16MSN160.py +++ b/tests/format/test_FormatCBFMiniEigerDLS16MSN160.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.format.FormatCBFMiniEigerDLS16MSN160 import FormatCBFMiniEigerDLS16MSN160 diff --git a/tests/format/test_FormatCBFMiniPilatus.py b/tests/format/test_FormatCBFMiniPilatus.py index a52732d54..408bc457a 100644 --- a/tests/format/test_FormatCBFMiniPilatus.py +++ b/tests/format/test_FormatCBFMiniPilatus.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus diff --git a/tests/format/test_FormatCBFMiniPilatusDLS12M.py b/tests/format/test_FormatCBFMiniPilatusDLS12M.py index 126c1ac0a..ce87e70d2 100644 --- a/tests/format/test_FormatCBFMiniPilatusDLS12M.py +++ b/tests/format/test_FormatCBFMiniPilatusDLS12M.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import calendar import os diff --git a/tests/format/test_FormatHDF5EigerNearlyNexus.py b/tests/format/test_FormatHDF5EigerNearlyNexus.py index baafb0741..4f62e43b1 100644 --- a/tests/format/test_FormatHDF5EigerNearlyNexus.py +++ b/tests/format/test_FormatHDF5EigerNearlyNexus.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pytest diff --git a/tests/format/test_FormatHDF5EigerNearlyNexusSPring8.py b/tests/format/test_FormatHDF5EigerNearlyNexusSPring8.py index e968e0ad6..76a964b67 100644 --- a/tests/format/test_FormatHDF5EigerNearlyNexusSPring8.py +++ b/tests/format/test_FormatHDF5EigerNearlyNexusSPring8.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.format.FormatHDF5EigerNearlyNexusSPring8 import ( diff --git a/tests/format/test_FormatHDF5SaclaMPCCD.py b/tests/format/test_FormatHDF5SaclaMPCCD.py index cd70da3c7..c1234ed97 100644 --- a/tests/format/test_FormatHDF5SaclaMPCCD.py +++ b/tests/format/test_FormatHDF5SaclaMPCCD.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pickle import pytest diff --git a/tests/format/test_FormatNexusEiger.py b/tests/format/test_FormatNexusEiger.py index be7d5b528..42540ba79 100644 --- a/tests/format/test_FormatNexusEiger.py +++ b/tests/format/test_FormatNexusEiger.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pytest diff --git a/tests/format/test_FormatNexusEigerDLS16M.py b/tests/format/test_FormatNexusEigerDLS16M.py index 0a1d57b70..6207552b9 100644 --- a/tests/format/test_FormatNexusEigerDLS16M.py +++ b/tests/format/test_FormatNexusEigerDLS16M.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import h5py diff --git a/tests/format/test_FormatNexusEigerDLS16MI03.py b/tests/format/test_FormatNexusEigerDLS16MI03.py index a13593293..5af73eb1b 100644 --- a/tests/format/test_FormatNexusEigerDLS16MI03.py +++ b/tests/format/test_FormatNexusEigerDLS16MI03.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pytest diff --git a/tests/format/test_FormatPYunspecified.py b/tests/format/test_FormatPYunspecified.py index 77146240e..09aa95b68 100644 --- a/tests/format/test_FormatPYunspecified.py +++ b/tests/format/test_FormatPYunspecified.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from dxtbx.format.FormatPYunspecifiedStill import FormatPYunspecifiedStill diff --git a/tests/format/test_FormatSMVADSC.py b/tests/format/test_FormatSMVADSC.py index 7f429c9d7..f9e3eb4f6 100644 --- a/tests/format/test_FormatSMVADSC.py +++ b/tests/format/test_FormatSMVADSC.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import dxtbx diff --git a/tests/format/test_abstract.py b/tests/format/test_abstract.py index e2f0f1427..a1a74bb1c 100644 --- a/tests/format/test_abstract.py +++ b/tests/format/test_abstract.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import h5py import pytest diff --git a/tests/format/test_cbf_mini_as_file.py b/tests/format/test_cbf_mini_as_file.py index 7e99410d6..9fd172039 100644 --- a/tests/format/test_cbf_mini_as_file.py +++ b/tests/format/test_cbf_mini_as_file.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pytest diff --git a/tests/format/test_nexus.py b/tests/format/test_nexus.py index 19e0d263d..cc405b381 100644 --- a/tests/format/test_nexus.py +++ b/tests/format/test_nexus.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path import h5py diff --git a/tests/format/test_uri.py b/tests/format/test_uri.py index 2252ce7e5..1406ee23b 100644 --- a/tests/format/test_uri.py +++ b/tests/format/test_uri.py @@ -2,6 +2,8 @@ Testing URI-passing in the Format class hierarchy """ +from __future__ import annotations + from typing import Type from unittest.mock import Mock diff --git a/tests/imagelist.py b/tests/imagelist.py index b0d459fad..32292c11a 100644 --- a/tests/imagelist.py +++ b/tests/imagelist.py @@ -1,3 +1,6 @@ +from __future__ import annotations + + def id_conversion(path): return path.replace("/", "-") diff --git a/tests/masking/test_masking.py b/tests/masking/test_masking.py index 625525b64..d71b8fefa 100644 --- a/tests/masking/test_masking.py +++ b/tests/masking/test_masking.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math import os import pickle diff --git a/tests/model/crystal_model_old.py b/tests/model/crystal_model_old.py index 38b6bc244..467668869 100644 --- a/tests/model/crystal_model_old.py +++ b/tests/model/crystal_model_old.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys from io import StringIO from math import pi, sqrt diff --git a/tests/model/test_beam.py b/tests/model/test_beam.py index ba1b6bf2b..7f1ef5b9d 100644 --- a/tests/model/test_beam.py +++ b/tests/model/test_beam.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from libtbx.phil import parse diff --git a/tests/model/test_crystal_model.py b/tests/model/test_crystal_model.py index b9106001e..5a9c592be 100644 --- a/tests/model/test_crystal_model.py +++ b/tests/model/test_crystal_model.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math import random diff --git a/tests/model/test_detector.py b/tests/model/test_detector.py index 622d56abd..dca2d72c6 100644 --- a/tests/model/test_detector.py +++ b/tests/model/test_detector.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy import pickle import random diff --git a/tests/model/test_detector2.py b/tests/model/test_detector2.py index bec001f5d..fcd23194e 100644 --- a/tests/model/test_detector2.py +++ b/tests/model/test_detector2.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pickle from copy import deepcopy from math import sqrt @@ -194,10 +196,10 @@ def test_get_valid_D_matrix(detector): # Test the panel coordinate systems eps = 1e-7 - p1_d0 = matrix.col((10.0 + sqrt(5.0 ** 2 / 2), 10.0 + sqrt(5.0 ** 2 / 2), 110)) - p2_d0 = matrix.col((10.0 - sqrt(5.0 ** 2 / 2), 10.0 + sqrt(5.0 ** 2 / 2), 90)) - p3_d0 = matrix.col((20.0 + sqrt(5.0 ** 2 / 2), 20.0 + sqrt(5.0 ** 2 / 2), 90)) - p4_d0 = matrix.col((20.0 + sqrt(5.0 ** 2 / 2), 20.0 - sqrt(5.0 ** 2 / 2), 110)) + p1_d0 = matrix.col((10.0 + sqrt(5.0**2 / 2), 10.0 + sqrt(5.0**2 / 2), 110)) + p2_d0 = matrix.col((10.0 - sqrt(5.0**2 / 2), 10.0 + sqrt(5.0**2 / 2), 90)) + p3_d0 = matrix.col((20.0 + sqrt(5.0**2 / 2), 20.0 + sqrt(5.0**2 / 2), 90)) + p4_d0 = matrix.col((20.0 + sqrt(5.0**2 / 2), 20.0 - sqrt(5.0**2 / 2), 110)) p1_d1 = matrix.col((1, 0, 0)) p2_d1 = matrix.col((0, 1, 0)) p3_d1 = matrix.col((0, -1, 0)) diff --git a/tests/model/test_experiment_list.py b/tests/model/test_experiment_list.py index e8d651dbc..cca54c12d 100644 --- a/tests/model/test_experiment_list.py +++ b/tests/model/test_experiment_list.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import collections import errno import os @@ -1073,8 +1075,8 @@ def test_extract_metadata_record(): def _equal_but_not_same(thing): - object_1 = tuple([thing]) - object_2 = tuple([thing]) + object_1 = (thing,) + object_2 = (thing,) assert object_1 == object_2 assert object_1 is not object_2 return object_1, object_2 diff --git a/tests/model/test_parallax_correction.py b/tests/model/test_parallax_correction.py index 248d24197..fab4e52eb 100644 --- a/tests/model/test_parallax_correction.py +++ b/tests/model/test_parallax_correction.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import random diff --git a/tests/model/test_pickle.py b/tests/model/test_pickle.py index deb90b7e3..24bb1941c 100644 --- a/tests/model/test_pickle.py +++ b/tests/model/test_pickle.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pickle from dxtbx.model import Beam, Detector, Goniometer, Panel, Scan diff --git a/tests/model/test_pixel_to_millimeter.py b/tests/model/test_pixel_to_millimeter.py index 10db13bd2..990594a54 100644 --- a/tests/model/test_pixel_to_millimeter.py +++ b/tests/model/test_pixel_to_millimeter.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math import os import pickle diff --git a/tests/model/test_profile.py b/tests/model/test_profile.py index 8a25bb805..53ec13bac 100644 --- a/tests/model/test_profile.py +++ b/tests/model/test_profile.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.model import ProfileModelFactory diff --git a/tests/model/test_ray_intersection.py b/tests/model/test_ray_intersection.py index 7366c92d0..04c7a68da 100644 --- a/tests/model/test_ray_intersection.py +++ b/tests/model/test_ray_intersection.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import random import pytest diff --git a/tests/model/test_scan.py b/tests/model/test_scan.py index fe52fdeab..3d026c1d5 100644 --- a/tests/model/test_scan.py +++ b/tests/model/test_scan.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dxtbx.model diff --git a/tests/model/test_scan_data.py b/tests/model/test_scan_data.py index 722ddab22..a058771c3 100644 --- a/tests/model/test_scan_data.py +++ b/tests/model/test_scan_data.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy import pytest diff --git a/tests/model/test_scan_helpers.py b/tests/model/test_scan_helpers.py index 355c8f691..b6f3d2e69 100644 --- a/tests/model/test_scan_helpers.py +++ b/tests/model/test_scan_helpers.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import random from dxtbx.model import ( diff --git a/tests/model/test_spectrum.py b/tests/model/test_spectrum.py index a8d30ec5e..a58694842 100644 --- a/tests/model/test_spectrum.py +++ b/tests/model/test_spectrum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math import random diff --git a/tests/model/test_to_from_dict.py b/tests/model/test_to_from_dict.py index 124cc3e92..ed78ccfa3 100644 --- a/tests/model/test_to_from_dict.py +++ b/tests/model/test_to_from_dict.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from scitbx.array_family import flex from dxtbx.model import Beam, Detector, Goniometer, Scan diff --git a/tests/nexus/conftest.py b/tests/nexus/conftest.py index bdaf0c78b..1a4d3bdc1 100644 --- a/tests/nexus/conftest.py +++ b/tests/nexus/conftest.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import h5py import numpy as np import pytest diff --git a/tests/nexus/test_build_dxtbx_models.py b/tests/nexus/test_build_dxtbx_models.py index f88442c55..e84d700ad 100644 --- a/tests/nexus/test_build_dxtbx_models.py +++ b/tests/nexus/test_build_dxtbx_models.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import h5py import numpy as np import pytest diff --git a/tests/nexus/test_nxmx.py b/tests/nexus/test_nxmx.py index 2817cd624..3062f5cd4 100644 --- a/tests/nexus/test_nxmx.py +++ b/tests/nexus/test_nxmx.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import datetime import dateutil diff --git a/tests/serialize/test_crystal_model_serialize.py b/tests/serialize/test_crystal_model_serialize.py index a48c5b2f3..bb2990bdd 100644 --- a/tests/serialize/test_crystal_model_serialize.py +++ b/tests/serialize/test_crystal_model_serialize.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pickle import pytest diff --git a/tests/serialize/test_filename.py b/tests/serialize/test_filename.py index 33b03174b..65393fac7 100644 --- a/tests/serialize/test_filename.py +++ b/tests/serialize/test_filename.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from dxtbx.serialize.filename import resolve_path diff --git a/tests/serialize/test_serialize.py b/tests/serialize/test_serialize.py index bb503e6d5..849f9c955 100644 --- a/tests/serialize/test_serialize.py +++ b/tests/serialize/test_serialize.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from scitbx import matrix diff --git a/tests/serialize/test_xds.py b/tests/serialize/test_xds.py index eda377cae..d32192b12 100644 --- a/tests/serialize/test_xds.py +++ b/tests/serialize/test_xds.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from libtbx.test_utils import approx_equal diff --git a/tests/test_FormatCBFFull.py b/tests/test_FormatCBFFull.py index 048313e34..0b3d4a71c 100644 --- a/tests/test_FormatCBFFull.py +++ b/tests/test_FormatCBFFull.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from libtbx.test_utils import approx_equal diff --git a/tests/test_beam.py b/tests/test_beam.py index 4c38dc4ec..1f32ec172 100644 --- a/tests/test_beam.py +++ b/tests/test_beam.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path from dxtbx.model.beam import BeamFactory diff --git a/tests/test_beamline_definitions.py b/tests/test_beamline_definitions.py index fc80e4374..0ed4a5951 100644 --- a/tests/test_beamline_definitions.py +++ b/tests/test_beamline_definitions.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dxtbx.data.beamline_defs as dxbd diff --git a/tests/test_compression.py b/tests/test_compression.py index e84a1a4b8..f0b421c78 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from scitbx.array_family import flex from dxtbx.ext import compress, uncompress diff --git a/tests/test_crystal_model_equivalence.py b/tests/test_crystal_model_equivalence.py index 560c2589b..3bcf18345 100644 --- a/tests/test_crystal_model_equivalence.py +++ b/tests/test_crystal_model_equivalence.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from cctbx import crystal_orientation from cctbx.crystal import symmetry from cctbx.uctbx import unit_cell diff --git a/tests/test_datablock.py b/tests/test_datablock.py index eb6b08d38..04a735e5a 100644 --- a/tests/test_datablock.py +++ b/tests/test_datablock.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import os import pickle diff --git a/tests/test_dataset_as_flex.py b/tests/test_dataset_as_flex.py index 7f0e0fc38..5b5ac1d5a 100644 --- a/tests/test_dataset_as_flex.py +++ b/tests/test_dataset_as_flex.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import h5py import numpy import pytest diff --git a/tests/test_detector.py b/tests/test_detector.py index 2641e2b38..dccd54c87 100644 --- a/tests/test_detector.py +++ b/tests/test_detector.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path from dxtbx.model.detector import DetectorFactory diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index a15285e24..67ad1937d 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pickle from dxtbx import IncorrectFormatError diff --git a/tests/test_filecache.py b/tests/test_filecache.py index fe2cf113c..ded92699d 100644 --- a/tests/test_filecache.py +++ b/tests/test_filecache.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import os import random diff --git a/tests/test_filecache_controller.py b/tests/test_filecache_controller.py index 1d2850d03..c2106ca00 100644 --- a/tests/test_filecache_controller.py +++ b/tests/test_filecache_controller.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from unittest.mock import Mock, create_autospec import pytest diff --git a/tests/test_flumpy.py b/tests/test_flumpy.py index 0133d0776..a874bfcb9 100644 --- a/tests/test_flumpy.py +++ b/tests/test_flumpy.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import itertools import numpy as np diff --git a/tests/test_goniometer.py b/tests/test_goniometer.py index ad22954cd..308709a20 100644 --- a/tests/test_goniometer.py +++ b/tests/test_goniometer.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import math from pathlib import Path diff --git a/tests/test_image_readers.py b/tests/test_image_readers.py index 332ead43c..9b03bc66f 100644 --- a/tests/test_image_readers.py +++ b/tests/test_image_readers.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pycbf diff --git a/tests/test_imageset.py b/tests/test_imageset.py index 66f9ac559..366818d93 100644 --- a/tests/test_imageset.py +++ b/tests/test_imageset.py @@ -1,8 +1,10 @@ +from __future__ import annotations + +import copy import os import pickle import shutil from unittest import mock -import copy import pytest diff --git a/tests/test_regression_images.py b/tests/test_regression_images.py index 1bb0ebf6e..4aa42aea1 100644 --- a/tests/test_regression_images.py +++ b/tests/test_regression_images.py @@ -2,6 +2,8 @@ Image reading tests against the dials_regression suite """ +from __future__ import annotations + import bz2 import gzip import os diff --git a/tests/test_scan.py b/tests/test_scan.py index 3e1958e4a..2297118ff 100644 --- a/tests/test_scan.py +++ b/tests/test_scan.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pytest diff --git a/tests/test_sequence_filenames.py b/tests/test_sequence_filenames.py index 28db95aff..ed351916e 100644 --- a/tests/test_sequence_filenames.py +++ b/tests/test_sequence_filenames.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.sequence_filenames import template_regex diff --git a/tests/test_split_singleimage_imageset.py b/tests/test_split_singleimage_imageset.py index 7cd718ea7..efdada48b 100644 --- a/tests/test_split_singleimage_imageset.py +++ b/tests/test_split_singleimage_imageset.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from dxtbx.model.experiment_list import ExperimentListFactory diff --git a/tests/test_util.py b/tests/test_util.py index b85367b3f..30d5d5b37 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dxtbx.util import ersatz_uuid4 from dxtbx.util import format_float_with_standard_uncertainty as ffwsu