我有一棵看起来像这样的文件树:
.
├── Makefile
├── README.md
├── exercises
│ ├── 100-exercises.ipynb
│ ├── 200-exercises.ipynb
│ ├── 300-exercises.ipynb
│ └── 400-exercises.ipynb
├── notes
│ ├── 101-notes-pandas.ipynb
│ ├── 102-notes-matplotlib-1.ipynb
│ ├── 103-notes-numpy-scipy.ipynb
│ └── 104-notes-matplotlib-seaborn.ipynb
└── tasks
├── 101-tasks-pandas.ipynb
├── 102-tasks-matplotlib-1.ipynb
├── 103-tasks-numpy-scipy.ipynb
└── 104-tasks-matplotlib-seaborn.ipynb
我想添加一些仅根据文件名中的模式对文件进行操作的目标。例如:
make lecture-1
make lecture-1-notes
make lecture-1-exercises
make lecture-2
make notes
make exercises
...
etc.
wherelecture-1指的是文件名以1eg开头的目标集tasks/101-tasks-pandas.ipynb- 要清楚,模式是:
notes -> ./notes/*exercises -> ./exercises/*tasks -> ./tasks/*lecture-1 -> ./*/1[0-9][0-9]*.ipynblecture-2 -> ./*/2[0-9][0-9]*.ipynblecture-1-notes -> ./notes/1[0-9][0-9]*.ipynb
很长的路要走,每个目标都有一个单独的目标,但我觉得必须有某种模式/正则表达式匹配可以避免这种情况。
编辑:
有关在每个目标上完成的操作的更多信息,我有一个可执行命令,它基本上将 IPython 笔记本转换为 HTML。这在 make 中存储为变量RENDER_HTML
例如,目前要渲染 notes 文件夹中的所有内容,我的 Makefile 中有以下部分:
RENDER_HTML=jupyter nbconvert --execute --to html
NOTES_TARGETS=$(wildcard ./notes/*.ipynb)
...
.PHONY: notes
notes: ${NOTES_TARGETS}
@mkdir -p $@/html/
${RENDER_HTML} $^
@mv $@/*.html $@/html/