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 python2 support #2215

Merged
merged 5 commits into from
Nov 20, 2020
Merged
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
27 changes: 4 additions & 23 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,40 +160,21 @@ jobs:
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install pylint pylint3 python3-sphinx sphinx-rtd-theme-common python3-recommonmark python3-sphinx-rtd-theme python3-pip
pip3 install sphinx-notfound-page
sudo apt-get install python3-sphinx sphinx-rtd-theme-common python3-recommonmark python3-sphinx-rtd-theme python3-pip python3-setuptools
pip3 install pylint sphinx-notfound-page


- name: check syntax
run: ./check_syntax || { cat syntax.log; false; }

- name: pylint (Python 2)
- name: pylint
run: |
echo "__version__ = 'pylint testing' #pylint: disable=unused-variable" > ./lib/mrtrix3/_version.py
PYTHON=python2 ./run_pylint || { cat pylint.log; false; }

- name: pylint (Python 3)
run: |
echo "__version__ = 'pylint testing' #pylint: disable=unused-variable" > ./lib/mrtrix3/_version.py
PYTHON=python3 ./run_pylint || { cat pylint.log; false; }
./run_pylint || { cat pylint.log; false; }

- name: check copyright headers
run: ./update_copyright && git diff --exit-code

- name: check building of documentation
run: python3 -m sphinx -n -N -W -w sphinx.log docs/ tmp/

- name: install build dependencies
run: sudo apt-get install clang-8 libqt5opengl5-dev libqt5svg5-dev libglvnd-dev libeigen3-dev zlib1g-dev libfftw3-dev

- name: check configure with Python 2
run: python2 ./configure || { cat configure.log; false; }

- name: check build with Python 2
run: python2 ./build -dryrun || { cat build.log; false; }

- name: check configure with Python 3
run: python3 ./configure || { cat configure.log; false; }

- name: check build with Python 3
run: python3 ./build -dryrun || { cat build.log; false; }
12 changes: 2 additions & 10 deletions bin/5ttgen
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand All @@ -15,14 +15,6 @@
#
# For more details, see http://www.mrtrix.org/.

# Script that generates a five-tissue-type (5TT) segmented image: the format appropriate for ACT
#
# In this script, major stages of processing can be performed in one of two ways:
# - Using FSL tools: BET for brain extraction, FAST for tissue segmentation, FIRST for sub-cortical grey matter segmentation
# - Using segmentations from FreeSurfer
# Alternative algorithms for performing this conversion can be added by creating a new file in lib/mrtrix3/_5ttgen/ and
# defining the appropriate functions; 5ttgen will automatically make that algorithm available at the command-line



def usage(cmdline): #pylint: disable=unused-variable
Expand Down Expand Up @@ -66,5 +58,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
2 changes: 1 addition & 1 deletion bin/blend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down
16 changes: 8 additions & 8 deletions bin/convert_bruker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -83,13 +83,13 @@ def main():
try:
nslices #pylint: disable=pointless-statement
file_out.write (',' + str(nslices))
except:
except NameError:
pass

try:
nacq #pylint: disable=pointless-statement
file_out.write (',' + str(nacq))
except:
except NameError:
pass

file_out.write ('\nvox: ' + str(res[0]) + ',' + str(res[1]))
Expand All @@ -99,12 +99,12 @@ def main():
try:
slicethick #pylint: disable=pointless-statement
file_out.write (',' + str(slicethick))
except:
except NameError:
pass
try:
nacq #pylint: disable=pointless-statement
file_out.write (',')
except:
except NameError:
pass

file_out.write ('\ndatatype: ')
Expand All @@ -122,12 +122,12 @@ def main():
try:
nslices #pylint: disable=pointless-statement
file_out.write (',+2')
except:
except NameError:
pass
try:
nacq #pylint: disable=pointless-statement
file_out.write (',+3')
except:
except NameError:
pass

file_out.write ('\nfile: ' + sys.argv[1] + '\n')
Expand All @@ -137,7 +137,7 @@ def main():
bvec = [ bvec[n:n+3] for n in range(0,len(bvec),3) ]
for direction, value in zip(bvec, bval):
file_out.write ('dw_scheme: ' + direction[0] + ',' + direction[1] + ',' + str(-float(direction[2])) + ',' + value + '\n')
except:
except AssertionError:
pass

main()
15 changes: 6 additions & 9 deletions bin/dwi2response
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand All @@ -15,9 +15,6 @@
#
# For more details, see http://www.mrtrix.org/.

# Script for estimating response functions for spherical deconvolution
# A number of different approaches are available within this script for performing response function estimation.



def usage(cmdline): #pylint: disable=unused-variable
Expand Down Expand Up @@ -62,16 +59,16 @@ def execute(): #pylint: disable=unused-variable
lmax = [ int(x) for x in app.ARGS.lmax.split(',') ]
if any([lmax_value%2 for lmax_value in lmax]):
raise MRtrixError('Value of lmax must be even')
except:
raise MRtrixError('Parameter lmax must be a number')
except ValueError as exception:
raise MRtrixError('Parameter lmax must be a number') from exception
if alg.needs_single_shell() and not len(lmax) == 1:
raise MRtrixError('Can only specify a single lmax value for single-shell algorithms')
shells_option = ''
if app.ARGS.shells:
try:
shells_values = [ int(round(float(x))) for x in app.ARGS.shells.split(',') ]
except:
raise MRtrixError('-shells option should provide a comma-separated list of b-values')
except ValueError as exception:
raise MRtrixError('-shells option should provide a comma-separated list of b-values') from exception
if alg.needs_single_shell() and not len(shells_values) == 1:
raise MRtrixError('Can only specify a single b-value shell for single-shell algorithms')
shells_option = ' -shells ' + app.ARGS.shells
Expand Down Expand Up @@ -123,5 +120,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
6 changes: 2 additions & 4 deletions bin/dwibiascorrect
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand All @@ -15,8 +15,6 @@
#
# For more details, see http://www.mrtrix.org/.

# Script that performs B1 field inhomogeneity correction for a DWI volume series
# Bias field is typically estimated using the mean b=0 image, and subsequently used to correct all volumes


def usage(cmdline): #pylint: disable=unused-variable
Expand Down Expand Up @@ -79,5 +77,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
8 changes: 4 additions & 4 deletions bin/dwicat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -109,8 +109,8 @@ def execute(): #pylint: disable=unused-variable
if 'Estimated scale factor is' in line:
try:
scaling_factor = float(line.split()[-1])
except ValueError:
raise MRtrixError('Unable to convert scaling factor from mrhistmatch output to floating-point number')
except ValueError as exception:
raise MRtrixError('Unable to convert scaling factor from mrhistmatch output to floating-point number') from exception
break
if scaling_factor is None:
raise MRtrixError('Unable to extract scaling factor from mrhistmatch output')
Expand All @@ -137,5 +137,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
17 changes: 8 additions & 9 deletions bin/dwifslpreproc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand All @@ -18,7 +18,6 @@


import glob, itertools, json, math, os, shutil, sys
from distutils.spawn import find_executable



Expand Down Expand Up @@ -306,10 +305,10 @@ def execute(): #pylint: disable=unused-variable
'contents of file \"' + app.ARGS.eddy_slspec + '\" appears to instead be slice timings; '
'these data have been imported and will be converted to the appropriate format')
if len(slice_timing) != dwi_num_slices:
raise MRtrixError('Cannot use slice timing information from file \"' + app.ARGS.eddy_slspec + '\" for slice-to-volume correction: ' + \
raise MRtrixError('Cannot use slice timing information from file \"' + app.ARGS.eddy_slspec + '\" for slice-to-volume correction: ' # pylint: disable=raise-missing-from
'number of entries (' + str(len(slice_timing)) + ') does not match number of slices (' + str(dwi_num_slices) + ')')
except ValueError:
raise MRtrixError('Error parsing eddy \"slspec\" file \"' + app.ARGS.eddy_slspec + '\" '
raise MRtrixError('Error parsing eddy \"slspec\" file \"' + app.ARGS.eddy_slspec + '\" ' # pylint: disable=raise-missing-from
'(please see FSL eddy help page, specifically the --slspec option)')
else:
if 'SliceTiming' not in dwi_header.keyval():
Expand All @@ -323,7 +322,7 @@ def execute(): #pylint: disable=unused-variable
# Fudges necessary to maniupulate nature of slice timing data in cases where
# bad JSON formatting has led to the data not being simply a list of floats
# (whether from MRtrix3 DICOM conversion or from anything else)
if isinstance(slice_timing, utils.STRING_TYPES):
if isinstance(slice_timing, str):
slice_timing = slice_timing.split()
if not isinstance(slice_timing, list):
raise MRtrixError('Cannot use slice timing information in image header for slice-to-volume correction: '
Expand All @@ -341,9 +340,9 @@ def execute(): #pylint: disable=unused-variable
if not all( [ isinstance(entry, float) for entry in slice_timing ] ):
try:
slice_timing = [ float(entry) for entry in slice_timing ]
except ValueError:
except ValueError as exception:
raise MRtrixError('Cannot use slice timing information in image header for slice-to-volume correction: '
'data are not numeric')
'data are not numeric') from exception
app.debug('Re-formatted slice timing contents from header: ' + str(slice_timing))
if len(slice_timing) != dwi_num_slices:
raise MRtrixError('Cannot use slice timing information in image header for slice-to-volume correction: '
Expand Down Expand Up @@ -1040,7 +1039,7 @@ def execute(): #pylint: disable=unused-variable

# Run eddy qc tool QUAD if installed and one of -eddyqc_text or -eddyqc_all is specified
if eddyqc_path:
if find_executable('eddy_quad'):
if shutil.which('eddy_quad'):
eddyqc_options = ' -idx eddy_indices.txt -par eddy_config.txt -m eddy_mask.nii -b bvals'
if os.path.isfile('dwi_post_eddy.eddy_residuals'):
eddyqc_options += ' -g ' + bvecs_path
Expand Down Expand Up @@ -1309,5 +1308,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
4 changes: 2 additions & 2 deletions bin/dwigradcheck
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -202,5 +202,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
6 changes: 2 additions & 4 deletions bin/dwinormalise
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand All @@ -15,8 +15,6 @@
#
# For more details, see http://www.mrtrix.org/.

# Script that performs intensity normalisation of DWIs in various ways


def usage(cmdline): #pylint: disable=unused-variable
from mrtrix3 import algorithm #pylint: disable=no-name-in-module, import-outside-toplevel
Expand Down Expand Up @@ -46,5 +44,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
4 changes: 2 additions & 2 deletions bin/dwishellmath
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -61,5 +61,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
14 changes: 7 additions & 7 deletions bin/for_each
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -81,7 +81,7 @@ def usage(cmdline): #pylint: disable=unused-variable


# These need to be globals in order to be accessible from execute_parallel()
class Shared(object):
class Shared:
def __init__(self):
self._job_index = 0
self.lock = threading.Lock()
Expand Down Expand Up @@ -132,7 +132,7 @@ def execute(): #pylint: disable=unused-variable
to_exclude.extend(regex_hits)
else:
exclude_unmatched.append(exclude)
except Exception:
except re.error:
exclude_unmatched.append(exclude)
if exclude_unmatched:
app.warn('Item' + ('s' if len(exclude_unmatched) > 1 else '') + ' specified via -exclude did not appear in input list: ' + str('\'' + exclude_unmatched[0] + '\'' if len(exclude_unmatched) == 1 else exclude_unmatched))
Expand All @@ -154,10 +154,10 @@ def execute(): #pylint: disable=unused-variable

try:
next(entry for entry in CMDSPLIT if any(key for key in KEYLIST if key in entry))
except StopIteration:
raise MRtrixError('None of the unique for_each keys ' + str(KEYLIST) + ' appear in command string "' + app.ARGS.command + '"; no substitution can occur')
except StopIteration as exception:
raise MRtrixError('None of the unique for_each keys ' + str(KEYLIST) + ' appear in command string "' + app.ARGS.command + '"; no substitution can occur') from exception

class Entry(object):
class Entry:
def __init__(self, input_text):
self.input_text = input_text
self.sub_in = input_text
Expand Down Expand Up @@ -297,5 +297,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
4 changes: 2 additions & 2 deletions bin/labelsgmfix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python3

# Copyright (c) 2008-2020 the MRtrix3 contributors.
#
Expand Down Expand Up @@ -171,5 +171,5 @@ def execute(): #pylint: disable=unused-variable


# Execute the script
import mrtrix3
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
Loading