49
49
ALTERNATIVE_HISTNORM = 'probability'
50
50
51
51
52
- http_msg = (
53
- "The plotly_domain and plotly_api_domain of your config file must start "
54
- "with 'https', 'http'.\n If you are not using On-Prem then run the "
55
- "following code to ensure your plotly_domain and plotly_api_domain start "
56
- "with 'https':\n \n \n "
57
- "import plotly\n "
58
- "plotly.tools.set_config_file(\n "
59
- " plotly_domain='https://plot.ly',\n "
60
- " plotly_api_domain='https://api.plot.ly'\n "
61
- ")\n \n \n "
62
- "If you are using On-Prem then you will need to use your company's "
63
- "domain and api_domain urls:\n \n \n "
64
- "import plotly\n "
65
- "plotly.tools.set_config_file(\n "
66
- " plotly_domain='https://plotly.your-company.com',\n "
67
- " plotly_api_domain='https://plotly.your-company.com'\n "
68
- ")\n \n \n "
69
- "Make sure to replace `your-company.com` with the URL of your Plotly "
70
- "On-Premise server.\n See "
71
- "https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users "
72
- "for more help with getting started with On-Prem."
73
- )
74
-
75
-
76
- def _validate_domains (* domains ):
77
- for d in domains :
78
- if not d .lower ().startswith ('https' ):
79
- warnings .warn (http_msg , category = UserWarning )
80
-
81
-
82
52
# Warning format
83
53
def warning_on_one_line (message , category , filename , lineno ,
84
54
file = None , line = None ):
@@ -216,14 +186,15 @@ def set_config_file(plotly_domain=None,
216
186
:param (bool) world_readable: True = public, False = private
217
187
218
188
"""
189
+ # import ipdb; ipdb.set_trace()
219
190
if not check_file_permissions ():
220
191
raise exceptions .PlotlyError ("You don't have proper file permissions "
221
192
"to run this function." )
222
193
ensure_local_plotly_files () # make sure what's there is OK
223
194
utils .validate_world_readable_and_sharing_settings ({
224
195
'sharing' : sharing , 'world_readable' : world_readable })
225
196
226
- settings = get_config_file (validate = False )
197
+ settings = get_config_file ()
227
198
if isinstance (plotly_domain , six .string_types ):
228
199
settings ['plotly_domain' ] = plotly_domain
229
200
elif plotly_domain is not None :
@@ -250,12 +221,9 @@ def set_config_file(plotly_domain=None,
250
221
raise TypeError ('auto_open should be a boolean' )
251
222
252
223
# validate plotly_domain and plotly_api_domain
253
- list_of_domains = []
254
- if plotly_domain is not None :
255
- list_of_domains .append (plotly_domain )
256
- if plotly_api_domain is not None :
257
- list_of_domains .append (plotly_api_domain )
258
- _validate_domains (* list_of_domains )
224
+ utils .validate_plotly_domains (
225
+ {'plotly_domain' : plotly_domain , 'plotly_api_domain' : plotly_api_domain }
226
+ )
259
227
260
228
if isinstance (world_readable , bool ):
261
229
settings ['world_readable' ] = world_readable
@@ -272,7 +240,7 @@ def set_config_file(plotly_domain=None,
272
240
ensure_local_plotly_files () # make sure what we just put there is OK
273
241
274
242
275
- def get_config_file (validate = True , * args ):
243
+ def get_config_file (* args ):
276
244
"""Return specified args from `~/.plotly/.config`. as tuple.
277
245
278
246
Returns all if no arguments are specified.
@@ -283,19 +251,9 @@ def get_config_file(validate=True, *args):
283
251
"""
284
252
if check_file_permissions ():
285
253
ensure_local_plotly_files () # make sure what's there is OK
286
- returned_obj = utils .load_json_dict (CONFIG_FILE , * args )
254
+ return utils .load_json_dict (CONFIG_FILE , * args )
287
255
else :
288
- returned_obj = FILE_CONTENT [CONFIG_FILE ]
289
-
290
- list_of_domains = []
291
- for domain in ['plotly_domain' , 'plotly_api_domain' ]:
292
- if domain in returned_obj :
293
- list_of_domains .append (returned_obj [domain ])
294
-
295
- if validate :
296
- _validate_domains (* list_of_domains )
297
-
298
- return returned_obj
256
+ return FILE_CONTENT [CONFIG_FILE ]
299
257
300
258
301
259
def reset_config_file ():
@@ -331,7 +289,7 @@ def get_embed(file_owner_or_url, file_id=None, width="100%", height=525):
331
289
332
290
"""
333
291
plotly_rest_url = (session .get_session_config ().get ('plotly_domain' ) or
334
- get_config_file (validate = False )['plotly_domain' ])
292
+ get_config_file ()['plotly_domain' ])
335
293
if file_id is None : # assume we're using a url
336
294
url = file_owner_or_url
337
295
if url [:len (plotly_rest_url )] != plotly_rest_url :
@@ -428,7 +386,7 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
428
386
if file_id :
429
387
plotly_domain = (
430
388
session .get_session_config ().get ('plotly_domain' ) or
431
- get_config_file (validate = False )['plotly_domain' ]
389
+ get_config_file ()['plotly_domain' ]
432
390
)
433
391
url = "{plotly_domain}/~{un}/{fid}" .format (
434
392
plotly_domain = plotly_domain ,
@@ -454,7 +412,7 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
454
412
455
413
456
414
### mpl-related tools ###
457
- @utils .template_doc (** get_config_file (validate = False ))
415
+ @utils .template_doc (** get_config_file ())
458
416
def mpl_to_plotly (fig , resize = False , strip_style = False , verbose = False ):
459
417
"""Convert a matplotlib figure to plotly dictionary and send.
460
418
0 commit comments