|
| 1 | +# Makefile for working with a Python module |
| 2 | + |
| 3 | +########################################################################## |
| 4 | +## REQUIREMENTS |
| 5 | +# |
| 6 | +# This file requires certain dependencies for full functionality. |
| 7 | +# |
| 8 | +# The following Python packages are required: |
| 9 | +# pytest For running tests |
| 10 | +# coverage For running test coverage |
| 11 | +# pylint For running linting on code |
| 12 | +# setuptools For creating distributions |
| 13 | +# |
| 14 | +# The following command line utilities are required: |
| 15 | +# cloc For counting code |
| 16 | +# |
| 17 | + |
| 18 | +########################################################################## |
| 19 | +## VARIABLES |
| 20 | + |
| 21 | +MODULE = fooof |
| 22 | +LINT_FILE = _lint.txt |
| 23 | + |
| 24 | +########################################################################## |
| 25 | +## CODE COUNTING |
| 26 | + |
| 27 | +# Run all counts |
| 28 | +run-counts: |
| 29 | + @make count-size |
| 30 | + @make count-module |
| 31 | + @make count-tests |
| 32 | + |
| 33 | +# Count the total number of lines in the module |
| 34 | +count-size: |
| 35 | + @printf "\n\nCHECK MODULE SIZE:" |
| 36 | + @printf "\nNumber of lines of code & comments in the module: " |
| 37 | + @find ./$(MODULE) -name "*.py" -type f -exec grep . {} \; | wc -l |
| 38 | + |
| 39 | +# Count module code with CLOC, excluding test files |
| 40 | +count-module: |
| 41 | + @printf "\n\nCLOC OUTPUT - MODULE: \n" |
| 42 | + @cloc $(MODULE) --exclude-dir='tests' |
| 43 | + |
| 44 | +# Count test code, with CLOC |
| 45 | +count-tests: |
| 46 | + @printf "\n\nCLOC OUTPUT - TEST FILES: \n" |
| 47 | + @cloc $(MODULE)/tests --exclude-dir='test_files' |
| 48 | + |
| 49 | +########################################################################## |
| 50 | +## CODE TESTING |
| 51 | + |
| 52 | +# Run all tests |
| 53 | +run-tests: |
| 54 | + @make coverage |
| 55 | + @make doctests |
| 56 | + |
| 57 | +# Run tests |
| 58 | +tests: |
| 59 | + @printf "\n\nRUN TESTS: \n" |
| 60 | + @pytest |
| 61 | + |
| 62 | +# Run test coverage |
| 63 | +coverage: |
| 64 | + @printf "\n\nRUN TESTS: \n" |
| 65 | + @coverage run --source $(MODULE) -m py.test |
| 66 | + @printf "\n\nCHECK COVERAGE: \n" |
| 67 | + @coverage report --omit="*/tests*" |
| 68 | + |
| 69 | +# Run doctests |
| 70 | +doctests: |
| 71 | + @printf "\n\nCHECK DOCTEST EXAMPLES: \n" |
| 72 | + @pytest --doctest-modules --ignore=$(MODULE)/tests $(MODULE) |
| 73 | + |
| 74 | +########################################################################## |
| 75 | +## CODE LINTING |
| 76 | + |
| 77 | +# Run pylint and print summary |
| 78 | +# Note: --exit-zero is because pylint throws an error when called |
| 79 | +# from a Makefile. Unclear why, but this avoids it stopping. |
| 80 | +run-lints: |
| 81 | + @printf "\n\nRUN PYLINT ACROSS MODULE: \n" |
| 82 | + @pylint $(MODULE) --ignore tests --exit-zero > $(LINT_FILE) |
| 83 | + @tail -n4 $(LINT_FILE) |
| 84 | + |
| 85 | +########################################################################## |
| 86 | +## SUMMARY |
| 87 | + |
| 88 | +# Run a summary of the module |
| 89 | +summary: |
| 90 | + @make run-counts |
| 91 | + @make run-tests |
| 92 | + @make run-lints |
| 93 | + |
| 94 | +########################################################################## |
| 95 | +## DISTRIBUTION |
| 96 | + |
| 97 | +# Create a distribution build of the module |
| 98 | +dist: |
| 99 | + @python setup.py sdist bdist_wheel |
| 100 | + |
| 101 | +# Clear out distribution files |
| 102 | +clear-dist: |
| 103 | + @rm -rf build dist $(MODULE).egg-info |
0 commit comments