Skip to content

Commit 6927957

Browse files
committed
Move to new path
1 parent e552363 commit 6927957

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ venv/
112112
ENV/
113113
env.bak/
114114
venv.bak/
115+
.idea/
115116

116117
# Spyder project settings
117118
.spyderproject

src/iterative_telemetry/__init__.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,44 @@ def _find_or_create_user_id():
196196
IDs are generated randomly with UUID.
197197
"""
198198

199-
config_dir = user_config_dir("telemetry", "iterative")
200-
fname = os.path.join(config_dir, "user_id")
199+
legacy_dvc_config_dir = user_config_dir("dvc", "iterative")
200+
config_dir = user_config_dir(os.path.join("iterative", "telemetry"), "iterative")
201+
legacy_user_id_file = os.path.join(legacy_dvc_config_dir, "user_id")
202+
user_id_file = os.path.join(config_dir, "user_id")
201203
lockfile = os.path.join(config_dir, "user_id.lock")
202204

203-
# Since the `fname` and `lockfile` are under the global config,
204-
# we need to make sure such directory exist already.
205-
os.makedirs(config_dir, exist_ok=True)
206-
207205
try:
208206
with FileLock( # pylint: disable=abstract-class-instantiated
209207
lockfile, timeout=5
210208
):
211209
try:
212-
with open(fname, encoding="utf8") as fobj:
210+
211+
# Backwards compatibility with DVC legacy telemetry file location
212+
# Will only try to copy over if config_dir doesn't exist (first run per machine)
213+
if legacy_dvc_config_dir.exists() and not config_dir.exists():
214+
with open(legacy_user_id_file, encoding="utf8") as fobj_legacy:
215+
with open(user_id_file, "w", encoding="utf8") as fobj_new:
216+
user_id = json.load(fobj_legacy)["user_id"]
217+
json.dump({"user_id": user_id}, fobj_new)
218+
219+
except (FileNotFoundError, ValueError, KeyError):
220+
221+
# Fail silently
222+
pass
223+
224+
try:
225+
226+
# Since the `user_id_file` and `lockfile` are under the global config,
227+
# we need to make sure such directory exist already.
228+
os.makedirs(config_dir, exist_ok=True)
229+
230+
with open(user_id_file, encoding="utf8") as fobj:
213231
user_id = json.load(fobj)["user_id"]
214232

215233
except (FileNotFoundError, ValueError, KeyError):
216234
user_id = str(uuid.uuid4())
217235

218-
with open(fname, "w", encoding="utf8") as fobj:
236+
with open(user_id_file, "w", encoding="utf8") as fobj:
219237
json.dump({"user_id": user_id}, fobj)
220238

221239
return user_id

0 commit comments

Comments
 (0)