-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathpixel_remove.py
66 lines (55 loc) · 3.02 KB
/
pixel_remove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# vertex-ai-mlops/architectures/tracking/setup/pixel/pixel_remove.py
# this file, pixel_remove.py, will remove the tracking from files in the repository
# to see files this will impact, first run pixel_list.py
import os
import json
# this file is in: vertex-ai-mlops/architectures/tracking/setup/pixel/pixel_remove.py
for root, dirs, files in os.walk('../../../../.'):
for file in files:
if file.endswith(('.md', '.ipynb')) and not root.endswith('.ipynb_checkpoints'):
print('Evaluating: ', os.path.join(root, file))
if file.endswith('.md'):
update = False
# read file contents
with open(os.path.join(root, file), 'r') as reader:
content = reader.readlines()
# check for pixel track
if content[0].startswith('![tracker](https://'):
content = content[1:]
update = True
# remove any blank lines at the start of the file (these were empty spaces/lines after the tracker)
while True:
if content[0] == '\n':
content = content[1:]
else:
break
# update files with pixel track - remove the tracking
if update:
print('Remove tracking from: ', file)
with open(os.path.join(root, file), 'w') as writer:
writer.writelines(content)
elif file.endswith('.ipynb'):
update = False
# read file contents
with open(os.path.join(root, file), 'r') as reader:
content = json.loads(reader.read())
# check for pixel track
for cell in content['cells']:
if cell['cell_type'] == 'markdown':
if cell['source'][0].startswith('![tracker](https://'):
cell['source'] = cell['source'][1:]
update = True
# remove any blank lines at the start of the file/cell (these were empty spaces/lines after the tracker)
while True:
if cell['source'][0] == '\n':
cell['source'] = cell['source'][1:]
else:
break
# only review the first markdown cell then break the for loop
break
# update files with pixel track - remove the tracking
if update:
print('Remove tracking from: ', file)
with open(os.path.join(root, file), 'w') as writer:
writer.write(json.dumps(content))
print('Done with evaluation.')