Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d909b5d

Browse files
committed
[CI] Rewrite get_all_files to use Path.glob
Rather than call `find` for hard-code list of folder, search for all `.py` files in folders ending with `_source` excluding those in `data folder
1 parent d1f4760 commit d909b5d

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

.jenkins/get_files_to_run.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
from typing import List
2-
from subprocess import run
32
import json
43
import os
54
from pathlib import Path
65
from remove_runnable_code import remove_runnable_code
76

87

98
# Calculate repo base dir
10-
REPO_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9+
REPO_BASE_DIR = Path(__file__).absolute().parent.parent
1110

12-
def get_all_files(encoding="utf-8") -> List[str]:
13-
sources = [
14-
"beginner_source",
15-
"intermediate_source",
16-
"advanced_source",
17-
"recipes_source",
18-
"prototype_source",
19-
]
20-
cmd = ["find"] + sources + ["-name", "*.py", "-not", "-path", "*/data/*"]
2111

22-
return run(cmd, capture_output=True, cwd=REPO_BASE_DIR).stdout.decode(encoding).splitlines()
12+
def get_all_files() -> List[str]:
13+
sources = [x.relative_to(REPO_BASE_DIR) for x in REPO_BASE_DIR.glob("*_source/**/*.py") if 'data' not in x.parts]
14+
return [str(x) for x in sources]
2315

2416

2517
def calculate_shards(all_files, num_shards=20):
26-
with open(os.path.join(REPO_BASE_DIR, ".jenkins", "metadata.json")) as fp:
18+
with (REPO_BASE_DIR / ".jenkins" / "metadata.json").open() as fp:
2719
metadata = json.load(fp)
2820
sharded_files = [(0.0, []) for _ in range(num_shards)]
2921

0 commit comments

Comments
 (0)