6.1.2
[nepi.git] / Makefile
1 PYTHON      = python
2 SRCDIR      = $(CURDIR)
3 TESTDIR     = $(CURDIR)/test
4 TESTLIB     = $(TESTDIR)/lib
5 BUILDDIR    = $(CURDIR)/build/lib
6 DISTDIR     = $(CURDIR)/dist
7
8 PYPATH = $(BUILDDIR):$(TESTLIB):$(PYTHONPATH)
9 COVERAGE = $(or $(shell which coverage), $(shell which python-coverage), \
10            coverage)
11
12 all: clean
13         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" $(PYTHON) ./setup.py build
14
15 install: all
16         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" $(PYTHON) ./setup.py install
17
18 test: all
19         retval=0; \
20                for i in `find "$(TESTDIR)" -iname '*.py' -perm -u+x -type f`; do \
21                echo $$i; \
22                PYTHONPATH="$(PYPATH)" $(PYTHON) $$i -v || retval=$$?; \
23                done; exit $$retval
24
25 ifeq ($(file),)
26 test-one:
27         echo Run $(make) $@ file=test/some/path
28 else
29 test-one: all
30         echo $(file) $(case)
31         PYTHONPATH="$(PYPATH)" $(PYTHON) $(file) $(case)
32 endif
33
34
35 all-tests: test-app test-node
36
37 test-app:
38         $(MAKE) test-one file=test/resources/linux/application.py case=$(case)
39 test-node:
40         $(MAKE) test-one file=test/resources/linux/node.py case=$(case)
41
42 coverage: all
43         rm -f .coverage
44         for i in `find "$(TESTDIR)" -perm -u+x -type f`; do \
45                 set -e; \
46                 PYTHONPATH="$(PYPATH)" $(COVERAGE) -x $$i -v; \
47                 done
48         $(COVERAGE) -c
49         $(COVERAGE) -r -m `find "$(BUILDDIR)" -name \\*.py -type f`
50         rm -f .coverage
51
52 clean:
53         rm -f $$(find . -name '*.pyc') .coverage *.pcap
54         rm -rf "$(BUILDDIR)"
55
56 distclean: clean
57         rm -rf "$(DISTDIR)"
58
59 MANIFEST:
60         find . -path ./.hg\* -prune -o -path ./build -prune -o \
61                 -name \*.pyc -prune -o -name \*.swp -prune -o \
62                 -name MANIFEST -prune -o -type f -print | \
63                 sed 's#^\./##' | sort > MANIFEST
64
65 dist: MANIFEST
66         ./setup.py sdist
67
68 .PHONY: all clean distclean dist test coverage install MANIFEST
69
70 ########## for uploading onto pypi
71 # this assumes you have an entry 'pypi' in your .pypirc
72 # see pypi documentation on how to create .pypirc
73 LOCAL_ID=$(shell id)
74 ifneq "$(LOCAL_ID)" "$(filter $(LOCAL_ID),parmen)"
75 BUILD_ID=thierry
76 USE_TWINE=
77 else
78 BUILD_ID=mario
79 USE_TWINE=true
80 endif
81
82 PYPI_TARGET=pypi
83 PYPI_TARBALL_HOST=$(BUILD_ID)@build.onelab.eu
84 PYPI_TARBALL_TOPDIR=/build/nepi
85
86 VERSION = $(shell cat VERSION)
87 VERSIONTAG = nepi-$(VERSION)-pypi
88 VERSIONTAR = nepi-$(VERSION).tar.gz
89 GIT-TAG-ALREADY-SET = $(shell git tag | grep '^$(VERSIONTAG)$$')
90 # to check for uncommitted changes
91 GIT-CHANGES = $(shell echo $$(git diff HEAD | wc -l))
92 GIT-URL = git://git.onelab.eu/nepi.git
93
94 version: nepi/util/version.py
95 nepi/util/version.py: VERSION nepi/util/version.py.in
96         sed -e "s,@VERSIONTAG@,$(VERSION),g" -e "s,@SCMURL@,$(GIT-URL),g" nepi/util/version.py.in > $@
97
98 clean: version-clean
99 version-clean:
100         rm -f nepi/util/version.py
101
102 ##########
103 # depending on the value of USE_TWINE, we either do the upload with setup.py itself,
104 # or with the help of twine which apparently is the only way that mario could find out on his setup
105 define upload_pypi
106 $(if $(USE_TWINE),./setup.py sdist && twine upload dist/* -r $(1),./setup.py sdist upload -r $(1))
107 endef
108
109 # run this only once the sources are in on the right tag
110 pypi: version
111         @if [ $(GIT-CHANGES) != 0 ]; then echo "You have uncommitted changes - cannot publish"; false; fi
112         @if [ -n "$(GIT-TAG-ALREADY-SET)" ] ; then echo "tag $(VERSIONTAG) already set"; false; fi
113         @if ! grep -q ' $(VERSION)' CHANGELOG.md ; then echo no mention of $(VERSION) in CHANGELOG.md; false; fi
114         @echo "You are about to release $(VERSION) - OK (Ctrl-c if not) ? " ; read _
115         git tag $(VERSIONTAG)
116         $(call upload_pypi,pypi)
117         @if [ ssh $(PYPI_TARBALL_HOST) ls $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAR) ] ;\
118           then echo "$(VERSIONTAR) already present on $(PYPI_TARBALL_HOST) - ignored" ;\
119           else rsync -av dist/$(VERSIONTAR) $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/ ;\
120           fi
121
122
123 # it can be convenient to define a test entry, say testpypi, in your .pypirc
124 # that points at the testpypi public site
125 # no upload to build.onelab.eu is done in this case 
126 # try it out with
127 # pip install -i https://testpypi.python.org/pypi nepi
128 # dependencies need to be managed manually though
129 testpypi: version
130         $(call upload_pypi,testpypi)
131
132 #################### convenience, for debugging only
133 # make +foo : prints the value of $(foo)
134 # make ++foo : idem but verbose, i.e. foo=$(foo)
135 ++%: varname=$(subst +,,$@)
136 ++%:
137         @echo "$(varname)=$($(varname))"
138 +%: varname=$(subst +,,$@)
139 +%:
140         @echo "$($(varname))"