03. Makefiles
Makefiles
ND9991 C04 L02 A03 Makefiles
You can follow along with Noah's code here.
Noah's Makefile
Here is what is contained in Noah's Makefile:
setup:
python3 -m venv ~/.myrepo
install:
pip install -r requirements.txt
test:
python -m pytest -vv --cov=myrepolib tests/*.py
python -m pytest --nbval notebook.ipynb
lint:
pylint --disable=R,C myrepolib cli web
all: install lint test
Note that each line is indented with a tab.
Noah's requirements.txt
Below are the libraries included in Noah's requirements.txt file:
pytest
pylint
jupyter
pytest-cov
pandas
nbval
click
flask
requests
Breaking Down the Makefile
If you haven't seen a Makefile before, this may seem like a lot of random commands all jumbled together. Let's briefly go through each.
setup: You have seen most of this line before, which is dealing with our Python 3 virtual environment.install: This installs the requirements for our environment. In our case, it also install thepytestandpylintlibraries used later on in the Makefile.test: This is broken into two parts for testing.- First, it will use
.pyfiles in thetestsdirectory. The-vvflag ensures short test durations are still shown (see documentation), while the-covflag helps to calculate what the test coverage of the code is (see documentation) in a given directory. - The second line is used to test Jupyter Notebook cells. The
--nbvalflag makes pytest pay attention to jupyter notebooks (see documentation).
- First, it will use
lint: This will lint what is in themyrepolibdirectory, as well as thecli.pyandweb.pyfiles in our current directory (see video). The--disable=R,Cis used to disable the "convention" (C) and "refactor" (R) message classes (see related Stack Overflow post).all: You may notice this line looks a little different than the above lines, with the commands on the same line. This will execute ourinstall,lintandtestcommands.
After Makefile Creation
Once the Makefile is created, you can use:
make installmake lint
To install dependencies and test your code.
Makefiles