Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make DataFrame and Spec clients compatible with SystemLink Client http configuration #61

Merged
merged 6 commits into from
Jun 18, 2024
11 changes: 11 additions & 0 deletions nisystemlink/clients/core/_http_configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class HttpConfigurationManager:
"""The default ID of the SystemLink Server's configuration on the SystemLink Server itself."""

_configs = None
_juypter_config = None

@classmethod
def get_configuration(
Expand Down Expand Up @@ -78,12 +79,22 @@ def _fallback(cls) -> Optional[core.HttpConfiguration]:
"""
if cls._configs is None:
cls._configs = cls._read_configurations()

if cls._juypter_config is None:
spanglerco marked this conversation as resolved.
Show resolved Hide resolved
try:
cls._juypter_config = core.JupyterHttpConfiguration()
except KeyError:
# Env variables for Jupyter Hub execution are not available.
santhoshramaraj marked this conversation as resolved.
Show resolved Hide resolved
pass

master_config = cls._configs.get(cls.HTTP_MASTER_CONFIGURATION_ID)
if master_config is not None:
return master_config
localhost_config = cls._configs.get(cls.HTTP_LOCALHOST_CONFIGURATION_ID)
if localhost_config is not None:
return localhost_config
if cls._juypter_config is not None:
return cls._juypter_config
return None

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions nisystemlink/clients/dataframe/_data_frame_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def __init__(self, configuration: Optional[core.HttpConfiguration] = None):

Args:
configuration: Defines the web server to connect to and information about
how to connect. If not provided, an instance of
:class:`JupyterHttpConfiguration <nisystemlink.clients.core.JupyterHttpConfiguration>`
is used.
how to connect. If not provided, the
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
is used to obtain the configuration.

Raises:
ApiException: if unable to communicate with the DataFrame Service.
"""
if configuration is None:
configuration = core.JupyterHttpConfiguration()
configuration = core.HttpConfigurationManager.get_configuration()

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

Expand Down
14 changes: 13 additions & 1 deletion nisystemlink/clients/spec/_spec_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@

class SpecClient(BaseClient):
def __init__(self, configuration: Optional[core.HttpConfiguration]):
"""Initialize an instance.

Args:
configuration: Defines the web server to connect to and information about
how to connect. If not provided, the
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
is used to obtain the configuration.

Raises:
ApiException: if unable to communicate with the Spec Service.
"""
if configuration is None:
configuration = core.JupyterHttpConfiguration()
configuration = core.HttpConfigurationManager.get_configuration()

super().__init__(configuration, base_path="/nispec/v1/")

@get("")
Expand Down
Loading