Skip to content

Commit cf159d6

Browse files
committed
Factor out get_config and get_credentials.
In general, we have cyclic import issues all over the place, this is one easy fix and will help out in later commits. Note that this maintains backwards compat due to how the the functions are imported into `plotly.py`.
1 parent cf4d831 commit cf159d6

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

Diff for: plotly/config.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Merges and prioritizes file/session config and credentials.
3+
4+
This is promoted to its own module to simplify imports.
5+
6+
"""
7+
from __future__ import absolute_import
8+
9+
from plotly import session, tools
10+
11+
12+
def get_credentials():
13+
"""Returns the credentials that will be sent to plotly."""
14+
credentials = tools.get_credentials_file()
15+
session_credentials = session.get_session_credentials()
16+
for credentials_key in credentials:
17+
18+
# checking for not false, but truthy value here is the desired behavior
19+
session_value = session_credentials.get(credentials_key)
20+
if session_value is False or session_value:
21+
credentials[credentials_key] = session_value
22+
return credentials
23+
24+
25+
def get_config():
26+
"""Returns either module config or file config."""
27+
config = tools.get_config_file()
28+
session_config = session.get_session_config()
29+
for config_key in config:
30+
31+
# checking for not false, but truthy value here is the desired behavior
32+
session_value = session_config.get(config_key)
33+
if session_value is False or session_value:
34+
config[config_key] = session_value
35+
return config

Diff for: plotly/plotly/plotly.py

+3-26
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
get_session_config)
3636
from plotly.grid_objs import Grid, Column
3737

38+
# This is imported like this for backwards compat. Careful if changing.
39+
from plotly.config import get_config, get_credentials
40+
3841
__all__ = None
3942

4043
DEFAULT_PLOT_OPTIONS = {
@@ -55,32 +58,6 @@
5558
update_plot_options = update_session_plot_options
5659

5760

58-
def get_credentials():
59-
"""Returns the credentials that will be sent to plotly."""
60-
credentials = tools.get_credentials_file()
61-
session_credentials = get_session_credentials()
62-
for credentials_key in credentials:
63-
64-
# checking for not false, but truthy value here is the desired behavior
65-
session_value = session_credentials.get(credentials_key)
66-
if session_value is False or session_value:
67-
credentials[credentials_key] = session_value
68-
return credentials
69-
70-
71-
def get_config():
72-
"""Returns either module config or file config."""
73-
config = tools.get_config_file()
74-
session_config = get_session_config()
75-
for config_key in config:
76-
77-
# checking for not false, but truthy value here is the desired behavior
78-
session_value = session_config.get(config_key)
79-
if session_value is False or session_value:
80-
config[config_key] = session_value
81-
return config
82-
83-
8461
def _plot_option_logic(plot_options_from_call_signature):
8562
"""
8663
Given some plot_options as part of a plot call, decide on final options.

0 commit comments

Comments
 (0)