@@ -199,29 +199,26 @@ def _find_or_create_user_id():
199
199
config_dir = user_config_dir (
200
200
os .path .join ("iterative" , "telemetry" ), "iterative"
201
201
)
202
- user_id_file = os .path .join (config_dir , "user_id" )
202
+ fname = os .path .join (config_dir , "user_id" )
203
203
lockfile = os .path .join (config_dir , "user_id.lock" )
204
204
205
- # Since the `user_id_file` and `lockfile` are under the
206
- # global config, we need to make sure such directory exist
207
- # already.
205
+ # Since the `fname` and `lockfile` are under the global config,
206
+ # we need to make sure such directory exist already.
208
207
os .makedirs (config_dir , exist_ok = True )
209
-
210
208
try :
211
209
with FileLock ( # pylint: disable=abstract-class-instantiated
212
210
lockfile , timeout = 5
213
211
):
214
-
215
212
try :
216
- with open (user_id_file , encoding = "utf8" ) as fobj :
213
+ with open (fname , encoding = "utf8" ) as fobj :
217
214
user_id = json .load (fobj )["user_id" ]
218
215
219
216
except (FileNotFoundError , ValueError , KeyError ):
220
217
221
218
# Backwards compatibility with DVC legacy telemetry location.
222
219
user_id = _try_read_legacy_user_id () or str (uuid .uuid4 ())
223
220
224
- with open (user_id_file , "w" , encoding = "utf8" ) as fobj :
221
+ with open (fname , "w" , encoding = "utf8" ) as fobj :
225
222
json .dump ({"user_id" : user_id }, fobj )
226
223
227
224
return user_id
@@ -232,12 +229,10 @@ def _find_or_create_user_id():
232
229
233
230
234
231
def _try_read_legacy_user_id ():
235
- legacy_user_id_file = os .path .join (
236
- user_config_dir ("dvc" , "iterative" ), "user_id"
237
- )
232
+ fname = os .path .join (user_config_dir ("dvc" , "iterative" ), "user_id" )
238
233
239
234
try :
240
- with open (legacy_user_id_file , encoding = "utf8" ) as fobj :
235
+ with open (fname , encoding = "utf8" ) as fobj :
241
236
return json .load (fobj )["user_id" ]
242
237
243
238
except (FileNotFoundError , ValueError , KeyError ):
0 commit comments