From ca7096275d42ab1dcf1b28d43c4e0624895d7624 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 15 Oct 2019 17:31:33 -0400 Subject: [PATCH 1/2] Revert back to makedirs with exist_ok in codegen since this is already Python 3 only --- packages/python/plotly/codegen/utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/python/plotly/codegen/utils.py b/packages/python/plotly/codegen/utils.py index 5bfd46830ca..ff950d60117 100644 --- a/packages/python/plotly/codegen/utils.py +++ b/packages/python/plotly/codegen/utils.py @@ -31,11 +31,9 @@ def write_source_py(py_source, filepath, leading_newlines=0): # Make dir if needed # ------------------ filedir = opath.dirname(filepath) - try: - os.makedirs(filedir) - except OSError as error: - if error.errno != errno.EEXIST: - raise + # The exist_ok kwarg is only supported with Python 3, but that's ok since + # codegen is only supported with Python 3 anyway + os.makedirs(filedir, exist_ok=True) # Write file # ---------- From f7386aef85b965be3cf0d29e78ee7555f2cfe3c6 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 15 Oct 2019 17:32:59 -0400 Subject: [PATCH 2/2] Follow the Python 3 makedirs implementation by checking isdir rather than errno --- packages/python/plotly/plotly/io/_base_renderers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 707348178e6..f0642c7a3f5 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -4,7 +4,7 @@ import webbrowser import inspect import os -import errno +from os.path import isdir import six from plotly.io import to_json, to_image, write_image, write_html @@ -568,7 +568,7 @@ def to_mimebundle(self, fig_dict): try: os.makedirs(self.html_directory) except OSError as error: - if error.errno != errno.EEXIST: + if not isdir(self.html_directory): raise write_html(