fix all-tests
[nepi.git] / Makefile
1 SRCDIR      = $(CURDIR)/src
2 TESTDIR     = $(CURDIR)/test
3 TESTLIB     = $(TESTDIR)/lib
4 BUILDDIR    = $(CURDIR)/build/lib
5 DISTDIR     = $(CURDIR)/dist
6
7 PYPATH = $(BUILDDIR):$(TESTLIB):$(PYTHONPATH)
8 COVERAGE = $(or $(shell which coverage), $(shell which python-coverage), \
9            coverage)
10
11 all: clean
12         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" ./setup.py build
13
14 install: all
15         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" ./setup.py install
16
17 test: all
18         retval=0; \
19                for i in `find "$(TESTDIR)" -iname '*.py' -perm -u+x -type f`; do \
20                echo $$i; \
21                PYTHONPATH="$(PYPATH)" $$i -v || retval=$$?; \
22                done; exit $$retval
23
24 ifeq ($(file),)
25 test-one:
26         echo Run $(make) $@ file=test/some/path
27 else
28 test-one: all
29         echo $(file) $(case)
30         PYTHONPATH="$(PYPATH)" $(file) $(case)
31 endif
32
33
34 all-tests: test-app test-node
35
36 test-app:
37         $(MAKE) test-one file=test/resources/linux/application.py case=$(case)
38 test-node:
39         $(MAKE) test-one file=test/resources/linux/node.py case=$(case)
40
41 coverage: all
42         rm -f .coverage
43         for i in `find "$(TESTDIR)" -perm -u+x -type f`; do \
44                 set -e; \
45                 PYTHONPATH="$(PYPATH)" $(COVERAGE) -x $$i -v; \
46                 done
47         $(COVERAGE) -c
48         $(COVERAGE) -r -m `find "$(BUILDDIR)" -name \\*.py -type f`
49         rm -f .coverage
50
51 clean:
52         rm -f $$(find . -name '*.pyc') .coverage *.pcap
53         rm -rf "$(BUILDDIR)"
54
55 distclean: clean
56         rm -rf "$(DISTDIR)"
57
58 MANIFEST:
59         find . -path ./.hg\* -prune -o -path ./build -prune -o \
60                 -name \*.pyc -prune -o -name \*.swp -prune -o \
61                 -name MANIFEST -prune -o -type f -print | \
62                 sed 's#^\./##' | sort > MANIFEST
63
64 dist: MANIFEST
65         ./setup.py sdist
66
67 .PHONY: all clean distclean dist test coverage install MANIFEST
68
69 ########## for uploading onto pypi
70 # this assumes you have an entry 'pypi' in your .pypirc
71 # see pypi documentation on how to create .pypirc
72 PYPI_TARGET=pypi
73 PYPI_TARBALL_HOST=mario@build.onelab.eu
74 PYPI_TARBALL_TOPDIR=/build/nepi
75
76 VERSION=$(shell cat VERSION)
77 VERSIONTAG=nepi-$(VERSION)-pypi
78 VERSIONTAR=nepi-$(VERSION).tar.gz
79 ALREADY_SET=$(shell git tag | grep '^$(VERSIONTAG)$$')
80
81 # run this only once the sources are in on the right tag
82 pypi:
83         @echo "Have you committed all changes (type Ctrl-c if not) ? " ; read _
84         @if [ -n "$(ALREADY_SET)" ] ; then echo "tag $(VERSIONTAG) already set"; false; fi
85         @echo "You are about to release $(VERSION) - OK (Ctrl-c if not) ? " ; read _
86         git tag $(VERSIONTAG)
87         #./setup.py sdist upload -r pypi
88         ./setup.py sdist
89         twine upload dist/* -r pypi
90         @if [ ssh $(PYPI_TARBALL_HOST) ls $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAR) ] ;\
91           then echo "$(VERSIONTAR) already present on $(PYPI_TARBALL_HOST) - ignored" ;\
92           else rsync -av dist/$(VERSIONTAR) $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/ ;\
93           fi
94
95
96 # it can be convenient to define a test entry, say testpypi
97 # that points at the testpypi public site
98 # in this case we do not want to upload anything on the build box though
99
100 testpypi: 
101         #./setup.py sdist upload -r testpypi
102         ./setup.py sdist
103         twine upload dist/* -r testpypi