Skip to content

Commit ba644c2

Browse files
committed
add makefile
1 parent dce05cb commit ba644c2

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

Makefile

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

0 commit comments

Comments
 (0)