diff --git a/HISTORY.rst b/HISTORY.rst index 305d2f9..748f996 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,7 @@ History 0.5.7 (unreleased) ------------------ +- Dropped support for Python 2. 0.5.6 (2023-05-08) ------------------ diff --git a/README.rst b/README.rst index 9f9d343..bed3b00 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,6 @@ Dependencies - `numpy `__ 1.2 or higher - `pydicom `__ 0.9.9 or higher (pydicom 1.0 compatible) - `matplotlib `__ 1.3.0 or higher (for DVH calculation) -- `six `__ 1.5 or higher - Optional: - `Pillow `__ (for image display) diff --git a/dicompylercore/config.py b/dicompylercore/config.py index 4038aae..29d97bc 100644 --- a/dicompylercore/config.py +++ b/dicompylercore/config.py @@ -7,52 +7,24 @@ # See the file license.txt included with this distribution, also # available at https://github.com/dicompyler/dicompyler-core/ -from six import PY2 - mpl_available = True pil_available = True shapely_available = True skimage_available = True scipy_available = True -if PY2: - import imp - try: - imp.find_module('matplotlib') - except ImportError: - mpl_available = False - - try: - imp.find_module('PIL') - except ImportError: - pil_available = False - - try: - imp.find_module('shapely') - except ImportError: - shapely_available = False - - try: - imp.find_module('skimage') - except ImportError: - skimage_available = False +import importlib - try: - imp.find_module('scipy') - except ImportError: - scipy_available = False -else: - import importlib - mpl_available = importlib.util.find_spec("matplotlib") is not None - pil_available = importlib.util.find_spec('PIL') is not None - shapely_available = importlib.util.find_spec('shapely') is not None - skimage_available = importlib.util.find_spec('skimage') is not None - scipy_available = importlib.util.find_spec('scipy') is not None +mpl_available = importlib.util.find_spec("matplotlib") is not None +pil_available = importlib.util.find_spec("PIL") is not None +shapely_available = importlib.util.find_spec("shapely") is not None +skimage_available = importlib.util.find_spec("skimage") is not None +scipy_available = importlib.util.find_spec("scipy") is not None # DICOM UID prefix -dicompyler_uid_prefix = '1.2.826.0.1.3680043.8.1070.' -dicompyler_uid_prefix_image = dicompyler_uid_prefix + '1.' -dicompyler_uid_prefix_rtstruct = dicompyler_uid_prefix + '2.' -dicompyler_uid_prefix_rtplan = dicompyler_uid_prefix + '3.' -dicompyler_uid_prefix_rtdose = dicompyler_uid_prefix + '4.' +dicompyler_uid_prefix = "1.2.826.0.1.3680043.8.1070." +dicompyler_uid_prefix_image = dicompyler_uid_prefix + "1." +dicompyler_uid_prefix_rtstruct = dicompyler_uid_prefix + "2." +dicompyler_uid_prefix_rtplan = dicompyler_uid_prefix + "3." +dicompyler_uid_prefix_rtdose = dicompyler_uid_prefix + "4." diff --git a/dicompylercore/dicomparser.py b/dicompylercore/dicomparser.py index 22d1991..5f92eb7 100755 --- a/dicompylercore/dicomparser.py +++ b/dicompylercore/dicomparser.py @@ -20,8 +20,8 @@ from dicom.dataset import Dataset import random from numbers import Number -from six import PY2, iterkeys, string_types, BytesIO -from six.moves import range +from io import BytesIO +from pathlib import Path from dicompylercore import dvh, util from dicompylercore.config import pil_available, shapely_available @@ -56,7 +56,7 @@ def __init__(self, dataset, memmap_pixel_array=False): self.memmap_pixel_array = memmap_pixel_array if isinstance(dataset, Dataset): self.ds = dataset - elif isinstance(dataset, (string_types, BytesIO)): + elif isinstance(dataset, (str, BytesIO, Path)): try: with open(dataset, "rb") as fp: self.ds = read_file(fp, defer_size=100, force=True, @@ -203,8 +203,6 @@ def GetDemographics(self): 'birth_date': None, 'gender': 'Other'} if 'PatientName' in self.ds: - if PY2: - self.ds.decode() name = self.ds.PatientName patient['name'] = str(name) patient['given_name'] = name.given_name @@ -668,7 +666,7 @@ def CalculatePlaneThickness(self, planesDict): planes = [] # Iterate over each plane in the structure - for z in iterkeys(planesDict): + for z in planesDict.keys(): planes.append(float(z)) planes.sort() diff --git a/dicompylercore/dvhcalc.py b/dicompylercore/dvhcalc.py index 01d3127..8766764 100644 --- a/dicompylercore/dvhcalc.py +++ b/dicompylercore/dvhcalc.py @@ -19,7 +19,6 @@ from collections.abc import Sequence except ImportError: from collections import Sequence -from six import iteritems import logging logger = logging.getLogger('dicompylercore.dvhcalc') @@ -140,10 +139,10 @@ def _calculate_dvh(structure, This is an internal function called by `get_dvh` and should not be called directly. """ - planes = collections.OrderedDict(sorted(iteritems(structure['planes']))) calcdvh = collections.namedtuple('DVH', ['notes', 'histogram']) logger.debug("Calculating DVH of %s %s", structure['id'], structure['name']) + planes = collections.OrderedDict(sorted(structure["planes"].items())) # Create an empty array of bins to store the histogram in cGy # only if the structure has contour data or the dose grid exists @@ -207,7 +206,7 @@ def _calculate_dvh(structure, 'thickness'] / (interpolation_segments_between_planes + 1) # Iterate over each plane in the structure - for z, plane in iteritems(planes): + for z, plane in planes.items(): # Get the dose plane for the current structure plane if interpolation_resolution or use_structure_extents: doseplane = get_interpolated_dose( diff --git a/tox.ini b/tox.ini index fb45b35..5bcc632 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py37 +envlist = py37 [testenv] setenv =