Skip to content

Commit

Permalink
Merge pull request fooof-tools#172 from fooof-tools/make
Browse files Browse the repository at this point in the history
Add module makefile
  • Loading branch information
TomDonoghue authored May 15, 2020
2 parents dce05cb + 5444db3 commit 2ac88b4
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 30 deletions.
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Makefile for working with a Python module

##########################################################################
## REQUIREMENTS
#
# This file requires certain dependencies for full functionality.
#
# The following Python packages are required:
# pytest For running tests
# coverage For running test coverage
# pylint For running linting on code
# setuptools For creating distributions
#
# The following command line utilities are required:
# cloc For counting code
#

##########################################################################
## VARIABLES

MODULE = fooof
LINT_FILE = _lint.txt

##########################################################################
## CODE COUNTING

# Run all counts
run-counts:
@make count-size
@make count-module
@make count-tests

# Count the total number of lines in the module
count-size:
@printf "\n\nCHECK MODULE SIZE:"
@printf "\nNumber of lines of code & comments in the module: "
@find ./$(MODULE) -name "*.py" -type f -exec grep . {} \; | wc -l

# Count module code with CLOC, excluding test files
count-module:
@printf "\n\nCLOC OUTPUT - MODULE: \n"
@cloc $(MODULE) --exclude-dir='tests'

# Count test code, with CLOC
count-tests:
@printf "\n\nCLOC OUTPUT - TEST FILES: \n"
@cloc $(MODULE)/tests --exclude-dir='test_files'

##########################################################################
## CODE TESTING

# Run all tests
run-tests:
@make coverage
@make doctests

# Run tests
tests:
@printf "\n\nRUN TESTS: \n"
@pytest

# Run test coverage
coverage:
@printf "\n\nRUN TESTS: \n"
@coverage run --source $(MODULE) -m py.test
@printf "\n\nCHECK COVERAGE: \n"
@coverage report --omit="*/tests*"

# Run doctests
doctests:
@printf "\n\nCHECK DOCTEST EXAMPLES: \n"
@pytest --doctest-modules --ignore=$(MODULE)/tests $(MODULE)

##########################################################################
## CODE LINTING

# Run pylint and print summary
# Note: --exit-zero is because pylint throws an error when called
# from a Makefile. Unclear why, but this avoids it stopping.
run-lints:
@printf "\n\nRUN PYLINT ACROSS MODULE: \n"
@pylint $(MODULE) --ignore tests --exit-zero > $(LINT_FILE)
@tail -n4 $(LINT_FILE)

##########################################################################
## SUMMARY

# Run a summary of the module
summary:
@make run-counts
@make run-tests
@make run-lints

##########################################################################
## DISTRIBUTION

# Create a distribution build of the module
dist:
@python setup.py sdist bdist_wheel

# Clear out distribution files
clear-dist:
@rm -rf build dist $(MODULE).egg-info
30 changes: 0 additions & 30 deletions summary.sh

This file was deleted.

0 comments on commit 2ac88b4

Please sign in to comment.