"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"\n",
"\n",
"\n",
"\n",
"``` make\n",
"DIR=kornia\n",
"REPO=https://github.com/kornia/kornia.git\n",
"\n",
".PHONEY: clean all\n",
"\n",
"all: funcscount.txt torchfuncs.txt\n",
"\n",
"funcs.txt: ${DIR}/CHANGELOG.md\n",
"\t./findfuncs ${DIR} > $@\n",
"\n",
"funcscount.txt: funcs.txt\n",
"\twc -l $< > $@\n",
"\n",
"# add this after so that we can see incremental running of rules\n",
"torchfuncs.txt: funcs.txt\n",
"\tgrep 'torch' $< > $@\n",
"\n",
"kornia/CHANGELOG.md:\n",
"\tgit clone ${REPO}\n",
"\n",
"clean:\n",
"\t-rm funcs.txt funcscount.txt torchfuncs.txt\n",
"\n",
"distclean:\n",
"\t-rm -rf ${DIR}\n",
"\n",
"```\n",
"\n",
"\n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"\n",
"- findfuncs will need to be modified to add an argument\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"\n",
"\n",
"\n",
"\n",
"``` bash\n",
"#!/bin/bash\n",
"# this is our crude bash script to try and find all python functions\n",
"# in all the .py files within a directory tree\n",
"\n",
"#set -n # -n dry run good for syntax checking (without running any commands)\n",
"#set -x # tracing of simple commands on \n",
"#set -e # exit script on any fail return code\n",
"#set -u # error if expanding unset variable ... goood for catching typeos\n",
"\n",
"DIR=$1\n",
"[[ -z $DIR ]] && echo \"USAGE: $0 \" && exit -1\n",
"\n",
"find $DIR -name \"*.py\" | while read file\n",
"do\n",
" cat -n $file | grep 'def '| while read line def func rest; do\n",
"\tfunc=${func%%(*}\n",
"\techo $func $file: $line\n",
" done\t\n",
"done | sort \n",
"\n",
"```\n",
"\n",
"\n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(Markdown(\n",
" '''\n",
"- BT lets create a project directory : findfunc\n",
"- lets put script and makefile in it\n",
"- start with \n",
"``` make\n",
"funcs.txt: ~/kornia/CHANGELOG.md\n",
" ./findfuncs > $@\n",
"```\n",
"- lets move towards the following\n",
" 1. add target `kornia/CHANGELOG.md:` no dep rule: git clone `https://github.com/kornia/kornia.git`\n",
" 2. modify our findfuncs to take directory as a paramter and a usage if empty\n",
" 3. progressively add Make variables\n",
" 4. add a clean target and .PHONEY\n",
" 5. add a funccount.txt target dep: `funcs.txt` rule: `wc -l $< > $@`\n",
" 6. add `all` target with `funccount.txt` as dependency\n",
" 7. add `torchfuncs.txt` target dep: `funcs.txt` rule: `grep 'torch' $< > $@`\n",
"- makefile\n",
" '''))\n",
"display(Markdown(FileCodeBox(\"../src/findfuncs/Makefile\",\"make\")))\n",
"display(Markdown(\n",
" '''\n",
"- findfuncs will need to be modified to add an argument\n",
" '''))\n",
"display(Markdown(FileCodeBox(\"../src/findfuncs/findfuncs\", \"bash\")))"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"hide_input": true,
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
},
"rise": {
"autolaunch": false,
"enable_chalkboard": true,
"footer": "SLS -- Lecture 4",
"header": "Unix : Editors and Make",
"height": "100%",
"scroll": true,
"start_slideshow_at": "selected",
"transition": "none",
"width": "100%"
}
},
"nbformat": 4,
"nbformat_minor": 5
}