Skip to content

Commit 74d0544

Browse files
authored
Merge branch 'develop' into PNO/QQC-3095-project-get-overview
2 parents 34620a4 + 0874c15 commit 74d0544

File tree

9 files changed

+762
-364
lines changed

9 files changed

+762
-364
lines changed

examples/README.md

Lines changed: 348 additions & 72 deletions
Large diffs are not rendered by default.

examples/format_notebooks.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,85 +5,86 @@
55
from yapf.yapflib.yapf_api import FormatCode
66

77
BANNER_CELL = {
8-
"cell_type":
9-
"markdown",
10-
"id":
11-
"db768cda",
8+
"cell_type": "markdown",
9+
"id": "db768cda",
1210
"metadata": {},
1311
"source": [
14-
"<td>\n",
15-
" <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n",
16-
"</td>"
17-
]
12+
"<td>",
13+
' <a target="_blank" href="https://labelbox.com" ><img src="https://labelbox.com/blog/content/images/2021/02/logo-v4.svg" width=256/></a>',
14+
"</td>",
15+
],
1816
}
1917

2018
LINK_CELL = {
21-
"cell_type":
22-
"markdown",
23-
"id":
24-
"cb5611d0",
19+
"cell_type": "markdown",
20+
"id": "cb5611d0",
2521
"metadata": {},
2622
"source": [
27-
"<td>\n", "<a href=\"{colab}\" target=\"_blank\"><img\n",
28-
"src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>\n",
29-
"</td>\n", "\n", "<td>\n",
30-
"<a href=\"{github}\" target=\"_blank\"><img\n",
31-
"src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n",
32-
"</td>"
33-
]
23+
"<td>",
24+
'<a href="{colab}" target="_blank"><img',
25+
'src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>',
26+
"</td>",
27+
"\n",
28+
"<td>",
29+
'<a href="{github}" target="_blank"><img',
30+
'src="https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white" alt="GitHub"></a>',
31+
"</td>",
32+
],
3433
}
3534

36-
COLAB_TEMPLATE = "https://colab.research.google.com/github/Labelbox/labelbox-python/blob/master/examples/{filename}"
37-
GITHUB_TEMPLATE = "https://github.com/Labelbox/labelbox-python/tree/master/examples/{filename}"
35+
COLAB_TEMPLATE = "https://colab.research.google.com/github/Labelbox/labelbox-python/blob/develop/examples/{filename}"
36+
GITHUB_TEMPLATE = (
37+
"https://github.com/Labelbox/labelbox-python/tree/develop/examples/{filename}"
38+
)
3839

3940

4041
def format_cell(source):
41-
for line in source.split('\n'):
42-
if line.strip().startswith(('!', '%')):
42+
for line in source.split("\n"):
43+
if line.strip().startswith(("!", "%")):
4344
return source
4445
return FormatCode(source, style_config="google")[0]
4546

4647

4748
def add_headers(file_name):
48-
with open(file_name, 'r') as file:
49+
with open(file_name, "r") as file:
4950
data = json.load(file)
5051

5152
colab_path = COLAB_TEMPLATE.format(filename=file_name)
5253
github_path = GITHUB_TEMPLATE.format(filename=file_name)
5354

5455
link_cell = deepcopy(LINK_CELL)
5556

56-
link_cell['source'][1] = link_cell['source'][1].format(colab=colab_path)
57-
link_cell['source'][6] = link_cell['source'][6].format(github=github_path)
57+
link_cell["source"][1] = link_cell["source"][1].format(colab=colab_path)
58+
link_cell["source"][6] = link_cell["source"][6].format(github=github_path)
5859

59-
data['cells'] = [BANNER_CELL, link_cell] + data['cells']
60+
data["cells"] = [BANNER_CELL, link_cell] + data["cells"]
6061

61-
with open(file_name, 'w') as file:
62+
with open(file_name, "w") as file:
6263
file.write(json.dumps(data, indent=4))
6364

6465
print("Formatted", file_name)
6566

6667

6768
def format_file(file_name):
68-
with open(file_name, 'r') as file:
69+
with open(file_name, "r") as file:
6970
data = json.load(file)
7071

7172
idx = 1
72-
for cell in data['cells']:
73-
if cell['cell_type'] == 'code':
74-
cell['execution_count'] = idx
75-
if isinstance(cell['source'], list):
76-
cell['source'] = ''.join(cell['source'])
77-
cell['source'] = format_cell(cell['source'])
73+
for cell in data["cells"]:
74+
if cell["cell_type"] == "code":
75+
cell["execution_count"] = idx
76+
if isinstance(cell["source"], list):
77+
cell["source"] = "".join(cell["source"])
78+
cell["source"] = format_cell(cell["source"])
7879
idx += 1
79-
if cell['source'].endswith('\n'):
80-
cell['source'] = cell['source'][:-1]
80+
if cell["source"].endswith("\n"):
81+
cell["source"] = cell["source"][:-1]
8182

82-
with open(file_name, 'w') as file:
83+
with open(file_name, "w") as file:
8384
file.write(json.dumps(data, indent=4))
8485
print("Formatted", file_name)
8586

8687

87-
if __name__ == '__main__':
88-
for file in glob.glob("*/*.ipynb"):
88+
if __name__ == "__main__":
89+
for file in glob.glob("**/*.ipynb", recursive=True):
8990
format_file(file)

0 commit comments

Comments
 (0)