Skip to content

Commit 33b94d1

Browse files
committed
Fixed exception compatibility.
FileNotFoundError is not part of built-in exceptions in Python 2. This commit allows to use it in Python 3, and replace it with a RuntimeError in Python 2.
1 parent 27ee6ae commit 33b94d1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,23 @@
152152
if hasattr(pyproj, 'datadir'): # pyproj version 2+
153153
epsgf = os.path.join(pyproj.datadir.get_data_dir(), 'epsg')
154154
if not os.path.isfile(epsgf):
155+
raise_exception = (
156+
FileNotFoundError if sys.version_info[0] == 3 else RuntimeError
157+
)
155158
if os.name == 'posix':
156159
epsgf = os.environ.get('PROJ_LIB', '/usr/share/proj')
157160
elif 'PROJ_LIB' in os.environ:
158161
epsgf = os.environ['PROJ_LIB']
159162
else:
160-
raise FileNotFoundError(
161-
("Cannot find '%s'" % epsgf)
162-
+ "and PROJ_LIB environment variable is not set."
163+
raise raise_exception(
164+
("Cannot find '%s'," % epsgf)
165+
+ " and PROJ_LIB environment variable is not set."
163166
)
164167
epsgf = os.path.join(epsgf, 'epsg')
165168
if not os.path.isfile(epsgf):
166-
raise FileNotFoundError(
167-
("Cannot find '%s'" % epsgf)
168-
+ "nor epsg file under pyproj's internal datadir."
169+
raise raise_exception(
170+
("Cannot find '%s'," % epsgf)
171+
+ " nor epsg file under pyproj's internal datadir."
169172
)
170173
else: # older versions of pyproj
171174
epsgf = os.path.join(pyproj.pyproj_datadir, 'epsg')

0 commit comments

Comments
 (0)