diff --git a/bdsf/functions.py b/bdsf/functions.py index 83cd5d5..39fb8b4 100644 --- a/bdsf/functions.py +++ b/bdsf/functions.py @@ -1105,8 +1105,11 @@ def read_image_from_file(filename, img, indir, quiet=False): import os import numpy as N from copy import deepcopy as cp - from distutils.version import StrictVersion import warnings + try: + from packaging.version import Version + except ImportError: + from distutils.version import StrictVersion as Version mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Readfile") if indir is None or indir == './': @@ -1129,10 +1132,10 @@ def read_image_from_file(filename, img, indir, quiet=False): use_sections = True except ImportError as err: import pyfits - if StrictVersion(pyfits.__version__) < StrictVersion('2.2'): + if Version(pyfits.__version__) < Version('2.2'): old_pyfits = True use_sections = False - elif StrictVersion(pyfits.__version__) < StrictVersion('2.4'): + elif Version(pyfits.__version__) < Version('2.4'): old_pyfits = False use_sections = False else: @@ -1163,10 +1166,10 @@ def read_image_from_file(filename, img, indir, quiet=False): use_sections = True except ImportError as err: import pyfits - if StrictVersion(pyfits.__version__) < StrictVersion('2.2'): + if Version(pyfits.__version__) < Version('2.2'): old_pyfits = True use_sections = False - elif StrictVersion(pyfits.__version__) < StrictVersion('2.4'): + elif Version(pyfits.__version__) < Version('2.4'): old_pyfits = False use_sections = False else: @@ -1517,7 +1520,10 @@ def write_image_to_file(use, filename, image, img, outdir=None, def make_fits_image(imagedata, wcsobj, beam, freq, equinox, telescope, xmin=0, ymin=0, is_mask=False, shape=None): """Makes a simple FITS hdulist appropriate for single-channel images""" - from distutils.version import StrictVersion + try: + from packaging.version import Version + except ImportError: + from distutils.version import StrictVersion as Version try: from astropy.io import fits as pyfits use_header_update = False @@ -1527,7 +1533,7 @@ def make_fits_image(imagedata, wcsobj, beam, freq, equinox, telescope, xmin=0, y # Due to changes in the way pyfits handles headers from version 3.1 on, # we need to check for older versions and change the setting of header # keywords accordingly. - if StrictVersion(pyfits.__version__) < StrictVersion('3.1'): + if Version(pyfits.__version__) < Version('3.1'): use_header_update = True else: use_header_update = False diff --git a/bdsf/output.py b/bdsf/output.py index 2ef8017..979ffba 100644 --- a/bdsf/output.py +++ b/bdsf/output.py @@ -366,14 +366,17 @@ def write_fits_list(img, filename=None, sort_by='index', objtype='gaul', """ Write as FITS binary table. """ from . import mylogger - from distutils.version import StrictVersion + try: + from packaging.version import Version + except ImportError: + from distutils.version import StrictVersion as Version try: from astropy.io import fits as pyfits use_header_update = False use_from_columns = True except ImportError: import pyfits - if StrictVersion(pyfits.__version__) < StrictVersion('3.1'): + if Version(pyfits.__version__) < Version('3.1'): use_header_update = True use_from_columns = False else: diff --git a/bdsf/psf_vary.py b/bdsf/psf_vary.py index d795c50..b95f039 100644 --- a/bdsf/psf_vary.py +++ b/bdsf/psf_vary.py @@ -43,9 +43,12 @@ def __call__(self, img): from astropy.io import fits as pyfits old_pyfits = False except ImportError as err: - from distutils.version import StrictVersion + try: + from packaging.version import Version + except ImportError: + from distutils.version import StrictVersion as Version import pyfits - if StrictVersion(pyfits.__version__) < StrictVersion('2.2'): + if Version(pyfits.__version__) < Version('2.2'): old_pyfits = True else: old_pyfits = False diff --git a/bdsf/pybdsf.py b/bdsf/pybdsf.py index 57a19f1..fe68bef 100755 --- a/bdsf/pybdsf.py +++ b/bdsf/pybdsf.py @@ -697,9 +697,12 @@ def main(): # greater is in common use. try: # IPython >= 0.11 - from distutils.version import LooseVersion + try: + from packaging.version import Version + except ImportError: + from distutils.version import LooseVersion as Version from IPython import __version__ as ipython_version - if LooseVersion(ipython_version) < LooseVersion('1.0.0'): + if Version(ipython_version) < Version('1.0.0'): from IPython.frontend.terminal.embed import InteractiveShellEmbed else: from IPython.terminal.embed import InteractiveShellEmbed diff --git a/setup.py b/setup.py index fd4cb3d..bf2735c 100644 --- a/setup.py +++ b/setup.py @@ -24,10 +24,14 @@ 'Topic :: Scientific/Engineering :: Astronomy' ], extras_require={ - 'ishell': ['ipython<8.11', 'matplotlib'] + 'ishell': [ + 'ipython!=8.11.*,!=8.12.*,!=8.13.*,!=8.14.*,!=8.15.*', + 'matplotlib', + ], }, install_requires=['backports.shutil_get_terminal_size', 'astropy', 'numpy', 'scipy'], + python_requires=">=3.7", entry_points = { 'console_scripts': [ 'pybdsf = bdsf.pybdsf:main [ishell]',