28
28
29
29
from requests .auth import HTTPBasicAuth
30
30
31
- from plotly import exceptions , tools , utils , version
31
+ from plotly import exceptions , tools , utils , version , files
32
32
from plotly .plotly import chunked_requests
33
33
from plotly .session import (sign_in , update_session_plot_options ,
34
34
get_session_plot_options , get_session_credentials ,
39
39
DEFAULT_PLOT_OPTIONS = {
40
40
'filename' : "plot from API" ,
41
41
'fileopt' : "new" ,
42
- 'world_readable' : True ,
43
- 'auto_open' : True ,
42
+ 'world_readable' : files . FILE_CONTENT [ files . CONFIG_FILE ][ 'world_readable' ] ,
43
+ 'auto_open' : files . FILE_CONTENT [ files . CONFIG_FILE ][ 'auto_open' ] ,
44
44
'validate' : True ,
45
- 'sharing' : "public"
45
+ 'sharing' : files . FILE_CONTENT [ files . CONFIG_FILE ][ 'sharing' ]
46
46
}
47
47
48
48
# test file permissions and make sure nothing is corrupted
@@ -80,68 +80,41 @@ def get_config():
80
80
return config
81
81
82
82
83
- def get_plot_options ( ):
83
+ def _plot_option_logic ( plot_options_from_call_signature ):
84
84
"""
85
- Merge default and user-defined plot options.
85
+ Given some plot_options as part of a plot call, decide on final options.
86
+ Precendence:
87
+ 1 - Start with DEFAULT_PLOT_OPTIONS
88
+ 2 - Update each key with ~/.plotly/.config options (tls.get_config)
89
+ 3 - Update each key with session plot options (set by py.sign_in)
90
+ 4 - Update each key with plot, iplot call signature options
86
91
87
92
"""
88
- plot_options = copy .deepcopy (DEFAULT_PLOT_OPTIONS )
89
- session_plot_options = get_session_plot_options ()
90
- for plot_option_key in plot_options :
93
+ default_plot_options = copy .deepcopy (DEFAULT_PLOT_OPTIONS )
94
+ file_options = tools .get_config_file ()
95
+ session_options = get_session_plot_options ()
96
+ plot_options_from_call_signature = copy .deepcopy (plot_options_from_call_signature )
91
97
92
- # checking for not false, but truthy value here is the desired behavior
93
- session_value = session_plot_options . get ( plot_option_key )
94
- if session_value is False or session_value :
95
- plot_options [ plot_option_key ] = session_value
96
- return plot_options
98
+ # Validate options and fill in defaults w world_readable and sharing
99
+ for option_set in [ plot_options_from_call_signature ,
100
+ session_options , file_options ] :
101
+ utils . validate_world_readable_and_sharing_settings ( option_set )
102
+ utils . set_sharing_and_world_readable ( option_set )
97
103
104
+ # dynamic defaults
105
+ if ('filename' in option_set and
106
+ 'fileopt' not in option_set ):
107
+ option_set ['fileopt' ] = 'overwrite'
98
108
99
- def _plot_option_logic (plot_options ):
100
- """
101
- Given some plot_options as part of a plot call, decide on final options
102
-
103
- """
104
- session_plot_options = get_session_plot_options ()
105
- current_plot_options = get_plot_options ()
106
- current_plot_options .update (plot_options )
107
- if (('filename' in plot_options or 'filename' in session_plot_options ) and
108
- 'fileopt' not in session_plot_options and
109
- 'fileopt' not in plot_options ):
110
- current_plot_options ['fileopt' ] = 'overwrite'
111
-
112
- # Check for any conflicts between 'sharing' and 'world_readable'
113
- if 'sharing' in plot_options :
114
- if plot_options ['sharing' ] in ['public' , 'private' , 'secret' ]:
115
-
116
- if 'world_readable' not in plot_options :
117
- if plot_options ['sharing' ] != 'public' :
118
- current_plot_options ['world_readable' ] = False
119
- else :
120
- current_plot_options ['world_readable' ] = True
121
- elif (plot_options ['world_readable' ] and
122
- plot_options ['sharing' ] != 'public' ):
123
- raise exceptions .PlotlyError (
124
- "Looks like you are setting your plot privacy to both "
125
- "public and private.\n If you set world_readable as True, "
126
- "sharing can only be set to 'public'" )
127
- elif (not plot_options ['world_readable' ] and
128
- plot_options ['sharing' ] == 'public' ):
129
- raise exceptions .PlotlyError (
130
- "Looks like you are setting your plot privacy to both "
131
- "public and private.\n If you set world_readable as "
132
- "False, sharing can only be set to 'private' or 'secret'" )
133
- else :
134
- raise exceptions .PlotlyError (
135
- "The 'sharing' argument only accepts one of the following "
136
- "strings:\n 'public' -- for public plots\n "
137
- "'private' -- for private plots\n "
138
- "'secret' -- for private plots that can be shared with a "
139
- "secret url"
140
- )
141
- else :
142
- current_plot_options ['sharing' ] = None
109
+ user_plot_options = {}
110
+ user_plot_options .update (default_plot_options )
111
+ user_plot_options .update (file_options )
112
+ user_plot_options .update (session_options )
113
+ user_plot_options .update (plot_options_from_call_signature )
114
+ user_plot_options = {k : v for k , v in user_plot_options .items ()
115
+ if k in default_plot_options }
143
116
144
- return current_plot_options
117
+ return user_plot_options
145
118
146
119
147
120
def iplot (figure_or_data , ** plot_options ):
@@ -150,13 +123,11 @@ def iplot(figure_or_data, **plot_options):
150
123
plot_options keyword agruments:
151
124
filename (string) -- the name that will be associated with this figure
152
125
fileopt ('new' | 'overwrite' | 'extend' | 'append')
153
- 'new': create a new, unique url for this plot
154
- 'overwrite': overwrite the file associated with `filename` with this
155
- 'extend': add additional numbers (data) to existing traces
156
- 'append': add additional traces to existing data lists
157
- world_readable (default=True) -- make this figure private/public
158
- sharing ('public' | 'private' | 'secret') -- Toggle who can view this
159
- graph
126
+ - 'new': create a new, unique url for this plot
127
+ - 'overwrite': overwrite the file associated with `filename` with this
128
+ - 'extend': add additional numbers (data) to existing traces
129
+ - 'append': add additional traces to existing data lists
130
+ sharing ('public' | 'private' | 'secret') -- Toggle who can view this graph
160
131
- 'public': Anyone can view this graph. It will appear in your profile
161
132
and can appear in search engines. You do not need to be
162
133
logged in to Plotly to view this chart.
@@ -172,6 +143,8 @@ def iplot(figure_or_data, **plot_options):
172
143
notebook, anybody who is viewing that page will be able to
173
144
view the graph. You do not need to be logged in to view
174
145
this plot.
146
+ world_readable (default=True) -- Deprecated: use "sharing".
147
+ Make this figure private/public
175
148
"""
176
149
if 'auto_open' not in plot_options :
177
150
plot_options ['auto_open' ] = False
@@ -212,7 +185,6 @@ def plot(figure_or_data, validate=True, **plot_options):
212
185
'overwrite': overwrite the file associated with `filename` with this
213
186
'extend': add additional numbers (data) to existing traces
214
187
'append': add additional traces to existing data lists
215
- world_readable (default=True) -- make this figure private/public
216
188
auto_open (default=True) -- Toggle browser options
217
189
True: open this plot in a new browser tab
218
190
False: do not open plot in the browser, but do return the unique url
@@ -233,6 +205,8 @@ def plot(figure_or_data, validate=True, **plot_options):
233
205
notebook, anybody who is viewing that page will be able to
234
206
view the graph. You do not need to be logged in to view
235
207
this plot.
208
+ world_readable (default=True) -- Deprecated: use "sharing".
209
+ Make this figure private/public
236
210
237
211
"""
238
212
figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
0 commit comments