Skip to content

Commit edcb73c

Browse files
committed
add FileExistsError to filemanipy for python 2 support
1 parent cba09b2 commit edcb73c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

nipype/interfaces/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
import tempfile
2929
from os.path import join, dirname
3030
from warnings import warn
31-
import errno
3231

3332
from .. import config, logging
3433
from ..utils.filemanip import (
3534
copyfile, simplify_list, ensure_list,
36-
get_related_files, split_filename)
35+
get_related_files, split_filename,
36+
FileExistsError)
3737
from ..utils.misc import human_order_sorted, str2bool
3838
from .base import (
3939
TraitedSpec, traits, Str, File, Directory, BaseInterface, InputMultiPath,
@@ -2883,7 +2883,7 @@ class ExportFile(SimpleInterface):
28832883

28842884
def _run_interface(self, runtime):
28852885
if not self.inputs.clobber and op.exists(self.inputs.out_file):
2886-
raise FileExistsError(errno.EEXIST, 'File %s exists' % self.inputs.out_file)
2886+
raise FileExistsError(self.inputs.out_file)
28872887
if not op.isabs(self.inputs.out_file):
28882888
raise ValueError('Out_file must be an absolute path.')
28892889
if (self.inputs.check_extension and

nipype/utils/filemanip.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def __init__(self, path):
5151
super(FileNotFoundError, self).__init__(
5252
2, 'No such file or directory', '%s' % path)
5353

54+
class FileExistsError(OSError): # noqa
55+
"""Defines the exception for Python 2."""
56+
57+
def __init__(self, path):
58+
"""Initialize the exception."""
59+
super(FileExistsError, self).__init__(
60+
17, 'File or directory exists', '%s' % path)
61+
5462

5563
USING_PATHLIB2 = False
5664
try:

0 commit comments

Comments
 (0)