Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0880002

Browse filesBrowse files
committed
Merge pull request plotly#303 from plotly/fix-config
fix config settings and add the rest of plot options to config
2 parents ff2dc96 + 0d873e1 commit 0880002
Copy full SHA for 0880002

File tree

14 files changed

+398
-180
lines changed
Filter options

14 files changed

+398
-180
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
66

7+
## [1.8.6] - 2015-09-28
8+
- Saving "world_readable" to your config file via `plotly.tools.set_config` actually works.
9+
- You can also save `auto_open` and `sharing` to the config file so that you can forget these
10+
keyword argument in `py.iplot` and `py.plot`.
11+
12+
713
## [1.8.3] - 2015-08-14
814
### Fixed
915
- Fixed typos in `plot` and `iplot` documentations

‎plotly/files.py

Copy file name to clipboardExpand all lines: plotly/files.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
'plotly_api_domain': 'https://api.plot.ly',
2020
'plotly_ssl_verification': True,
2121
'plotly_proxy_authorization': False,
22-
'world_readable': True}}
22+
'world_readable': True,
23+
'sharing': 'public',
24+
'auto_open': True}}
2325

2426
try:
2527
os.mkdir(TEST_DIR)

‎plotly/plotly/__init__.py

Copy file name to clipboardExpand all lines: plotly/plotly/__init__.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from . plotly import (
1111
sign_in,
1212
update_plot_options,
13-
get_plot_options,
1413
get_credentials,
1514
iplot,
1615
plot,

‎plotly/plotly/plotly.py

Copy file name to clipboardExpand all lines: plotly/plotly/plotly.py
+41-67Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from requests.auth import HTTPBasicAuth
3030

31-
from plotly import exceptions, tools, utils, version
31+
from plotly import exceptions, tools, utils, version, files
3232
from plotly.plotly import chunked_requests
3333
from plotly.session import (sign_in, update_session_plot_options,
3434
get_session_plot_options, get_session_credentials,
@@ -39,10 +39,10 @@
3939
DEFAULT_PLOT_OPTIONS = {
4040
'filename': "plot from API",
4141
'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'],
4444
'validate': True,
45-
'sharing': "public"
45+
'sharing': files.FILE_CONTENT[files.CONFIG_FILE]['sharing']
4646
}
4747

4848
# test file permissions and make sure nothing is corrupted
@@ -80,68 +80,41 @@ def get_config():
8080
return config
8181

8282

83-
def get_plot_options():
83+
def _plot_option_logic(plot_options_from_call_signature):
8484
"""
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
8691
8792
"""
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)
9197

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)
97103

104+
# dynamic defaults
105+
if ('filename' in option_set and
106+
'fileopt' not in option_set):
107+
option_set['fileopt'] = 'overwrite'
98108

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}
143116

144-
return current_plot_options
117+
return user_plot_options
145118

146119

147120
def iplot(figure_or_data, **plot_options):
@@ -150,13 +123,11 @@ def iplot(figure_or_data, **plot_options):
150123
plot_options keyword agruments:
151124
filename (string) -- the name that will be associated with this figure
152125
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
160131
- 'public': Anyone can view this graph. It will appear in your profile
161132
and can appear in search engines. You do not need to be
162133
logged in to Plotly to view this chart.
@@ -172,6 +143,8 @@ def iplot(figure_or_data, **plot_options):
172143
notebook, anybody who is viewing that page will be able to
173144
view the graph. You do not need to be logged in to view
174145
this plot.
146+
world_readable (default=True) -- Deprecated: use "sharing".
147+
Make this figure private/public
175148
"""
176149
if 'auto_open' not in plot_options:
177150
plot_options['auto_open'] = False
@@ -212,7 +185,6 @@ def plot(figure_or_data, validate=True, **plot_options):
212185
'overwrite': overwrite the file associated with `filename` with this
213186
'extend': add additional numbers (data) to existing traces
214187
'append': add additional traces to existing data lists
215-
world_readable (default=True) -- make this figure private/public
216188
auto_open (default=True) -- Toggle browser options
217189
True: open this plot in a new browser tab
218190
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):
233205
notebook, anybody who is viewing that page will be able to
234206
view the graph. You do not need to be logged in to view
235207
this plot.
208+
world_readable (default=True) -- Deprecated: use "sharing".
209+
Make this figure private/public
236210
237211
"""
238212
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)

‎plotly/session.py

Copy file name to clipboardExpand all lines: plotly/session.py
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131
'plotly_api_domain': six.string_types,
3232
'plotly_ssl_verification': bool,
3333
'plotly_proxy_authorization': bool,
34-
'world_readable': bool
34+
'world_readable': bool,
35+
'auto_open': bool,
36+
'sharing': six.string_types
3537
}
3638

3739
PLOT_OPTIONS = {
3840
'filename': six.string_types,
3941
'fileopt': six.string_types,
42+
'validate': bool,
4043
'world_readable': bool,
4144
'auto_open': bool,
42-
'validate': bool,
4345
'sharing': six.string_types
4446
}
4547

@@ -96,6 +98,14 @@ def sign_in(username, api_key, **kwargs):
9698
.format(key, CONFIG_KEYS[key]))
9799
_session['config'][key] = kwargs.get(key)
98100

101+
# add plot options, raise error if type is wrong.
102+
for key in PLOT_OPTIONS:
103+
if key in kwargs:
104+
if not isinstance(kwargs[key], CONFIG_KEYS[key]):
105+
raise exceptions.PlotlyError("{} must be of type '{}'"
106+
.format(key, CONFIG_KEYS[key]))
107+
_session['plot_options'][key] = kwargs.get(key)
108+
99109

100110
def update_session_plot_options(**kwargs):
101111
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.