1# The MIT License (MIT)
2#
3# Copyright (c) 2019 Looker Data Sciences, Inc.
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22
23from typing import Optional
24
25from looker_sdk.rtl import api_settings
26from looker_sdk.rtl import requests_transport
27from looker_sdk.rtl import serialize
28from looker_sdk.rtl import auth_session
29from looker_sdk.sdk import constants
30
31# F401 - providing convenience shortcut for methods/models at top level
32from looker_sdk.sdk.api40 import methods as methods40
33from looker_sdk.sdk.api40 import models as models40 # noqa: F401
34
35API_SETTINGS_API_VERSION_DEPRECATED = "API_VERSION config value is no longer needed."
36
37
38def _settings(
39 config_file: str, section: Optional[str] = None
40) -> api_settings.ApiSettings:
41 return api_settings.ApiSettings(
42 filename=config_file,
43 section=section,
44 sdk_version=constants.sdk_version,
45 env_prefix=constants.environment_prefix,
46 )
47
48def init40(
49 config_file: str = "looker.ini",
50 section: Optional[str] = None,
51 config_settings: Optional[api_settings.ApiSettings] = None,
52) -> methods40.Looker40SDK:
53 """Default dependency configuration"""
54 settings = (
55 _settings(config_file, section) if config_settings is None else config_settings
56 )
57 settings.is_configured()
58 transport = requests_transport.RequestsTransport.configure(settings)
59 return methods40.Looker40SDK(
60 auth_session.AuthSession(settings, transport, serialize.deserialize40, "4.0"),
61 serialize.deserialize40,
62 serialize.serialize40,
63 transport,
64 "4.0",
65 )