Skip to content

Commit 7954e14

Browse files
feat: Make DataFrame and Spec clients compatible with SystemLink Client http configuration (#61)
1 parent edace37 commit 7954e14

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

nisystemlink/clients/core/_http_configuration_manager.py

+31
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class HttpConfigurationManager:
2323
HTTP_LOCALHOST_CONFIGURATION_ID = "SYSTEMLINK_LOCALHOST"
2424
"""The default ID of the SystemLink Server's configuration on the SystemLink Server itself."""
2525

26+
_HTTP_JUPYTER_CONFIGURATION_ID = "SYSTEMLINK_VIRTUAL_JUPYTER"
27+
"""Virtual ID of SystemLink Server's configuration for Jupyter Notebook execution on SLE."""
28+
2629
_configs = None
30+
_virtual_configs = None
2731

2832
@classmethod
2933
def get_configuration(
@@ -78,14 +82,41 @@ def _fallback(cls) -> Optional[core.HttpConfiguration]:
7882
"""
7983
if cls._configs is None:
8084
cls._configs = cls._read_configurations()
85+
if cls._virtual_configs is None:
86+
cls._virtual_configs = cls._read_virtual_configurations()
87+
8188
master_config = cls._configs.get(cls.HTTP_MASTER_CONFIGURATION_ID)
8289
if master_config is not None:
8390
return master_config
8491
localhost_config = cls._configs.get(cls.HTTP_LOCALHOST_CONFIGURATION_ID)
8592
if localhost_config is not None:
8693
return localhost_config
94+
95+
jupyter_config = cls._virtual_configs.get(cls._HTTP_JUPYTER_CONFIGURATION_ID)
96+
if jupyter_config is not None:
97+
return jupyter_config
98+
8799
return None
88100

101+
@classmethod
102+
def _read_virtual_configurations(cls) -> Dict[str, core.HttpConfiguration]:
103+
"""Loads the virtual HTTP configurations.
104+
105+
Returns:
106+
A dictionary mapping each loaded configuration ID to its corresponding
107+
:class:`HttpConfiguration`.
108+
"""
109+
configurations = {} # type: Dict[str, core.HttpConfiguration]
110+
try:
111+
configurations[cls._HTTP_JUPYTER_CONFIGURATION_ID] = (
112+
core.JupyterHttpConfiguration()
113+
)
114+
except KeyError:
115+
# Env variables for Jupyter notebook execution are not available.
116+
pass
117+
118+
return configurations
119+
89120
@classmethod
90121
def _read_configurations(cls) -> Dict[str, core.HttpConfiguration]:
91122
"""Discover and loads the HTTP configuration files.

nisystemlink/clients/dataframe/_data_frame_client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def __init__(self, configuration: Optional[core.HttpConfiguration] = None):
2424
2525
Args:
2626
configuration: Defines the web server to connect to and information about
27-
how to connect. If not provided, an instance of
28-
:class:`JupyterHttpConfiguration <nisystemlink.clients.core.JupyterHttpConfiguration>`
29-
is used.
27+
how to connect. If not provided, the
28+
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
29+
is used to obtain the configuration.
3030
3131
Raises:
3232
ApiException: if unable to communicate with the DataFrame Service.
3333
"""
3434
if configuration is None:
35-
configuration = core.JupyterHttpConfiguration()
35+
configuration = core.HttpConfigurationManager.get_configuration()
3636

3737
super().__init__(configuration, "/nidataframe/v1/")
3838

nisystemlink/clients/spec/_spec_client.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@
1212

1313
class SpecClient(BaseClient):
1414
def __init__(self, configuration: Optional[core.HttpConfiguration]):
15+
"""Initialize an instance.
16+
17+
Args:
18+
configuration: Defines the web server to connect to and information about
19+
how to connect. If not provided, the
20+
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
21+
is used to obtain the configuration.
22+
23+
Raises:
24+
ApiException: if unable to communicate with the Spec Service.
25+
"""
1526
if configuration is None:
16-
configuration = core.JupyterHttpConfiguration()
27+
configuration = core.HttpConfigurationManager.get_configuration()
28+
1729
super().__init__(configuration, base_path="/nispec/v1/")
1830

1931
@get("")

0 commit comments

Comments
 (0)