Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 3.9, 3.10 is now the new minimum #769

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import re
import sys
from pathlib import Path
from typing import Any, Dict, List
from typing import Any


def get_entry_point(filename: Path, prefix: str, import_path: str) -> List[str]:
def get_entry_point(filename: Path, prefix: str, import_path: str) -> list[str]:
"""Returns the entry point string for a given path.

This looks for LIBTBX_SET_DISPATCHER_NAME, and a root function
Expand Down Expand Up @@ -54,7 +54,7 @@ def get_entry_point(filename: Path, prefix: str, import_path: str) -> List[str]:
return [f"{prefix}.{filename.stem}={import_path}.{filename.stem}:run"]


def enumerate_format_classes(path: Path) -> List[str]:
def enumerate_format_classes(path: Path) -> list[str]:
"""Find all Format*.py files and contained Format classes in a path"""
format_classes = []
for filename in path.glob("Format*.py"):
Expand All @@ -81,7 +81,7 @@ def enumerate_format_classes(path: Path) -> List[str]:
return format_classes


def build(setup_kwargs: Dict[str, Any]) -> None:
def build(setup_kwargs: dict[str, Any]) -> None:
"""Called by setup.py to inject any dynamic configuration"""
package_path = Path(__file__).parent / "src" / "dxtbx"
entry_points = setup_kwargs.setdefault("entry_points", {})
Expand Down
6 changes: 3 additions & 3 deletions cmake/read_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _read_obj(obj, prev=None):
return obj


class prop_object(object):
class prop_object:
"""Object that can convert itself to a dictionary"""

def to_dict(self):
Expand All @@ -63,13 +63,13 @@ class _pathed_prop_object(prop_object):
return _pathed_prop_object


class relocatable_path(object):
class relocatable_path:
def __repr__(self):
_all_relocatable_paths.add(self)
return os.path.normpath(os.path.join(str(self._anchor), self.relocatable))


class absolute_path(object):
class absolute_path:
def __init__(self, path):
# This init not used by unpickle - only for rewriting in here
self._path = str(path)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/769.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.10 is now the minimum required
4 changes: 1 addition & 3 deletions src/dxtbx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class IncorrectFormatError(RuntimeError):
"""

def __init__(self, format_instance, filename):
super().__init__(
"Could not open {} as {}".format(filename, str(format_instance))
)
super().__init__(f"Could not open {filename} as {str(format_instance)}")
self.args = (format_instance, filename)


Expand Down
8 changes: 4 additions & 4 deletions src/dxtbx/dxtbx_format_nexus_ext.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from typing import Any, Tuple
from typing import Any

from scitbx.array_family import flex

def dataset_as_flex_double(dataset_id: Any, selection: Tuple[slice]) -> flex.double: ...
def dataset_as_flex_float(dataset_id: Any, selection: Tuple[slice]) -> flex.float: ...
def dataset_as_flex_int(dataset_id: Any, selection: Tuple[slice]) -> flex.int: ...
def dataset_as_flex_double(dataset_id: Any, selection: tuple[slice]) -> flex.double: ...
def dataset_as_flex_float(dataset_id: Any, selection: tuple[slice]) -> flex.float: ...
def dataset_as_flex_int(dataset_id: Any, selection: tuple[slice]) -> flex.int: ...
4 changes: 2 additions & 2 deletions src/dxtbx/dxtbx_imageset_ext.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Tuple, Union
from typing import Any, Union

from scitbx.array_family import flex

Expand Down Expand Up @@ -71,7 +71,7 @@ class ImageSet:
def get_mask(self, int) -> Any: ...
def get_path(self, int) -> Any: ...
def get_pedestal(self, int) -> Any: ...
def get_raw_data(self, index: int) -> Tuple[ImageData]: ...
def get_raw_data(self, index: int) -> tuple[ImageData]: ...
def get_scan(self) -> Any: ...
def has_dynamic_mask(self) -> Any: ...
def indices(self) -> Any: ...
Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/dxtbx_masking_ext.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Tuple
from typing import Any

from scitbx.array_family import flex

Expand Down Expand Up @@ -31,7 +31,7 @@ class GoniometerShadowMasker:
def project_extrema(
self, detector: Detector, scan_angle: float
) -> flex.vec2_double: ...
def get_mask(self, detector: Detector, scan_angle: float) -> Tuple[flex.bool]: ...
def get_mask(self, detector: Detector, scan_angle: float) -> tuple[flex.bool]: ...

class SmarGonShadowMasker(GoniometerShadowMasker):
def __init__(self, goniometer: MultiAxisGoniometer) -> None: ...
Expand Down
91 changes: 41 additions & 50 deletions src/dxtbx/dxtbx_model_ext.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from __future__ import annotations

from collections.abc import Iterator, Sequence
from enum import Enum
from typing import (
Any,
Dict,
Iterator,
List,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
overload,
Expand All @@ -33,12 +28,12 @@ TExperimentModel = TypeVar(
"TExperimentModel", BeamBase, Detector, Goniometer, Scan, CrystalBase, object
)

Vec2Float = Tuple[float, float]
Vec3Float = Tuple[float, float, float]
Vec6Float = Tuple[float, float, float, float, float, float]
Vec9Float = Tuple[float, float, float, float, float, float, float, float, float]
Vec2Int = Tuple[int, int]
Vec4Int = Tuple[int, int, int, int]
Vec2Float = tuple[float, float]
Vec3Float = tuple[float, float, float]
Vec6Float = tuple[float, float, float, float, float, float]
Vec9Float = tuple[float, float, float, float, float, float, float, float, float]
Vec2Int = tuple[int, int]
Vec4Int = tuple[int, int, int, int]
ScanPropertyTypes = Union[
flex.int,
flex.double,
Expand All @@ -65,7 +60,7 @@ class BeamBase:
def get_s0_at_scan_point(self, index: int) -> Vec3Float: ...
def get_s0_at_scan_points(self) -> flex.vec3_double: ...
def set_s0_at_scan_points(
self, points: Union[Tuple[Vec3Float], List[Vec3Float]]
self, points: tuple[Vec3Float] | list[Vec3Float]
) -> None: ...
def get_sample_to_source_direction(self) -> Vec3Float: ...
def get_sample_to_source_distance(self) -> float: ...
Expand Down Expand Up @@ -144,8 +139,8 @@ class Beam(BeamBase):
deg: bool = ...,
) -> None: ...
@staticmethod
def from_dict(data: Dict) -> Beam: ...
def to_dict(self) -> Dict: ...
def from_dict(data: dict) -> Beam: ...
def to_dict(self) -> dict: ...
@staticmethod
def get_probe_from_name(name: str) -> Probe: ...

Expand Down Expand Up @@ -179,8 +174,8 @@ class PolychromaticBeam(Beam):
def set_wavelength_range(self, wavelength_range: Vec2Float) -> None: ...
def get_wavelength_range(self) -> Vec2Float: ...
@staticmethod
def from_dict(data: Dict) -> PolychromaticBeam: ...
def to_dict(self) -> Dict: ...
def from_dict(data: dict) -> PolychromaticBeam: ...
def to_dict(self) -> dict: ...

class CrystalBase:
@property
Expand All @@ -205,7 +200,7 @@ class CrystalBase:
def get_real_space_vectors(self) -> flex.vec3_double: ...
def get_recalculated_cell_parameter_sd(self) -> Vec6Float: ...
def get_recalculated_cell_volume_sd(self) -> float: ...
def get_recalculated_unit_cell(self) -> Optional[unit_cell]: ...
def get_recalculated_unit_cell(self) -> unit_cell | None: ...
def get_unit_cell(self) -> unit_cell: ...
def get_space_group(self) -> space_group: ...
def get_unit_cell_at_scan_point(self, index: int) -> unit_cell: ...
Expand All @@ -222,11 +217,9 @@ class CrystalBase:
self, axis: Vec3Float, angle: float, deg: bool = ...
) -> Any: ...
def set_A_at_scan_points(
self, value: Union[List[Vec9Float], Tuple[Vec9Float], flex.mat3_double]
) -> None: ...
def set_B_covariance(
self, covariance: Union[Tuple[float, ...], flex.double]
self, value: list[Vec9Float] | tuple[Vec9Float] | flex.mat3_double
) -> None: ...
def set_B_covariance(self, covariance: tuple[float, ...] | flex.double) -> None: ...
def set_B_covariance_at_scan_points(self, data: flex.double) -> None: ...
def set_recalculated_cell_parameter_sd(self, value: Vec6Float) -> None: ...
def set_recalculated_cell_volume_sd(self, volume: float) -> None: ...
Expand Down Expand Up @@ -306,13 +299,13 @@ class Detector:
@overload
def add_panel(self, panel: Panel) -> Panel: ...
@staticmethod
def from_dict(data: Dict) -> Detector: ...
def to_dict(self) -> Dict: ...
def from_dict(data: dict) -> Detector: ...
def to_dict(self) -> dict: ...
def get_max_inscribed_resolution(self, s0: Vec3Float) -> float: ...
def get_max_resolution(self, s0: Vec3Float) -> float: ...
def get_names(self) -> flex.std_string: ...
def get_panel_intersection(self, s1: Vec3Float) -> int: ...
def get_ray_intersection(self, s1: Vec3Float) -> Tuple[int, Vec2Float]: ...
def get_ray_intersection(self, s1: Vec3Float) -> tuple[int, Vec2Float]: ...
def has_projection_2d(self) -> bool: ...
def is_similar_to(
self,
Expand Down Expand Up @@ -380,10 +373,10 @@ class ExperimentList:
def __contains__(self, obj: TExperimentModel) -> bool: ...
def replace(self, obj: TExperimentModel, withobj: TExperimentModel) -> None: ...
def indices(
self, obj: Union[TExperimentModel, FlexPlain[TExperimentModel]]
self, obj: TExperimentModel | FlexPlain[TExperimentModel]
) -> flex.size_t: ...
def remove_on_experiment_identifiers(self, identifiers: List[str]) -> None: ...
def select_on_experiment_identifiers(self, identifiers: List[str]) -> None: ...
def remove_on_experiment_identifiers(self, identifiers: list[str]) -> None: ...
def select_on_experiment_identifiers(self, identifiers: list[str]) -> None: ...
def where(
self,
beam: BeamBase,
Expand Down Expand Up @@ -419,7 +412,7 @@ class Goniometer(GoniometerBase):
@property
def num_scan_points(self) -> int: ...
@staticmethod
def from_dict(data: Dict) -> Goniometer: ...
def from_dict(data: dict) -> Goniometer: ...
def get_fixed_rotation(self) -> Vec9Float: ...
def get_num_scan_points(self) -> int: ...
def get_rotation_axis(self) -> Vec3Float: ...
Expand All @@ -444,9 +437,9 @@ class Goniometer(GoniometerBase):
def set_setting_rotation(self, rotation: Vec9Float) -> None: ...
def set_setting_rotation_at_scan_points(
self,
setting_rotations: Union[List[Vec9Float], Tuple[Vec9Float], flex.mat3_double],
setting_rotations: list[Vec9Float] | tuple[Vec9Float] | flex.mat3_double,
) -> Any: ...
def to_dict(self) -> Dict: ...
def to_dict(self) -> dict: ...

class KappaDirection(Enum):
PlusY = ...
Expand Down Expand Up @@ -498,8 +491,8 @@ class MultiAxisGoniometer(Goniometer):
scan_axis: int,
) -> None: ...
@staticmethod
def from_dict(data: Dict) -> MultiAxisGoniometer: ...
def to_dict(self) -> Dict: ...
def from_dict(data: dict) -> MultiAxisGoniometer: ...
def to_dict(self) -> dict: ...
def get_angles(self) -> flex.double: ...
def set_angles(self, angles: flex.double) -> None: ...
def get_axes(self) -> flex.vec3_double: ...
Expand Down Expand Up @@ -601,7 +594,7 @@ class Panel(PanelData):
slow_axis: Vec3Float,
origin: Vec3Float,
pixel_size: Vec2Float,
image_size: Tuple[int, int],
image_size: tuple[int, int],
trusted_range: Vec2Float,
thickness: float,
material: str,
Expand All @@ -617,7 +610,7 @@ class Panel(PanelData):
slow_axis: Vec3Float,
origin: Vec3Float,
pixel_size: Vec2Float,
image_size: Tuple[int, int],
image_size: tuple[int, int],
trusted_range: Vec2Float,
thickness: float,
material: str,
Expand All @@ -627,10 +620,10 @@ class Panel(PanelData):
) -> None: ...
@staticmethod
@overload
def from_dict(data: Dict) -> Panel: ...
def from_dict(data: dict) -> Panel: ...
@staticmethod
@overload
def from_dict(data: Dict, dx: flex.double, dy: flex.double) -> Panel: ...
def from_dict(data: dict, dx: flex.double, dy: flex.double) -> Panel: ...
def get_beam_centre_px(self, s0: Vec3Float) -> Vec2Float: ...
def get_bidirectional_ray_intersection_px(self, s1: Vec3Float) -> Vec2Float: ...
def get_cos2_two_theta_array(self, s0: Vec3Float) -> flex.double: ...
Expand All @@ -652,7 +645,7 @@ class Panel(PanelData):
def get_normal_origin_px(self) -> Vec2Float: ...
def get_pedestal(self) -> float: ...
def get_pixel_lab_coord(self, px: Vec2Float) -> Vec3Float: ...
def get_projection_2d(self) -> Union[Tuple[Vec4Int, Vec2Int], Tuple[()]]: ...
def get_projection_2d(self) -> tuple[Vec4Int, Vec2Int] | tuple[()]: ...
def get_px_mm_strategy(self) -> PxMmStrategy: ...
def get_ray_intersection_px(self, s1: Vec3Float) -> Vec2Float: ...
@overload
Expand All @@ -663,9 +656,7 @@ class Panel(PanelData):
def get_resolution_at_pixel(
self, beam: PolychromaticBeam, xy: Vec2Float
) -> float: ...
def get_trusted_range_mask(
self, image: Union[flex.int, flex.double]
) -> flex.bool: ...
def get_trusted_range_mask(self, image: flex.int | flex.double) -> flex.bool: ...
def get_two_theta_array(self, s0: Vec3Float) -> flex.double: ...
def get_two_theta_at_pixel(self, s0: Vec3Float, xy: Vec2Float) -> float: ...
def get_untrusted_rectangle_mask(self) -> flex.bool: ...
Expand All @@ -689,7 +680,7 @@ class Panel(PanelData):
def set_pedestal(self, pedestal: float) -> None: ...
def set_projection_2d(self, rotation: Vec4Int, translation: Vec2Int) -> None: ...
def set_px_mm_strategy(self, strategy: PxMmStrategy) -> None: ...
def to_dict(self) -> Dict: ...
def to_dict(self) -> dict: ...

class DetectorNode(Panel):
@overload
Expand Down Expand Up @@ -780,13 +771,13 @@ class Scan(ScanBase):
def __init__(
self,
image_range: Vec2Int,
properties_table: Dict,
properties_table: dict,
batch_offset: int,
deg: bool = ...,
) -> None: ...
def append(self, other: Scan, scan_tolerance: float) -> None: ...
@staticmethod
def from_dict(data: Dict) -> Scan: ...
def from_dict(data: dict) -> Scan: ...
@overload
def get_angle_from_array_index(self, index: float, deg: bool = ...) -> float: ...
@overload
Expand Down Expand Up @@ -825,8 +816,8 @@ class Scan(ScanBase):
def get_oscillation(self, deg: bool = ...) -> Vec2Float: ...
def set_oscillation(self, oscillation: Vec2Float, deg: bool = ...) -> None: ...
def get_oscillation_range(self, deg: bool = ...) -> Vec2Float: ...
def get_valid_image_ranges(self, i: str) -> List[Vec2Int]: ...
def set_valid_image_ranges(self, i: str, ranges: List[Vec2Int]) -> None: ...
def get_valid_image_ranges(self, i: str) -> list[Vec2Int]: ...
def set_valid_image_ranges(self, i: str, ranges: list[Vec2Int]) -> None: ...
def get_properties(self) -> dict: ...
def set_properties(self, properties: dict) -> None: ...
def has_property(self, key: str) -> bool: ...
Expand All @@ -852,8 +843,8 @@ class Scan(ScanBase):
def is_image_index_valid(self, index: int) -> bool: ...
def is_still(self) -> bool: ...
def swap(self, other: Scan) -> None: ...
def to_dict(self) -> Dict: ...
def __getitem__(self, index: Union[int, slice]) -> Scan: ...
def to_dict(self) -> dict: ...
def __getitem__(self, index: int | slice) -> Scan: ...
def __len__(self) -> int: ...
def __add__(self, other: Scan) -> Scan: ...
def __iadd__(self, other: Scan) -> Scan: ...
Expand All @@ -868,15 +859,15 @@ class Spectrum:
@overload
def __init__(self, energies: flex.double, weights: flex.double) -> None: ...
@staticmethod
def from_dict(data: Dict) -> Spectrum: ...
def from_dict(data: dict) -> Spectrum: ...
def get_emax_eV(self) -> float: ...
def get_emin_eV(self) -> float: ...
def get_energies_eV(self) -> flex.double: ...
def get_weighted_energy_eV(self) -> float: ...
def get_weighted_energy_variance(self) -> float: ...
def get_weighted_wavelength(self) -> float: ...
def get_weights(self) -> flex.double: ...
def to_dict(self) -> Dict: ...
def to_dict(self) -> dict: ...

class flex_Beam(FlexPlain[Beam]):
pass
Expand Down
3 changes: 2 additions & 1 deletion src/dxtbx/format/Format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import bz2
import functools
import os
from collections.abc import Callable
from io import IOBase
from typing import Callable, ClassVar
from typing import ClassVar

import libtbx

Expand Down
Loading
Loading