# Copyright (C) 2010  Michał Masłowski  <mtjm@mtjm.eu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


DOCS = README.html NEWS.html

PKG = urlreader

SRCS := $(shell find $(PKG) -name '*.py')
TESTS := $(shell find tests_$(PKG) -name '*.py')

# Support both Debian's modified docutils script names and the
# upstream ones.
ifdef RST2HTML
else ifeq ($(shell which rst2html 2>/dev/null),)
RST2HTML=rst2html.py
else
RST2HTML=rst2html
endif

all: $(DOCS) Makefile

check: $(SRCS) $(TESTS) Makefile
	PYTHONPATH=.:$$PYTHONPATH \
		coverage run --source=$(PKG) --branch tests_$(PKG)/__init__.py
	coverage html

pyflakes: $(SRCS) Makefile
	@pyflakes $(PKG)

# Many warnings are disabled, since pylint doesn't understand some code used.
pylint-srcs: $(SRCS) Makefile
	@pylint \
		--output-format=colorized \
		--include-ids=y \
		--report=n \
		--max-args=6 \
		--disable=F0401 \
		--disable=E0611 \
		--disable=E0702 \
		--disable=R0903 \
		$(PKG)

pylint-tests: $(TESTS) Makefile
	@pylint \
		--output-format=colorized \
		--include-ids=y \
		--report=n \
		--disable=W0401 \
		--disable=W0603 \
		--disable=R0904 \
		--disable=W0404 \
		--generated-members=resource_filename,md5 \
		--good-names=setUp,tearDown \
		tests_$(PKG)

pep8: $(SRCS) Makefile
	@pep8 $(PKG) tests_$(PKG)

style: pyflakes pylint-srcs pylint-tests pep8 Makefile

%.html: %.txt Makefile
	$(RST2HTML) $< $@

.PHONY: all pep8 style check pyflakes pylint-srcs pylint-tests
