|
14 | 14 | from __future__ import absolute_import |
15 | 15 |
|
16 | 16 | import logging |
| 17 | +import os |
17 | 18 | import platform |
18 | 19 |
|
19 | 20 | import boto3 |
|
28 | 29 | _LocalTransformJob, |
29 | 30 | ) |
30 | 31 | from sagemaker.session import Session |
31 | | -from sagemaker.utils import DeferredError, get_config_value |
32 | | - |
33 | | -try: |
34 | | - import urllib3 |
35 | | -except ImportError as e: |
36 | | - logging.warning("urllib3 failed to import. Local mode features will be impaired or broken.") |
37 | | - # Any subsequent attempt to use urllib3 will raise the ImportError |
38 | | - urllib3 = DeferredError(e) |
| 32 | +from sagemaker.utils import get_config_value, _module_import_error |
39 | 33 |
|
40 | 34 | logger = logging.getLogger(__name__) |
41 | 35 |
|
@@ -329,6 +323,12 @@ def __init__(self, config=None): |
329 | 323 | config (dict): Optional configuration for this client. In particular only |
330 | 324 | the local port is read. |
331 | 325 | """ |
| 326 | + try: |
| 327 | + import urllib3 |
| 328 | + except ImportError as e: |
| 329 | + logging.error(_module_import_error("urllib3", "Local mode", "local")) |
| 330 | + raise e |
| 331 | + |
332 | 332 | self.http = urllib3.PoolManager() |
333 | 333 | self.serving_port = 8080 |
334 | 334 | self.config = config |
@@ -403,6 +403,16 @@ def _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client): |
403 | 403 | self.sagemaker_runtime_client = LocalSagemakerRuntimeClient(self.config) |
404 | 404 | self.local_mode = True |
405 | 405 |
|
| 406 | + sagemaker_config_file = os.path.join(os.path.expanduser("~"), ".sagemaker", "config.yaml") |
| 407 | + if os.path.exists(sagemaker_config_file): |
| 408 | + try: |
| 409 | + import yaml |
| 410 | + except ImportError as e: |
| 411 | + logging.error(_module_import_error("yaml", "Local mode", "local")) |
| 412 | + raise e |
| 413 | + |
| 414 | + self.config = yaml.load(open(sagemaker_config_file, "r")) |
| 415 | + |
406 | 416 | def logs_for_job(self, job_name, wait=False, poll=5): |
407 | 417 | """ |
408 | 418 |
|
|
0 commit comments