3
3
import urllib
4
4
from contextlib import contextmanager
5
5
from subprocess import Popen
6
- from typing import Any , Callable , Optional , Tuple
6
+ from typing import Any , Callable , List , Optional , Tuple , Union
7
7
8
- from lightning .data .constants import _IS_IN_STUDIO , _LIGHTNING_CLOUD_LATEST
9
-
10
- from typing import Optional , List , Tuple , Union
11
- import os
12
8
import urllib3
13
9
10
+ from lightning .data .constants import _IS_IN_STUDIO , _LIGHTNING_CLOUD_LATEST
11
+
14
12
if _LIGHTNING_CLOUD_LATEST :
15
- from lightning_cloud .rest_client import LightningClient
16
13
from lightning_cloud .openapi import (
17
14
ProjectIdDatasetsBody ,
18
15
V1DatasetType ,
19
16
)
20
17
from lightning_cloud .openapi .rest import ApiException
18
+ from lightning_cloud .rest_client import LightningClient
21
19
22
20
23
21
def _create_dataset (
@@ -34,9 +32,7 @@ def _create_dataset(
34
32
name : Optional [str ] = None ,
35
33
version : Optional [int ] = None ,
36
34
):
37
- """
38
- Create a dataset with metadata information about its source and destination
39
- """
35
+ """Create a dataset with metadata information about its source and destination."""
40
36
project_id = os .getenv ("LIGHTNING_CLOUD_PROJECT_ID" , None )
41
37
cluster_id = os .getenv ("LIGHTNING_CLUSTER_ID" , None )
42
38
user_id = os .getenv ("LIGHTNING_USER_ID" , None )
@@ -71,14 +67,14 @@ def _create_dataset(
71
67
type = dataset_type ,
72
68
version = version ,
73
69
),
74
- project_id = project_id
70
+ project_id = project_id ,
75
71
)
76
72
except (ApiException , urllib3 .exceptions .HTTPError ) as ex :
77
- # Note: This function can be called in a distributed way.
73
+ # Note: This function can be called in a distributed way.
78
74
# There is a race condition where one machine might create the entry before another machine
79
75
# and this request would fail with duplicated key
80
- # In this case, it is fine not to raise
81
- if ' already exists' in str (ex .body ):
76
+ # In this case, it is fine not to raise
77
+ if " already exists" in str (ex .body ):
82
78
pass
83
79
else :
84
80
raise ex
0 commit comments