Skip to content

Commit 1ec3d8e

Browse files
committed
makefile now only runs modified tutorials by default
1 parent ac24a0b commit 1ec3d8e

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

.github/get_modified_tutorials.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
from git import Repo
33

44

5-
def main(repo_path):
5+
def main(repo_path, main_branch, **kw):
66
r = Repo(repo_path)
77

88
# NOTE: assumes the main branch is named "main"
99
files_changed = r.git.diff(
10-
f'{str(r.head.object.hexsha)}..origin/main',
10+
f'{str(r.head.object.hexsha)}..{main_branch}',
1111
'--name-only').split("\n")
1212
files_changed = [f for f in files_changed if f.endswith('.ipynb')]
1313
if files_changed:
1414
print(" ".join(files_changed))
1515

1616

1717
if __name__ == "__main__":
18-
try:
19-
repo_path = sys.argv[1]
20-
except IndexError:
21-
print("ERROR: did not receive a repo path.\n"
22-
"Usage: get_modified_tutorials.py <ROOT TUTORIALS REPO PATH>")
23-
sys.exit(1)
18+
from argparse import ArgumentParser
2419

25-
main(repo_path)
20+
parser = ArgumentParser()
21+
parser.add_argument(
22+
'-r', '--repo-path',
23+
dest='repo_path',
24+
default='.',
25+
help='The path to the root of the astropy-tutorials repository folder.'
26+
)
27+
parser.add_argument(
28+
'--main-branch',
29+
dest='main_branch',
30+
default='main',
31+
help=('The name of the main branch to compare against. Default is '
32+
'"main" but on CI it should be origin/main.')
33+
)
34+
args = parser.parse_args()
35+
main(**vars(args))

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
default: all
1+
default: build
22

3-
all: envcheck execute convert
3+
TUTORIALS_MAIN_BRANCH ?= main
4+
MODIFIED := $(shell python .github/get_modified_tutorials.py --main-branch $(TUTORIALS_MAIN_BRANCH))
5+
6+
build: envcheck execute convert
7+
buildall: envcheck executeall convertall
48

59
envcheck:
610
python -c "import pkg_resources; pkg_resources.require(open('pip-requirements.txt', mode='r')); print('Your environment is all set!')"
711

812
execute:
9-
nbcollection execute --timeout=600 --flatten --build-path=. -v tutorials
13+
nbcollection execute --timeout=600 --flatten --build-path=. -v ${MODIFIED}
1014

1115
convert:
16+
nbcollection convert --flatten --build-path=. -v --make-index --index-template=templates/index.tpl ${MODIFIED}
17+
18+
executeall:
19+
nbcollection execute --timeout=600 --flatten --build-path=. -v tutorials
20+
21+
convertall:
1222
nbcollection convert --flatten --build-path=. -v --make-index --index-template=templates/index.tpl tutorials
1323

1424
clean:
1525
rm -rf _build
1626

17-
.PHONY: all clean execute convert
27+
.PHONY: all clean execute convert executeall convertall build buildall

0 commit comments

Comments
 (0)