Skip to content

Commit d43331a

Browse files
authored
Python 2 iframe renderer follow-on to #1809 (#1822)
* Revert back to makedirs with exist_ok in codegen since this is already Python 3 only * Follow the Python 3 makedirs implementation by checking isdir rather than errno
1 parent d7021e8 commit d43331a

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

Diff for: packages/python/plotly/codegen/utils.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ def write_source_py(py_source, filepath, leading_newlines=0):
3131
# Make dir if needed
3232
# ------------------
3333
filedir = opath.dirname(filepath)
34-
try:
35-
os.makedirs(filedir)
36-
except OSError as error:
37-
if error.errno != errno.EEXIST:
38-
raise
34+
# The exist_ok kwarg is only supported with Python 3, but that's ok since
35+
# codegen is only supported with Python 3 anyway
36+
os.makedirs(filedir, exist_ok=True)
3937

4038
# Write file
4139
# ----------

Diff for: packages/python/plotly/plotly/io/_base_renderers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import webbrowser
55
import inspect
66
import os
7-
import errno
7+
from os.path import isdir
88

99
import six
1010
from plotly.io import to_json, to_image, write_image, write_html
@@ -568,7 +568,7 @@ def to_mimebundle(self, fig_dict):
568568
try:
569569
os.makedirs(self.html_directory)
570570
except OSError as error:
571-
if error.errno != errno.EEXIST:
571+
if not isdir(self.html_directory):
572572
raise
573573

574574
write_html(

0 commit comments

Comments
 (0)