Skip to content

Commit df27924

Browse files
aliabddawoodkhan82
authored andcommitted
Excluding untracked files from demo notebook check action (#2897)
* excluding untracked files from wget * changelog
1 parent 1b1b49a commit df27924

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ No changes to highlight.
3030
## Full Changelog:
3131
* The `default_enabled` parameter of the `Blocks.queue` method has no effect by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2876](https://github.com/gradio-app/gradio/pull/2876)
3232
* Added typing to several Python files in codebase by [@abidlabs](https://github.com/abidlabs) in [PR 2887](https://github.com/gradio-app/gradio/pull/2887)
33+
* Excluding untracked files from demo notebook check action by [@aliabd](https://github.com/aliabd) in [PR 2897](https://github.com/gradio-app/gradio/pull/2897)
3334

3435
## Contributors Shoutout:
3536
* @JaySmithWpg for making their first contribution to gradio!

demo/generate_notebooks.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
import os
33
import json
44
import random
5+
import subprocess
56

67
GRADIO_DEMO_DIR = os.getcwd()
78
DEMOS_TO_SKIP = {"all_demos", "reset_components", "custom_path", "kitchen_sink_random"}
89

910
demos = os.listdir(GRADIO_DEMO_DIR)
1011
demos = [demo for demo in demos if demo not in DEMOS_TO_SKIP and os.path.isdir(os.path.join(GRADIO_DEMO_DIR, demo)) and os.path.exists(os.path.join(GRADIO_DEMO_DIR, demo, "run.py"))]
1112

13+
def git_tracked(demo, file):
14+
osstdout = subprocess.Popen(f"cd {demo} && git ls-files --error-unmatch {file}", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
15+
osstdout.wait()
16+
return not osstdout.returncode
17+
1218
for demo in demos:
1319
nb = nbf.v4.new_notebook()
1420
text = f"# Gradio Demo: {demo}"
@@ -20,17 +26,18 @@
2026
"""
2127

2228
files = os.listdir(os.path.join(GRADIO_DEMO_DIR, demo))
23-
skip = ["run.py", "run.ipynb", "setup.sh", ".gitignore", "requirements.txt", "DESCRIPTION.md", "screenshot.png", "screenshot.gif", ".DS_Store", "flagged", "__pycache__"]
24-
files = [file for file in files if file not in skip]
29+
skip = ["run.py", "run.ipynb", "setup.sh", ".gitignore", "requirements.txt", "DESCRIPTION.md", "screenshot.png", "screenshot.gif"]
30+
files = [file for file in files if file not in skip if git_tracked(demo, file)]
2531
files.sort()
2632
if files:
2733
get_files = "# Downloading files from the demo repo\nimport os"
2834
for file in files:
2935
if os.path.isdir(os.path.join(GRADIO_DEMO_DIR, demo, file)):
30-
get_files += f"\nos.mkdir('{file}')"
3136
sub_files = os.listdir(os.path.join(GRADIO_DEMO_DIR, demo, file))
32-
sub_files = [sub for sub in sub_files if sub not in skip]
37+
sub_files = [sub for sub in sub_files if sub not in skip if git_tracked(demo, f"{file}/{sub}")]
3338
sub_files.sort()
39+
if sub_files:
40+
get_files += f"\nos.mkdir('{file}')"
3441
for sub_file in sub_files:
3542
get_files += f"\n!wget -q -O {file}/{sub_file} https://github.com/gradio-app/gradio/raw/main/demo/{demo}/{file}/{sub_file}"
3643
else:

0 commit comments

Comments
 (0)