PEP8=pep8
COVERAGE_FILES=`find juju -name "*py" | grep -v "tests\|lib/mocker.py\|lib/testing.py"`

all:
	@echo "You've just watched the fastest build on earth."

tests:
	./test

coverage:
	python -c "import coverage as c; c.main()" run ./test
	python -c "import coverage as c; c.main()" html -d htmlcov $(COVERAGE_FILES)
	gnome-open htmlcov/index.html

ftests:
	./test --functional

tags:
	@ctags --python-kinds=-iv -R juju

etags:
	@ctags -e --python-kinds=-iv -R juju


present_pep8=$(shell which $(PEP8))
present_pyflakes=$(shell which pyflakes)
warn_missing_linters:
	@test -n "$(present_pep8)" || echo "WARNING: $(PEP8) not installed."
	@test -n "$(present_pyflakes)" || echo "WARNING: pyflakes not installed."


# "check": Check uncommitted changes for lint.
check_changes=$(shell bzr status -S | grep '^[ +]*[MN]' | awk '{print $$2;}' | grep "\\.py$$")
check: warn_missing_linters
	@test -z $(present_pep8) || (echo $(check_changes) | xargs -r $(PEP8) --repeat)
	@test -z $(present_pyflakes) || (echo $(check_changes) | xargs -r pyflakes)


# "review": Check all changes compared to trunk for lint.
review_changes=$(shell bzr status -S -r ancestor:$(JUJU_TRUNK) | grep '^[ +]*[MN]' | awk '{print $$2;}' | grep "\\.py$$")
review: warn_missing_linters
	#@test -z $(present_pep8) || (echo $(review_changes) | xargs -r $(PEP8) --repeat)
	@test -z $(present_pyflakes) || (echo $(review_changes) | xargs -r pyflakes)


ptests_changes=$(shell bzr status -S -r branch::prev | grep -P '^[ +]*[MN]' | awk '{print $$2;}'| grep "test_.*\\.py$$")
ptests:
	@echo $(ptests_changes) | xargs -r ./test

btests_changes=$(shell bzr status -S -r ancestor:$(JUJU_TRUNK)/ | grep "test.*\\.py$$" | awk '{print $$2;}')
btests:
	@./test $(btests_changes)

.PHONY: tags check review warn_missing_linters
